[clang] 59df564 - [clang/Lexer] Enhance `Lexer::getImmediateMacroNameForDiagnostics` to return a result from non-file buffers
Argyrios Kyrtzidis via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 15 22:50:56 PST 2022
Author: Argyrios Kyrtzidis
Date: 2022-12-15T22:46:41-08:00
New Revision: 59df56413bdc25bef53bf1629b26bd2176089088
URL: https://github.com/llvm/llvm-project/commit/59df56413bdc25bef53bf1629b26bd2176089088
DIFF: https://github.com/llvm/llvm-project/commit/59df56413bdc25bef53bf1629b26bd2176089088.diff
LOG: [clang/Lexer] Enhance `Lexer::getImmediateMacroNameForDiagnostics` to return a result from non-file buffers
Use `SourceManager::isWrittenInScratchSpace()` to specifically check for token paste or stringization, instead of
excluding all non-file buffers. This allows diagnostics to mention macro names that were defined from the command-line.
Differential Revision: https://reviews.llvm.org/D140164
Added:
Modified:
clang/lib/Lex/Lexer.cpp
clang/test/Modules/build-fail-notes.m
clang/test/Modules/epic-fail.m
Removed:
################################################################################
diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index 3866c2c85f18e..4a9c5b5cd680e 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -1047,9 +1047,11 @@ StringRef Lexer::getImmediateMacroNameForDiagnostics(
while (SM.isMacroArgExpansion(Loc))
Loc = SM.getImmediateExpansionRange(Loc).getBegin();
- // If the macro's spelling has no FileID, then it's actually a token paste
- // or stringization (or similar) and not a macro at all.
- if (!SM.getFileEntryForID(SM.getFileID(SM.getSpellingLoc(Loc))))
+ // If the macro's spelling isn't FileID or from scratch space, then it's
+ // actually a token paste or stringization (or similar) and not a macro at
+ // all.
+ SourceLocation SpellLoc = SM.getSpellingLoc(Loc);
+ if (!SpellLoc.isFileID() || SM.isWrittenInScratchSpace(SpellLoc))
return {};
// Find the spelling location of the start of the non-argument expansion
diff --git a/clang/test/Modules/build-fail-notes.m b/clang/test/Modules/build-fail-notes.m
index 47bdbc7fca6cb..929e1f1890e8a 100644
--- a/clang/test/Modules/build-fail-notes.m
+++ b/clang/test/Modules/build-fail-notes.m
@@ -6,7 +6,7 @@
// CHECK: While building module 'DependsOnModule' imported from
// CHECK: While building module 'Module' imported from
// CHECK: error: expected ';' after top level declarator
-// CHECK: note: expanded from here
+// CHECK: note: expanded from macro 'getModuleVersion'
// CHECK: fatal error: could not build module 'Module'
// CHECK: fatal error: could not build module 'DependsOnModule'
// CHECK-NOT: error:
@@ -24,7 +24,7 @@
// CHECK-SDIAG: Module.h:9:13: error: expected ';' after top level declarator
// CHECK-SDIAG: build-fail-notes.m:4:9: note: while building module 'DependsOnModule' imported from
// CHECK-SDIAG: DependsOnModule.h:1:10: note: while building module 'Module' imported from
-// CHECK-SDIAG: note: expanded from here
+// CHECK-SDIAG: note: expanded from macro 'getModuleVersion'
// CHECK-SDIAG: warning: umbrella header for module 'Module' does not include header 'NotInModule.h' [-Wincomplete-umbrella]
// CHECK-SDIAG: DependsOnModule.h:1:10: fatal: could not build module 'Module'
// CHECK-SDIAG: build-fail-notes.m:4:9: note: while building module 'DependsOnModule' imported from
diff --git a/clang/test/Modules/epic-fail.m b/clang/test/Modules/epic-fail.m
index b368ceaec8984..efa397b0a8497 100644
--- a/clang/test/Modules/epic-fail.m
+++ b/clang/test/Modules/epic-fail.m
@@ -6,7 +6,7 @@
// CHECK: While building module 'Module' imported from
// CHECK: error: expected ';' after top level declarator
-// CHECK: note: expanded from here
+// CHECK: note: expanded from macro 'getModuleVersion'
// CHECK: fatal error: could not build module 'Module'
// CHECK: While building module 'DependsOnModule' imported from
// CHECK: fatal error: could not build module 'Module'
More information about the cfe-commits
mailing list