[cfe-commits] r133993 - in /cfe/trunk: include/clang/Frontend/TextDiagnosticPrinter.h lib/Frontend/TextDiagnosticPrinter.cpp test/Misc/caret-diags-macros.c
Chris Lattner
sabre at nondot.org
Mon Jun 27 22:11:33 PDT 2011
Author: lattner
Date: Tue Jun 28 00:11:33 2011
New Revision: 133993
URL: http://llvm.org/viewvc/llvm-project?rev=133993&view=rev
Log:
Fix PR9279 - Macro expansion stack trace seriously broken with function-style macros, by not recursively printing notes for other 'instantiated from' notes.
This is a one line fix here:
+ // Don't print recursive instantiation notes from an instantiation note.
+ Loc = SM.getSpellingLoc(Loc);
While here, fix the testcase to be more precise (it got filecheck'ized
brutally), and fix EmitCaretDiagnostic to be private and to not pass down
the unused 'Level' argument.
Modified:
cfe/trunk/include/clang/Frontend/TextDiagnosticPrinter.h
cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
cfe/trunk/test/Misc/caret-diags-macros.c
Modified: cfe/trunk/include/clang/Frontend/TextDiagnosticPrinter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/TextDiagnosticPrinter.h?rev=133993&r1=133992&r2=133993&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/TextDiagnosticPrinter.h (original)
+++ cfe/trunk/include/clang/Frontend/TextDiagnosticPrinter.h Tue Jun 28 00:11:33 2011
@@ -62,18 +62,17 @@
std::string &CaretLine,
const std::string &SourceLine);
- void EmitCaretDiagnostic(Diagnostic::Level Level, SourceLocation Loc,
- CharSourceRange *Ranges, unsigned NumRanges,
- const SourceManager &SM,
- const FixItHint *Hints,
- unsigned NumHints,
- unsigned Columns,
- unsigned OnMacroInst,
- unsigned MacroSkipStart,
- unsigned MacroSkipEnd);
-
virtual void HandleDiagnostic(Diagnostic::Level Level,
const DiagnosticInfo &Info);
+
+private:
+ void EmitCaretDiagnostic(SourceLocation Loc, CharSourceRange *Ranges,
+ unsigned NumRanges, const SourceManager &SM,
+ const FixItHint *Hints,
+ unsigned NumHints, unsigned Columns,
+ unsigned OnMacroInst, unsigned MacroSkipStart,
+ unsigned MacroSkipEnd);
+
};
} // end namespace clang
Modified: cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp?rev=133993&r1=133992&r2=133993&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp Tue Jun 28 00:11:33 2011
@@ -292,8 +292,7 @@
}
}
-void TextDiagnosticPrinter::EmitCaretDiagnostic(Diagnostic::Level Level,
- SourceLocation Loc,
+void TextDiagnosticPrinter::EmitCaretDiagnostic(SourceLocation Loc,
CharSourceRange *Ranges,
unsigned NumRanges,
const SourceManager &SM,
@@ -314,10 +313,10 @@
bool Suppressed
= OnMacroInst >= MacroSkipStart && OnMacroInst < MacroSkipEnd;
-
SourceLocation OneLevelUp = SM.getImmediateInstantiationRange(Loc).first;
+
// FIXME: Map ranges?
- EmitCaretDiagnostic(Level, OneLevelUp, Ranges, NumRanges, SM,
+ EmitCaretDiagnostic(OneLevelUp, Ranges, NumRanges, SM,
Hints, NumHints, Columns,
OnMacroInst + 1, MacroSkipStart, MacroSkipEnd);
@@ -356,7 +355,10 @@
}
OS << "note: instantiated from:\n";
- EmitCaretDiagnostic(Level, Loc, Ranges, NumRanges, SM, 0, 0,
+ // Don't print recursive instantiation notes from an instantiation note.
+ Loc = SM.getSpellingLoc(Loc);
+
+ EmitCaretDiagnostic(Loc, Ranges, NumRanges, SM, 0, 0,
Columns, OnMacroInst + 1, MacroSkipStart,
MacroSkipEnd);
return;
@@ -371,7 +373,7 @@
return;
}
-
+
// Decompose the location into a FID/Offset pair.
std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(Loc);
FileID FID = LocInfo.first;
@@ -1059,7 +1061,7 @@
}
}
- EmitCaretDiagnostic(Level, LastLoc, Ranges, NumRanges, LastLoc.getManager(),
+ EmitCaretDiagnostic(LastLoc, Ranges, NumRanges, LastLoc.getManager(),
Info.getFixItHints(),
Info.getNumFixItHints(),
DiagOpts->MessageLength,
Modified: cfe/trunk/test/Misc/caret-diags-macros.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/caret-diags-macros.c?rev=133993&r1=133992&r2=133993&view=diff
==============================================================================
--- cfe/trunk/test/Misc/caret-diags-macros.c (original)
+++ cfe/trunk/test/Misc/caret-diags-macros.c Tue Jun 28 00:11:33 2011
@@ -5,20 +5,20 @@
void foo() {
M1(
M2);
- // CHECK: {{.*}}:6:{{[0-9]+}}: warning: expression result unused
- // CHECK: {{.*}}:7:{{[0-9]+}}: note: instantiated from:
- // CHECK: {{.*}}:4:{{[0-9]+}}: note: instantiated from:
+ // CHECK: :6:3: warning: expression result unused
+ // CHECK: :7:5: note: instantiated from:
}
+
#define A 1
#define B A
#define C B
void bar() {
C;
- // CHECK: {{.*}}:17:{{[0-9]+}}: warning: expression result unused
- // CHECK: {{.*}}:15:{{[0-9]+}}: note: instantiated from:
- // CHECK: {{.*}}:14:{{[0-9]+}}: note: instantiated from:
- // CHECK: {{.*}}:13:{{[0-9]+}}: note: instantiated from:
+ // CHECK: :17:3: warning: expression result unused
+ // CHECK: :15:11: note: instantiated from:
+ // CHECK: :14:11: note: instantiated from:
+ // CHECK: :13:11: note: instantiated from:
}
@@ -30,3 +30,15 @@
sprintf(Msg, " sizeof FoooLib : =%3u\n", 12LL);
}
+
+
+// PR9279 - Notes shouldn't print 'instantiated from' notes recursively.
+#define N1(x) int arr[x]
+#define N2(x) N1(x)
+#define N3(x) N2(x)
+N3(-1);
+
+// CHECK: :39:1: error: 'arr' declared as an array with a negative size
+// CHECK: :38:15: note: instantiated from:
+// CHECK: :37:15: note: instantiated from:
+// CHECK: :39:1: note: instantiated from:
More information about the cfe-commits
mailing list