[PATCH] D81916: [analyzer] Fix StdLibraryFunctionsChecker crash on macOS

Valeriy Savchenko via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 16 06:37:19 PDT 2020


vsavchenko updated this revision to Diff 271073.
vsavchenko added a comment.

Add FIXME comment


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81916/new/

https://reviews.llvm.org/D81916

Files:
  clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp
  clang/test/Analysis/pch_crash.cpp


Index: clang/test/Analysis/pch_crash.cpp
===================================================================
--- /dev/null
+++ clang/test/Analysis/pch_crash.cpp
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.15.0 -emit-pch -o %t %s
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-macosx10.15.0 -include-pch %t \
+// RUN:   -analyzer-checker=core,apiModeling -verify %s
+//
+// RUN: %clang_cc1 -emit-pch -o %t %s
+// RUN: %clang_analyze_cc1 -include-pch %t \
+// RUN:   -analyzer-checker=core,apiModeling -verify %s
+
+// expected-no-diagnostics
+
+#ifndef HEADER
+#define HEADER
+// Pre-compiled header
+
+int foo();
+
+// Literal data for this macro value will be null
+#define EOF -1
+
+#else
+// Source file
+
+int test() {
+  // we need a function call here to initiate erroneous routine
+  return foo(); // no-crash
+}
+
+#endif
Index: clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp
+++ clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp
@@ -128,7 +128,9 @@
 
   // Parse an integer at the end of the macro definition.
   const Token &T = FilteredTokens.back();
-  if (!T.isLiteral())
+  // FIXME: EOF macro token coming from a PCH file on macOS while marked as
+  //        literal, doesn't contain any literal data
+  if (!T.isLiteral() || !T.getLiteralData())
     return llvm::None;
   StringRef ValueStr = StringRef(T.getLiteralData(), T.getLength());
   llvm::APInt IntValue;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81916.271073.patch
Type: text/x-patch
Size: 1529 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200616/076f9d42/attachment.bin>


More information about the cfe-commits mailing list