https://github.com/carsonRadtke updated https://github.com/llvm/llvm-project/pull/190131
>From 8ca8dfc0f2af8a6175aae7722341ea482ba9745b Mon Sep 17 00:00:00 2001 From: Carson Radtke <[email protected]> Date: Thu, 2 Apr 2026 02:08:39 -0600 Subject: [PATCH] [clang:static-analyze] fix: allow construction of atomic pointers from nullptr. fixes: https://github.com/llvm/llvm-project/issues/187925 Previous code did not handle passing AtomicType to `makeNullWithType` and this led to an assertion failure. This change updates `makeNullWithType` to allow for atomic types to be passed in and to "unwrap" them in order to get the correct pointer/reference type for constructing the nullptr. --- .../clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h | 7 ++++--- .../clang/StaticAnalyzer/Core/PathSensitive/SVals.h | 1 + clang/test/Analysis/atomics.c | 5 +++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h index 2911554de9d97..4ee21f4a637e8 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h @@ -346,11 +346,12 @@ class SValBuilder { /// \param type pointer type. loc::ConcreteInt makeNullWithType(QualType type) { // We cannot use the `isAnyPointerType()`. - assert((type->isPointerType() || type->isObjCObjectPointerType() || - type->isBlockPointerType() || type->isNullPtrType() || - type->isReferenceType()) && + assert((type->isObjCObjectPointerType() || Loc::isLocType(type)) && "makeNullWithType must use pointer type"); + type = + type->isAtomicType() ? type->getAs<AtomicType>()->getValueType() : type; + // The `sizeof(T&)` is `sizeof(T)`, thus we replace the reference with a // pointer. Here we assume that references are actually implemented by // pointers under-the-hood. diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h index aeb57b28077c6..d7644645b1c15 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h @@ -260,6 +260,7 @@ class Loc : public DefinedSVal { void dumpToStream(raw_ostream &Out) const; static bool isLocType(QualType T) { + T = T->isAtomicType() ? T->getAs<AtomicType>()->getValueType() : T; return T->isAnyPointerType() || T->isBlockPointerType() || T->isReferenceType() || T->isNullPtrType(); } diff --git a/clang/test/Analysis/atomics.c b/clang/test/Analysis/atomics.c index ef1a216c7d577..fc5ab5f589a00 100644 --- a/clang/test/Analysis/atomics.c +++ b/clang/test/Analysis/atomics.c @@ -101,3 +101,8 @@ void test_atomic_compare(int input) { // no crash } } + +void test_atomic_gh187925(void) { + void foo(_Atomic(void*)); + foo(0); // no assertion failure +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
