Skip to content

Commit 8893dd5

Browse files
committed
address comments
1 parent 3bd12ac commit 8893dd5

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,14 @@ std::optional<int> tryExpandAsInteger(StringRef Macro, const Preprocessor &PP) {
134134
return std::nullopt;
135135

136136
bool InvalidSpelling = false;
137+
SmallVector<char> Buffer(T.getLength());
137138
// `Preprocessor::getSpelling` can get the spelling of the token regardless of
138139
// whether the macro is defined in a PCH or not:
139-
std::string Spelling = PP.getSpelling(T, &InvalidSpelling);
140+
StringRef ValueStr = PP.getSpelling(T, Buffer, &InvalidSpelling);
140141

141142
if (InvalidSpelling)
142143
return std::nullopt;
143144

144-
StringRef ValueStr(Spelling);
145145
llvm::APInt IntValue;
146146
constexpr unsigned AutoSenseRadix = 0;
147147
if (ValueStr.getAsInteger(AutoSenseRadix, IntValue))

clang/test/Analysis/pch_macro.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.15.0 -emit-pch -o %t %s
2-
// RUN: %clang_analyze_cc1 -triple x86_64-apple-macosx10.15.0 -include-pch %t \
3-
// RUN: -analyzer-checker=core,apiModeling,unix.StdCLibraryFunctions -verify %s
1+
// RUN: rm -rf %t
2+
// RUN: mkdir -p %t
3+
// RUN: split-file %s %t
4+
5+
// RUN: %clang_cc1 -x c++ -triple x86_64-apple-macosx10.15.0 -emit-pch -o %t/header.pch %t/header.h
6+
// RUN: %clang_analyze_cc1 -triple x86_64-apple-macosx10.15.0 -include-pch %t/header.pch \
7+
// RUN: -analyzer-checker=core,apiModeling,unix.StdCLibraryFunctions -verify %t/main.cpp
48
//
5-
// RUN: %clang_cc1 -emit-pch -o %t %s
6-
// RUN: %clang_analyze_cc1 -include-pch %t \
7-
// RUN: -analyzer-checker=core,apiModeling,unix.StdCLibraryFunctions -verify %s
9+
// RUN: %clang_cc1 -x c++ -emit-pch -o %t/header.pch %t/header.h
10+
// RUN: %clang_analyze_cc1 -include-pch %t/header.pch \
11+
// RUN: -analyzer-checker=core,apiModeling,unix.StdCLibraryFunctions -verify %t/main.cpp
12+
13+
14+
//--- header.h
815

9-
// expected-no-diagnostics
1016

11-
#ifndef HEADER
12-
#define HEADER
1317
// Pre-compiled header
1418

1519
int foo();
@@ -18,9 +22,12 @@ int foo();
1822
#define EOF -1
1923
#define AT_FDCWD -2
2024

21-
#else
22-
// Source file
2325

26+
//--- main.cpp
27+
28+
29+
// Source file
30+
// expected-no-diagnostics
2431
int test() {
2532
// we need a function call here to initiate erroneous routine
2633
return foo(); // no-crash
@@ -36,4 +43,3 @@ void test_faccessat() {
3643
if (0 != faccessat(AT_FDCWD, fileSystemPath, 2, 0x0030)) {}
3744
}
3845

39-
#endif

0 commit comments

Comments
 (0)