[clang] 14b947f - [analyzer] Fix StdLibraryFunctionsChecker crash on macOS
Valeriy Savchenko via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 16 06:10:31 PDT 2020
Author: Valeriy Savchenko
Date: 2020-06-16T16:10:07+03:00
New Revision: 14b947f306ac7bc2e4eb55ac1e4255fd762b217b
URL: https://github.com/llvm/llvm-project/commit/14b947f306ac7bc2e4eb55ac1e4255fd762b217b
DIFF: https://github.com/llvm/llvm-project/commit/14b947f306ac7bc2e4eb55ac1e4255fd762b217b.diff
LOG: [analyzer] Fix StdLibraryFunctionsChecker crash on macOS
Summary:
EOF macro token coming from a PCH file on macOS while marked as literal,
doesn't contain any literal data. This causes crash on every project
using PCHs.
This commit doesn't resolve the problem with PCH (maybe it was
designed like this for a purpose) or with `tryExpandAsInteger`, but
rather simply shoots off a crash itself.
Differential Revision: https://reviews.llvm.org/D81916
Added:
clang/test/Analysis/pch_crash.cpp
Modified:
clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp
Removed:
################################################################################
diff --git a/clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp b/clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp
index 4b63ebc40ede..cae728815b41 100644
--- a/clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp
+++ b/clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp
@@ -128,7 +128,9 @@ llvm::Optional<int> tryExpandAsInteger(StringRef Macro,
// 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;
diff --git a/clang/test/Analysis/pch_crash.cpp b/clang/test/Analysis/pch_crash.cpp
new file mode 100644
index 000000000000..7ad2cb2d2ab5
--- /dev/null
+++ b/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
More information about the cfe-commits
mailing list