Skip to content

Commit 13ccaf9

Browse files
committed
Revert "Reapply "[analyzer] Accept C library functions from the std namespace""
This reverts commit e48d5a8. Fails to build on x86-64 w/gcc version 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04) with the following message: ../llvm-project/clang/unittests/StaticAnalyzer/IsCLibraryFunctionTest.cpp:41:28: error: declaration of ‘std::unique_ptr<clang::ASTUnit> IsCLibraryFunctionTest::ASTUnit’ changes meaning of ‘ASTUnit’ [-fpermissive] 41 | std::unique_ptr<ASTUnit> ASTUnit; | ^~~~~~~ In file included from ../llvm-project/clang/unittests/StaticAnalyzer/IsCLibraryFunctionTest.cpp:4: ../llvm-project/clang/include/clang/Frontend/ASTUnit.h:89:7: note: ‘ASTUnit’ declared here as ‘class clang::ASTUnit’ 89 | class ASTUnit { | ^~~~~~~
1 parent 35f5cae commit 13ccaf9

File tree

5 files changed

+9
-93
lines changed

5 files changed

+9
-93
lines changed

clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ class CallDescription {
4141
/// - We also accept calls where the number of arguments or parameters is
4242
/// greater than the specified value.
4343
/// For the exact heuristics, see CheckerContext::isCLibraryFunction().
44-
/// (This mode only matches functions that are declared either directly
45-
/// within a TU or in the namespace `std`.)
44+
/// Note that functions whose declaration context is not a TU (e.g.
45+
/// methods, functions in namespaces) are not accepted as C library
46+
/// functions.
47+
/// FIXME: If I understand it correctly, this discards calls where C++ code
48+
/// refers a C library function through the namespace `std::` via headers
49+
/// like <cstdlib>.
4650
CLibrary,
4751

4852
/// Matches "simple" functions that are not methods. (Static methods are

clang/lib/StaticAnalyzer/Core/CheckerContext.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,9 @@ bool CheckerContext::isCLibraryFunction(const FunctionDecl *FD,
8787
if (!II)
8888
return false;
8989

90-
// C library functions are either declared directly within a TU (the common
91-
// case) or they are accessed through the namespace `std` (when they are used
92-
// in C++ via headers like <cstdlib>).
93-
const DeclContext *DC = FD->getDeclContext()->getRedeclContext();
94-
if (!(DC->isTranslationUnit() || DC->isStdNamespace()))
90+
// Look through 'extern "C"' and anything similar invented in the future.
91+
// If this function is not in TU directly, it is not a C library function.
92+
if (!FD->getDeclContext()->getRedeclContext()->isTranslationUnit())
9593
return false;
9694

9795
// If this function is not externally visible, it is not a C library function.

clang/unittests/StaticAnalyzer/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ add_clang_unittest(StaticAnalysisTests
1111
CallEventTest.cpp
1212
ConflictingEvalCallsTest.cpp
1313
FalsePositiveRefutationBRVisitorTest.cpp
14-
IsCLibraryFunctionTest.cpp
1514
NoStateChangeFuncVisitorTest.cpp
1615
ParamRegionTest.cpp
1716
RangeSetTest.cpp

clang/unittests/StaticAnalyzer/IsCLibraryFunctionTest.cpp

Lines changed: 0 additions & 84 deletions
This file was deleted.

llvm/utils/gn/secondary/clang/unittests/StaticAnalyzer/BUILD.gn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ unittest("StaticAnalysisTests") {
1919
"CallEventTest.cpp",
2020
"ConflictingEvalCallsTest.cpp",
2121
"FalsePositiveRefutationBRVisitorTest.cpp",
22-
"IsCLibraryFunctionTest.cpp",
2322
"NoStateChangeFuncVisitorTest.cpp",
2423
"ParamRegionTest.cpp",
2524
"RangeSetTest.cpp",

0 commit comments

Comments
 (0)