[PATCH] D99274: [analyzer] Fix crash when reasoning about C11 atomics (PR49422)
Valeriy Savchenko via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 30 06:04:58 PDT 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaf7e1f07ac03: [analyzer] Fix crash when reasoning about C11 atomics (PR49422) (authored by vsavchenko).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D99274/new/
https://reviews.llvm.org/D99274
Files:
clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
clang/test/Analysis/atomics.c
Index: clang/test/Analysis/atomics.c
===================================================================
--- clang/test/Analysis/atomics.c
+++ clang/test/Analysis/atomics.c
@@ -93,3 +93,11 @@
clang_analyzer_eval(s->refCount == 3); // expected-warning {{UNKNOWN}}
clang_analyzer_eval(expected == 2); // expected-warning {{UNKNOWN}}
}
+
+// PR49422
+void test_atomic_compare(int input) {
+ _Atomic(int) x = input;
+ if (x > 0) {
+ // no crash
+ }
+}
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
===================================================================
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
@@ -139,6 +139,12 @@
/// Returns the type of the APSInt used to store values of the given QualType.
APSIntType getAPSIntType(QualType T) const {
+ // For the purposes of the analysis and constraints, we treat atomics
+ // as their underlying types.
+ if (const AtomicType *AT = T->getAs<AtomicType>()) {
+ T = AT->getValueType();
+ }
+
assert(T->isIntegralOrEnumerationType() || Loc::isLocType(T));
return APSIntType(Ctx.getIntWidth(T),
!T->isSignedIntegerOrEnumerationType());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99274.334130.patch
Type: text/x-patch
Size: 1302 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210330/f078af7f/attachment.bin>
More information about the cfe-commits
mailing list