[clang] [analyzer][z3] Fix crash in Z3 SMTConv when casting atomic int (PR #211489)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 23 02:09:57 PDT 2026
https://github.com/guillem-bartrina-sonarsource updated https://github.com/llvm/llvm-project/pull/211489
>From fa9de228557198b532aab28d71e0887506cc20e6 Mon Sep 17 00:00:00 2001
From: guillem-bartrina-sonarsource <guillem.bartrina at sonarsource.com>
Date: Thu, 23 Jul 2026 09:47:53 +0200
Subject: [PATCH 1/2] Add crashing example
---
clang/test/Analysis/z3/z3-crosscheck.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/clang/test/Analysis/z3/z3-crosscheck.c b/clang/test/Analysis/z3/z3-crosscheck.c
index 41ecaee5529e0..79a93c9e5bae2 100644
--- a/clang/test/Analysis/z3/z3-crosscheck.c
+++ b/clang/test/Analysis/z3/z3-crosscheck.c
@@ -89,3 +89,14 @@ void e() {
int f;
a(f); // expected-warning {{1st function call argument is an uninitialized value [core.CallAndMessage]}}
}
+
+// don't crash, and also produce a core.NullDereference finding
+_Atomic int b;
+int x;
+void k(void) {
+ int *p = 0;
+ b = x;
+ if (b == 0) {
+ *p = 1; // expected-warning {{Dereference of null pointer (loaded from variable 'p') [core.NullDereference]}}
+ }
+}
>From 356c7bb645001422828b7dfb211f537ea64ac8e8 Mon Sep 17 00:00:00 2001
From: guillem-bartrina-sonarsource <guillem.bartrina at sonarsource.com>
Date: Thu, 23 Jul 2026 11:09:21 +0200
Subject: [PATCH 2/2] Consider atomic integer types for casting
---
.../include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h
index 4ba0483dc0380..61a71545fb1a6 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h
@@ -270,8 +270,8 @@ class SMTConv {
QualType ToTy, uint64_t ToBitWidth,
QualType FromTy,
uint64_t FromBitWidth) {
- if ((FromTy->isIntegralOrEnumerationType() &&
- ToTy->isIntegralOrEnumerationType()) ||
+ if ((FromTy.getAtomicUnqualifiedType()->isIntegralOrEnumerationType() &&
+ ToTy.getAtomicUnqualifiedType()->isIntegralOrEnumerationType()) ||
(FromTy->isAnyPointerType() ^ ToTy->isAnyPointerType()) ||
(FromTy->isBlockPointerType() ^ ToTy->isBlockPointerType()) ||
(FromTy->isReferenceType() ^ ToTy->isReferenceType())) {
More information about the cfe-commits
mailing list