forked from OSchip/llvm-project
[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
This commit is contained in:
parent
e1ba7241c3
commit
14b947f306
|
@ -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;
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue