Skip to content

Commit

Permalink
Revert "[analyzer] Accept C library functions from the std namespac…
Browse files Browse the repository at this point in the history
…e" (llvm#84926)

Reverts llvm#84469 because it causes buildbot failures.
I'll examine them and re-submit the change.
  • Loading branch information
NagyDonat authored Mar 12, 2024
1 parent 0fe271c commit f32b04d
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ class CallDescription {
/// - We also accept calls where the number of arguments or parameters is
/// greater than the specified value.
/// For the exact heuristics, see CheckerContext::isCLibraryFunction().
/// (This mode only matches functions that are declared either directly
/// within a TU or in the namespace `std`.)
/// Note that functions whose declaration context is not a TU (e.g.
/// methods, functions in namespaces) are not accepted as C library
/// functions.
/// FIXME: If I understand it correctly, this discards calls where C++ code
/// refers a C library function through the namespace `std::` via headers
/// like <cstdlib>.
CLibrary,

/// Matches "simple" functions that are not methods. (Static methods are
Expand Down
8 changes: 3 additions & 5 deletions clang/lib/StaticAnalyzer/Core/CheckerContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,9 @@ bool CheckerContext::isCLibraryFunction(const FunctionDecl *FD,
if (!II)
return false;

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

// If this function is not externally visible, it is not a C library function.
Expand Down
1 change: 0 additions & 1 deletion clang/unittests/StaticAnalyzer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ add_clang_unittest(StaticAnalysisTests
CallEventTest.cpp
ConflictingEvalCallsTest.cpp
FalsePositiveRefutationBRVisitorTest.cpp
IsCLibraryFunctionTest.cpp
NoStateChangeFuncVisitorTest.cpp
ParamRegionTest.cpp
RangeSetTest.cpp
Expand Down
89 changes: 0 additions & 89 deletions clang/unittests/StaticAnalyzer/IsCLibraryFunctionTest.cpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ unittest("StaticAnalysisTests") {
"CallEventTest.cpp",
"ConflictingEvalCallsTest.cpp",
"FalsePositiveRefutationBRVisitorTest.cpp",
"IsCLibraryFunctionTest.cpp",
"NoStateChangeFuncVisitorTest.cpp",
"ParamRegionTest.cpp",
"RangeSetTest.cpp",
Expand Down

0 comments on commit f32b04d

Please sign in to comment.