summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristof Umann <dkszelethus@gmail.com>2019-02-25 18:49:42 +0000
committerKristof Umann <dkszelethus@gmail.com>2019-02-25 18:49:42 +0000
commitcd8c438086b46b3edcf291cbfd52ca5e04382d53 (patch)
treeec858b4bc16b9cb7978098c1b9935cbae341febe
parent310b75e51995e8a9aeae0ea6c6d7922324453f57 (diff)
downloadbcm5719-llvm-cd8c438086b46b3edcf291cbfd52ca5e04382d53.tar.gz
bcm5719-llvm-cd8c438086b46b3edcf291cbfd52ca5e04382d53.zip
[analyzer] Fix infinite recursion in printing macros
#define f(y) x #define x f(x) int main() { x; } This example results a compilation error since "x" in the first line was not defined earlier. However, the macro expression printer goes to an infinite recursion on this example. Patch by Tibor Brunner! Differential Revision: https://reviews.llvm.org/D57892 llvm-svn: 354806
-rw-r--r--clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp b/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
index 889ea100cfa..bda72e87004 100644
--- a/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
+++ b/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
@@ -842,6 +842,9 @@ static std::string getMacroNameAndPrintExpansion(TokenPrinter &Printer,
MacroNameAndArgs Info = getMacroNameAndArgs(SM.getExpansionLoc(MacroLoc), PP);
+ if (!Info.MI)
+ return Info.Name;
+
// Manually expand its arguments from the previous macro.
Info.Args.expandFromPrevMacro(PrevArgs);
@@ -936,7 +939,14 @@ static MacroNameAndArgs getMacroNameAndArgs(SourceLocation ExpanLoc,
assert(II && "Failed to acquire the IndetifierInfo for the macro!");
const MacroInfo *MI = getMacroInfoForLocation(PP, SM, II, ExpanLoc);
- assert(MI && "The macro must've been defined at it's expansion location!");
+ // assert(MI && "The macro must've been defined at it's expansion location!");
+ //
+ // We should always be able to obtain the MacroInfo in a given TU, but if
+ // we're running the analyzer with CTU, the Preprocessor won't contain the
+ // directive history (or anything for that matter) from another TU.
+ // TODO: assert when we're not running with CTU.
+ if (!MI)
+ return { MacroName, MI, {} };
// Acquire the macro's arguments.
//
OpenPOWER on IntegriCloud