r359230 - [analyzer][UninitializedObjectChecker] PR41590: Regard _Atomic types as primitive
Kristof Umann via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 25 13:00:51 PDT 2019
Author: szelethus
Date: Thu Apr 25 13:00:51 2019
New Revision: 359230
URL: http://llvm.org/viewvc/llvm-project?rev=359230&view=rev
Log:
[analyzer][UninitializedObjectChecker] PR41590: Regard _Atomic types as primitive
https://bugs.llvm.org/show_bug.cgi?id=41590
For the following code snippet, UninitializedObjectChecker crashed:
struct MyAtomicInt {
_Atomic(int) x;
MyAtomicInt() {}
};
void entry() {
MyAtomicInt b;
}
The problem was that _Atomic types were not regular records, unions,
dereferencable or primitive, making the checker hit the llvm_unreachable at
lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp:347.
The solution is to regard these types as primitive as well. The test case shows
that with this addition, not only are we able to get rid of the crash, but we
can identify x as uninitialized.
Differential Revision: https://reviews.llvm.org/D61106
Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h
cfe/trunk/test/Analysis/cxx-uninitialized-object.cpp
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h?rev=359230&r1=359229&r2=359230&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h Thu Apr 25 13:00:51 2019
@@ -324,7 +324,7 @@ private:
inline bool isPrimitiveType(const QualType &T) {
return T->isBuiltinType() || T->isEnumeralType() ||
T->isMemberPointerType() || T->isBlockPointerType() ||
- T->isFunctionType();
+ T->isFunctionType() || T->isAtomicType();
}
inline bool isDereferencableType(const QualType &T) {
Modified: cfe/trunk/test/Analysis/cxx-uninitialized-object.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/cxx-uninitialized-object.cpp?rev=359230&r1=359229&r2=359230&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/cxx-uninitialized-object.cpp (original)
+++ cfe/trunk/test/Analysis/cxx-uninitialized-object.cpp Thu Apr 25 13:00:51 2019
@@ -1130,3 +1130,18 @@ void fCXX11MemberInitTest2() {
// TODO: we'd expect the warning: {{2 uninitializeds field}}
CXX11MemberInitTest2(); // no-warning
}
+
+//===----------------------------------------------------------------------===//
+// _Atomic tests.
+//===----------------------------------------------------------------------===//
+
+struct MyAtomicInt {
+ _Atomic(int) x; // expected-note{{uninitialized field 'this->x'}}
+ int dontGetFilteredByNonPedanticMode = 0;
+
+ MyAtomicInt() {} // expected-warning{{1 uninitialized field}}
+};
+
+void entry() {
+ MyAtomicInt b;
+}
More information about the cfe-commits
mailing list