[Macros] Diagnose how ExternalMacroDefinition request was failed

Return the failure reason as the result.
This commit is contained in:
Rintaro Ishizaki
2023-09-29 09:13:03 -07:00
parent d4adba20fc
commit bdd4c005e5
12 changed files with 122 additions and 55 deletions

View File

@@ -21,9 +21,11 @@
#include "swift/Basic/LLVM.h"
#include "swift/Basic/OptionSet.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/Allocator.h"
#include <iterator>
#include <string>
@@ -492,13 +494,17 @@ public:
/// Create a null-terminated string, copying \p Str into \p A .
template <typename Allocator>
NullTerminatedStringRef(StringRef Str, Allocator &A) : Ref("") {
if (Str.empty())
NullTerminatedStringRef(llvm::Twine Str, Allocator &A) : Ref("") {
if (Str.isTriviallyEmpty())
return;
llvm::SmallString<0> stash;
auto _ref = Str.toStringRef(stash);
size_t size = Str.size();
char *memory = A.template Allocate<char>(size + 1);
memcpy(memory, Str.data(), size);
size_t size = _ref.size();
if (size == 0)
return;
char *memory = static_cast<char *>(A.Allocate(size + 1, alignof(char)));
memcpy(memory, _ref.data(), size);
memory[size] = '\0';
Ref = {memory, size};
}