[cfe-commits] r169373 - in /cfe/trunk: lib/Frontend/DiagnosticRenderer.cpp test/Misc/diag-macro-backtrace.c test/Modules/epic-fail.m
Richard Smith
richard-llvm at metafoo.co.uk
Wed Dec 5 03:04:56 PST 2012
Author: rsmith
Date: Wed Dec 5 05:04:55 2012
New Revision: 169373
URL: http://llvm.org/viewvc/llvm-project?rev=169373&view=rev
Log:
PR14049: Don't say "expanded from macro 'foo'" when 'foo' just happens to be
the LHS of a token paste. Use "expanded from here" instead when we're not sure
it's actually a macro.
Modified:
cfe/trunk/lib/Frontend/DiagnosticRenderer.cpp
cfe/trunk/test/Misc/diag-macro-backtrace.c
cfe/trunk/test/Modules/epic-fail.m
Modified: cfe/trunk/lib/Frontend/DiagnosticRenderer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/DiagnosticRenderer.cpp?rev=169373&r1=169372&r2=169373&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/DiagnosticRenderer.cpp (original)
+++ cfe/trunk/lib/Frontend/DiagnosticRenderer.cpp Wed Dec 5 05:04:55 2012
@@ -47,6 +47,11 @@
while (SM.isMacroArgExpansion(Loc))
Loc = SM.getImmediateExpansionRange(Loc).first;
+ // 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))))
+ return StringRef();
+
// Find the spelling location of the start of the non-argument expansion
// range. This is where the macro name was spelled in order to begin
// expanding this macro.
@@ -448,8 +453,11 @@
SmallString<100> MessageStorage;
llvm::raw_svector_ostream Message(MessageStorage);
- Message << "expanded from macro '"
- << getImmediateMacroName(Loc, SM, LangOpts) << "'";
+ StringRef MacroName = getImmediateMacroName(Loc, SM, LangOpts);
+ if (MacroName.empty())
+ Message << "expanded from here";
+ else
+ Message << "expanded from macro '" << MacroName << "'";
emitDiagnostic(SpellingLoc, DiagnosticsEngine::Note,
Message.str(),
SpellingRanges, ArrayRef<FixItHint>(), &SM);
Modified: cfe/trunk/test/Misc/diag-macro-backtrace.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/diag-macro-backtrace.c?rev=169373&r1=169372&r2=169373&view=diff
==============================================================================
--- cfe/trunk/test/Misc/diag-macro-backtrace.c (original)
+++ cfe/trunk/test/Misc/diag-macro-backtrace.c Wed Dec 5 05:04:55 2012
@@ -12,7 +12,7 @@
#define DROOL WAZ
#define FOOL DROOL
-FOOL
+FOOL;
// CHECK: :15:1: error: expected identifier or '('
// CHECK: FOOL
@@ -50,4 +50,17 @@
// CHECK: :3:13: note: expanded from macro 'FOO'
// CHECK: #define FOO 1+"hi"
// CHECK: ^
-// CHECK: 1 error generated.
+
+#define ADD(a, b) a ## #b
+ADD(L, foo)
+// CHECK: error: expected identifier or '('
+// CHECK: ADD(L, foo)
+// CHECK: {{^\^}}
+// CHECK: note: expanded from macro 'ADD'
+// CHECK: #define ADD(a, b) a ## #b
+// CHECK: {{^ \^}}
+// CHECK: note: expanded from here
+// CHECK: L"foo"
+// CHECK: {{^\^}}
+
+// CHECK: 2 errors generated.
Modified: cfe/trunk/test/Modules/epic-fail.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/epic-fail.m?rev=169373&r1=169372&r2=169373&view=diff
==============================================================================
--- cfe/trunk/test/Modules/epic-fail.m (original)
+++ cfe/trunk/test/Modules/epic-fail.m Wed Dec 5 05:04:55 2012
@@ -6,7 +6,7 @@
// CHECK: While building module 'Module' imported from
// CHECK: error: expected ';' after top level declarator
-// CHECK: note: expanded from macro 'getModuleVersion'
+// CHECK: note: expanded from here
// 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