================
@@ -129,11 +129,19 @@ std::optional<int> tryExpandAsInteger(StringRef Macro, 
const Preprocessor &PP) {
 
   // Parse an integer at the end of the macro definition.
   const Token &T = FilteredTokens.back();
-  // FIXME: EOF macro token coming from a PCH file on macOS while marked as
-  //        literal, doesn't contain any literal data
-  if (!T.isLiteral() || !T.getLiteralData())
+
+  if (!T.isLiteral())
     return std::nullopt;
-  StringRef ValueStr = StringRef(T.getLiteralData(), T.getLength());
+
+  bool InvalidSpelling = false;
+  // `Preprocessor::getSpelling` can get the spelling of the token regardless 
of
+  // whether the macro is defined in a PCH or not:
+  std::string Spelling = PP.getSpelling(T, &InvalidSpelling);
----------------
steakhal wrote:

You were right, it had to allocate because it needs to do some sort of 
"cleaning".
Despite I suggested this, the potential allocation is unavoidable because it 
needs to own the buffer.
I didn't know about this, so feel free to revert this part back because that is 
actually shorter than passing a buffer directly.

Anyway, I don't mind either of these. There is every day I learn something.

https://github.com/llvm/llvm-project/pull/142722
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to