[PATCH] D61106: [analyzer][UninitializedObjectChecker] PR41590: Regard _Atomic types as primitive

Kristóf Umann via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 24 17:25:59 PDT 2019


Szelethus created this revision.
Szelethus added reviewers: NoQ, dcoughlin, baloghadamsoftware, Charusso, rnkovacs, xazax.hun, gribozavr.
Szelethus added a project: clang.
Herald added subscribers: cfe-commits, gamesh411, dkrupp, donat.nagy, jfb, mikhail.ramalho, a.sidorin, szepet, whisperity.

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.


Repository:
  rC Clang

https://reviews.llvm.org/D61106

Files:
  lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h
  test/Analysis/cxx-uninitialized-object.cpp


Index: test/Analysis/cxx-uninitialized-object.cpp
===================================================================
--- test/Analysis/cxx-uninitialized-object.cpp
+++ test/Analysis/cxx-uninitialized-object.cpp
@@ -1130,3 +1130,18 @@
   // 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;
+}
Index: lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h
===================================================================
--- lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h
+++ lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h
@@ -324,7 +324,7 @@
 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) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61106.196558.patch
Type: text/x-patch
Size: 1402 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190425/c3e06650/attachment.bin>


More information about the cfe-commits mailing list