Skip to content

Commit f46c58e

Browse files
author
Kristof Umann
committedApr 25, 2019
[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 llvm-svn: 359230
1 parent 65d4d5e commit f46c58e

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed
 

‎clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ class FindUninitializedFields {
324324
inline bool isPrimitiveType(const QualType &T) {
325325
return T->isBuiltinType() || T->isEnumeralType() ||
326326
T->isMemberPointerType() || T->isBlockPointerType() ||
327-
T->isFunctionType();
327+
T->isFunctionType() || T->isAtomicType();
328328
}
329329

330330
inline bool isDereferencableType(const QualType &T) {

‎clang/test/Analysis/cxx-uninitialized-object.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,3 +1130,18 @@ void fCXX11MemberInitTest2() {
11301130
// TODO: we'd expect the warning: {{2 uninitializeds field}}
11311131
CXX11MemberInitTest2(); // no-warning
11321132
}
1133+
1134+
//===----------------------------------------------------------------------===//
1135+
// _Atomic tests.
1136+
//===----------------------------------------------------------------------===//
1137+
1138+
struct MyAtomicInt {
1139+
_Atomic(int) x; // expected-note{{uninitialized field 'this->x'}}
1140+
int dontGetFilteredByNonPedanticMode = 0;
1141+
1142+
MyAtomicInt() {} // expected-warning{{1 uninitialized field}}
1143+
};
1144+
1145+
void entry() {
1146+
MyAtomicInt b;
1147+
}

0 commit comments

Comments
 (0)
Please sign in to comment.