Skip to content

Commit f32b04d

Browse files
authored
Revert "[analyzer] Accept C library functions from the std namespace" (#84926)
Reverts #84469 because it causes buildbot failures. I'll examine them and re-submit the change.
1 parent 0fe271c commit f32b04d

File tree

5 files changed

+9
-98
lines changed

5 files changed

+9
-98
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 & 89 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)