Author: Balázs Benics Date: 2026-02-20T10:58:54Z New Revision: 8715094d52f9dc350de93b8e1ef93f1e23120189
URL: https://github.com/llvm/llvm-project/commit/8715094d52f9dc350de93b8e1ef93f1e23120189 DIFF: https://github.com/llvm/llvm-project/commit/8715094d52f9dc350de93b8e1ef93f1e23120189.diff LOG: [analyzer] Remove the alpha.core.FixedAddr checker (#182033) This checker is way to simplistic. It's also alpha. I don't think it's worth for anyone keeping it, especially that we have an `optin.core.FixedAddressDereference` checker that largely supresedes this alpha checker. I propose the removal of this checker. Also relates to: https://github.com/llvm/llvm-project/pull/181858#discussion_r2818756964 Added: Modified: clang/docs/analyzer/checkers.rst clang/include/clang/StaticAnalyzer/Checkers/Checkers.td clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt clang/test/Analysis/concrete-address.c clang/test/Analysis/ptr-arith.c llvm/utils/gn/secondary/clang/lib/StaticAnalyzer/Checkers/BUILD.gn Removed: clang/lib/StaticAnalyzer/Checkers/FixedAddressChecker.cpp ################################################################################ diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst index 0afb094ecf0d2..87a5cb5cab103 100644 --- a/clang/docs/analyzer/checkers.rst +++ b/clang/docs/analyzer/checkers.rst @@ -3154,19 +3154,6 @@ Check for cases where the dynamic and the static type of an object are unrelated NSNumber *number = date; [number doubleValue]; -.. _alpha-core-FixedAddr: - -alpha.core.FixedAddr (C) -"""""""""""""""""""""""" -Check for assignment of a fixed address to a pointer. - -.. code-block:: c - - void test() { - int *p; - p = (int *) 0x10000; // warn - } - .. _alpha-core-PointerArithm: alpha.core.PointerArithm (C) diff --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td index 35d2f9c1d5ef1..9e552d171cd26 100644 --- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td +++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td @@ -247,10 +247,6 @@ def ConversionChecker : Checker<"Conversion">, HelpText<"Loss of sign/precision in implicit conversions">, Documentation<HasDocumentation>; -def FixedAddressChecker : Checker<"FixedAddr">, - HelpText<"Check for assignment of a fixed address to a pointer">, - Documentation<HasDocumentation>; - def PointerArithChecker : Checker<"PointerArithm">, HelpText<"Check for pointer arithmetic on locations other than array " "elements">, diff --git a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt index 3edbd7ebdc1bf..dc1feef484302 100644 --- a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt +++ b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt @@ -44,7 +44,6 @@ add_clang_library(clangStaticAnalyzerCheckers ErrnoModeling.cpp ErrnoTesterChecker.cpp ExprInspectionChecker.cpp - FixedAddressChecker.cpp FuchsiaHandleChecker.cpp GCDAntipatternChecker.cpp GenericTaintChecker.cpp diff --git a/clang/lib/StaticAnalyzer/Checkers/FixedAddressChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/FixedAddressChecker.cpp deleted file mode 100644 index f7fd92db7757e..0000000000000 --- a/clang/lib/StaticAnalyzer/Checkers/FixedAddressChecker.cpp +++ /dev/null @@ -1,77 +0,0 @@ -//=== FixedAddressChecker.cpp - Fixed address usage checker ----*- C++ -*--===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// This files defines FixedAddressChecker, a builtin checker that checks for -// assignment of a fixed address to a pointer. -// This check corresponds to CWE-587. -// -//===----------------------------------------------------------------------===// - -#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h" -#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h" -#include "clang/StaticAnalyzer/Core/Checker.h" -#include "clang/StaticAnalyzer/Core/CheckerManager.h" -#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h" - -using namespace clang; -using namespace ento; - -namespace { -class FixedAddressChecker - : public Checker< check::PreStmt<BinaryOperator> > { - const BugType BT{this, "Use fixed address"}; - -public: - void checkPreStmt(const BinaryOperator *B, CheckerContext &C) const; -}; -} - -void FixedAddressChecker::checkPreStmt(const BinaryOperator *B, - CheckerContext &C) const { - // Using a fixed address is not portable because that address will probably - // not be valid in all environments or platforms. - - if (B->getOpcode() != BO_Assign) - return; - - QualType T = B->getType(); - if (!T->isPointerType()) - return; - - // Omit warning if the RHS has already pointer type. Without this passing - // around one fixed value in several pointer variables would produce several - // redundant warnings. - if (B->getRHS()->IgnoreParenCasts()->getType()->isPointerType()) - return; - - SVal RV = C.getSVal(B->getRHS()); - - if (!RV.isConstant() || RV.isZeroConstant()) - return; - - if (C.getSourceManager().isInSystemMacro(B->getRHS()->getBeginLoc())) - return; - - if (ExplodedNode *N = C.generateNonFatalErrorNode()) { - // FIXME: improve grammar in the following strings: - constexpr llvm::StringLiteral Msg = - "Using a fixed address is not portable because that address will " - "probably not be valid in all environments or platforms."; - auto R = std::make_unique<PathSensitiveBugReport>(BT, Msg, N); - R->addRange(B->getRHS()->getSourceRange()); - C.emitReport(std::move(R)); - } -} - -void ento::registerFixedAddressChecker(CheckerManager &mgr) { - mgr.registerChecker<FixedAddressChecker>(); -} - -bool ento::shouldRegisterFixedAddressChecker(const CheckerManager &mgr) { - return true; -} diff --git a/clang/test/Analysis/concrete-address.c b/clang/test/Analysis/concrete-address.c index 0822c8a0b7532..17e8ba57b9ea1 100644 --- a/clang/test/Analysis/concrete-address.c +++ b/clang/test/Analysis/concrete-address.c @@ -1,4 +1,4 @@ -// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core.FixedAddr,optin.core.FixedAddressDereference -verify %s +// RUN: %clang_analyze_cc1 -analyzer-checker=core,optin.core.FixedAddressDereference -verify %s extern void __assert_fail (__const char *__assertion, __const char *__file, unsigned int __line, __const char *__function) @@ -74,7 +74,7 @@ int f4_2(void) { if (p != (short *)1) { *p = 5; // no-warning - p = (short *)1; // expected-warning {{Using a fixed address is not portable}} + p = (short *)1; } else return 1; @@ -138,7 +138,7 @@ void f8(struct f8_s *s, int coin) { void f9() { int (*p_function) (char, char) = (int (*)(char, char))0x04040; // FIXME: warn at this initialization - p_function = (int (*)(char, char))0x04080; // expected-warning {{Using a fixed address is not portable}} + p_function = (int (*)(char, char))0x04080; // FIXME: there should be a warning from calling the function pointer with fixed address int x = (*p_function) ('x', 'y'); } diff --git a/clang/test/Analysis/ptr-arith.c b/clang/test/Analysis/ptr-arith.c index 79ca190b25a0f..51a13b8cfb723 100644 --- a/clang/test/Analysis/ptr-arith.c +++ b/clang/test/Analysis/ptr-arith.c @@ -1,5 +1,5 @@ -// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.core.FixedAddr,alpha.core.PointerArithm,debug.ExprInspection -Wno-pointer-to-int-cast -verify -triple x86_64-apple-darwin9 -Wno-tautological-pointer-compare -analyzer-config eagerly-assume=false %s -// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.core.FixedAddr,alpha.core.PointerArithm,debug.ExprInspection -Wno-pointer-to-int-cast -verify -triple i686-apple-darwin9 -Wno-tautological-pointer-compare -analyzer-config eagerly-assume=false %s +// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.core.PointerArithm,debug.ExprInspection -Wno-pointer-to-int-cast -verify -triple x86_64-apple-darwin9 -Wno-tautological-pointer-compare -analyzer-config eagerly-assume=false %s +// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.core.PointerArithm,debug.ExprInspection -Wno-pointer-to-int-cast -verify -triple i686-apple-darwin9 -Wno-tautological-pointer-compare -analyzer-config eagerly-assume=false %s #include "Inputs/system-header-simulator.h" @@ -37,26 +37,6 @@ domain_port (const char *domain_b, const char *domain_e, return port; } -#define FIXED_VALUE (int*) 0x1111 - -void f4(void) { - int *p; - p = (int*) 0x10000; // expected-warning{{Using a fixed address is not portable because that address will probably not be valid in all environments or platforms}} - - int *p1; - p1 = p; // no warning - - long x = 0x10100; - x += 10; - p = (int*) x; // expected-warning{{Using a fixed address is not portable because that address will probably not be valid in all environments or platforms}} - - struct sigaction sa; - sa.sa_handler = SIG_IGN; // no warning (exclude macros defined in system header) - sigaction(SIGINT, &sa, NULL); - - p = FIXED_VALUE; // expected-warning{{Using a fixed address is not portable because that address will probably not be valid in all environments or platforms}} -} - void f5(void) { int x, y; int *p; diff --git a/llvm/utils/gn/secondary/clang/lib/StaticAnalyzer/Checkers/BUILD.gn b/llvm/utils/gn/secondary/clang/lib/StaticAnalyzer/Checkers/BUILD.gn index 3464c524190fa..85905ad40a329 100644 --- a/llvm/utils/gn/secondary/clang/lib/StaticAnalyzer/Checkers/BUILD.gn +++ b/llvm/utils/gn/secondary/clang/lib/StaticAnalyzer/Checkers/BUILD.gn @@ -53,7 +53,6 @@ static_library("Checkers") { "ErrnoModeling.cpp", "ErrnoTesterChecker.cpp", "ExprInspectionChecker.cpp", - "FixedAddressChecker.cpp", "FuchsiaHandleChecker.cpp", "GCDAntipatternChecker.cpp", "GTestChecker.cpp", _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
