vsavchenko created this revision. vsavchenko added reviewers: NoQ, xazax.hun, Szelethus. Herald added subscribers: cfe-commits, ASDenysPetrov, martong, Charusso, dkrupp, donat.nagy, mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware. Herald added a project: clang. vsavchenko added a reviewer: martong.
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. Repository: rG LLVM Github Monorepo 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,24 @@ +// 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=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(); +} + +#endif Index: clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp +++ clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp @@ -128,7 +128,7 @@ // Parse an integer at the end of the macro definition. const Token &T = FilteredTokens.back(); - if (!T.isLiteral()) + if (!T.isLiteral() || !T.getLiteralData()) return llvm::None; StringRef ValueStr = StringRef(T.getLiteralData(), T.getLength()); llvm::APInt IntValue;
Index: clang/test/Analysis/pch_crash.cpp =================================================================== --- /dev/null +++ clang/test/Analysis/pch_crash.cpp @@ -0,0 +1,24 @@ +// 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=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(); +} + +#endif Index: clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp +++ clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp @@ -128,7 +128,7 @@ // Parse an integer at the end of the macro definition. const Token &T = FilteredTokens.back(); - if (!T.isLiteral()) + if (!T.isLiteral() || !T.getLiteralData()) return llvm::None; StringRef ValueStr = StringRef(T.getLiteralData(), T.getLength()); llvm::APInt IntValue;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits