[PATCH] D57892: [analyzer] Fix macro printer crash when macro comes from another translation unit

Tibor Brunner via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 7 07:18:41 PST 2019

bruntib created this revision.
bruntib added reviewers: NoQ, george.karpenkov, Szelethus, xazax.hun.
Herald added subscribers: cfe-commits, dkrupp, donat.nagy, mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware.
Herald added a project: clang.

  rC Clang



Index: lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
--- lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
+++ lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
@@ -820,6 +820,9 @@
     return Info.Name;
+  if (!Info.MI)
+    return Info.Name;
   // Manually expand its arguments from the previous macro.
@@ -917,7 +920,14 @@
   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.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57892.185758.patch
Type: text/x-patch
Size: 1158 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190207/350fdde6/attachment.bin>

More information about the cfe-commits mailing list