https://github.com/carsonRadtke created 
https://github.com/llvm/llvm-project/pull/190131

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.

>From a4c0092b17fc2183446bb8aaae24f7ebf209c6b6 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 | 8 +++++---
 .../clang/StaticAnalyzer/Core/PathSensitive/SVals.h       | 3 +++
 clang/test/Analysis/atomics.c                             | 5 +++++
 3 files changed, 13 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..2df0aa33f2cc8 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
@@ -346,11 +346,13 @@ 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..4207432be2ae6 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
@@ -260,6 +260,9 @@ 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

Reply via email to