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. llvm-svn: 133993
This commit is contained in:
parent
411daa5e81
commit
ac57f21cd1
|
@ -62,18 +62,17 @@ public:
|
|||
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
|
||||
|
|
|
@ -292,8 +292,7 @@ static void SelectInterestingSourceRegion(std::string &SourceLine,
|
|||
}
|
||||
}
|
||||
|
||||
void TextDiagnosticPrinter::EmitCaretDiagnostic(Diagnostic::Level Level,
|
||||
SourceLocation Loc,
|
||||
void TextDiagnosticPrinter::EmitCaretDiagnostic(SourceLocation Loc,
|
||||
CharSourceRange *Ranges,
|
||||
unsigned NumRanges,
|
||||
const SourceManager &SM,
|
||||
|
@ -314,10 +313,10 @@ void TextDiagnosticPrinter::EmitCaretDiagnostic(Diagnostic::Level Level,
|
|||
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 @@ void TextDiagnosticPrinter::EmitCaretDiagnostic(Diagnostic::Level Level,
|
|||
}
|
||||
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 @@ void TextDiagnosticPrinter::EmitCaretDiagnostic(Diagnostic::Level Level,
|
|||
|
||||
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 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level,
|
|||
}
|
||||
}
|
||||
|
||||
EmitCaretDiagnostic(Level, LastLoc, Ranges, NumRanges, LastLoc.getManager(),
|
||||
EmitCaretDiagnostic(LastLoc, Ranges, NumRanges, LastLoc.getManager(),
|
||||
Info.getFixItHints(),
|
||||
Info.getNumFixItHints(),
|
||||
DiagOpts->MessageLength,
|
||||
|
|
|
@ -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 @@ void baz(char *Msg) {
|
|||
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:
|
||||
|
|
Loading…
Reference in New Issue