]> granicus.if.org Git - clang/commitdiff
[analyzer][UninitializedObjectChecker] PR41611: Regard vector types as primitive
authorKristof Umann <kristof.umann@ericsson.com>
Tue, 30 Apr 2019 08:47:56 +0000 (08:47 +0000)
committerKristof Umann <kristof.umann@ericsson.com>
Tue, 30 Apr 2019 08:47:56 +0000 (08:47 +0000)
https://bugs.llvm.org/show_bug.cgi?id=41611

Similarly to D61106, the checker ran over an llvm_unreachable for vector types:

struct VectorSizeLong {
  VectorSizeLong() {}
  __attribute__((__vector_size__(16))) long x;
};

void __vector_size__LongTest() {
  VectorSizeLong v;
}
Since, according to my short research,

"The vector_size attribute is only applicable to integral and float scalars,
although arrays, pointers, and function return values are allowed in conjunction
with this construct."
[src: https://gcc.gnu.org/onlinedocs/gcc-4.6.1/gcc/Vector-Extensions.html#Vector-Extensions]

vector types are safe to regard as primitive.

Differential Revision: https://reviews.llvm.org/D61246

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@359539 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h
test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
test/Analysis/cxx-uninitialized-object.cpp

index a0d3e56b1ceec3e19f78d21c2392f925600031d3..3f33443f98b792c4f56cf1c026593429f98bbfae 100644 (file)
@@ -324,7 +324,8 @@ private:
 inline bool isPrimitiveType(const QualType &T) {
   return T->isBuiltinType() || T->isEnumeralType() ||
          T->isMemberPointerType() || T->isBlockPointerType() ||
-         T->isFunctionType() || T->isAtomicType();
+         T->isFunctionType() || T->isAtomicType() ||
+         T->isVectorType();
 }
 
 inline bool isDereferencableType(const QualType &T) {
index 4f737fa31b09ca982314c0561a51acc70ff09438..5363831342fb10d26041535254421641cde6f7fc 100644 (file)
@@ -256,6 +256,29 @@ void fCharPointerTest() {
   CharPointerTest();
 }
 
+struct VectorSizePointer {
+  VectorSizePointer() {} // expected-warning{{1 uninitialized field}}
+  __attribute__((__vector_size__(8))) int *x; // expected-note{{uninitialized pointer 'this->x'}}
+  int dontGetFilteredByNonPedanticMode = 0;
+};
+
+void __vector_size__PointerTest() {
+  VectorSizePointer v;
+}
+
+struct VectorSizePointee {
+  using MyVectorType = __attribute__((__vector_size__(8))) int;
+  MyVectorType *x;
+
+  VectorSizePointee(decltype(x) x) : x(x) {}
+};
+
+void __vector_size__PointeeTest() {
+  VectorSizePointee::MyVectorType i;
+  // TODO: Report v.x's pointee.
+  VectorSizePointee v(&i);
+}
+
 struct CyclicPointerTest1 {
   int *ptr; // expected-note{{object references itself 'this->ptr'}}
   int dontGetFilteredByNonPedanticMode = 0;
index 86f2ecdd83a84c62f404eae4350b3eefca45b39e..a8113198541c64ebde57dcefde8ac11b8d2c281f 100644 (file)
@@ -1132,7 +1132,7 @@ void fCXX11MemberInitTest2() {
 }
 
 //===----------------------------------------------------------------------===//
-// _Atomic tests.
+// "Esoteric" primitive type tests.
 //===----------------------------------------------------------------------===//
 
 struct MyAtomicInt {
@@ -1142,6 +1142,17 @@ struct MyAtomicInt {
   MyAtomicInt() {} // expected-warning{{1 uninitialized field}}
 };
 
-void entry() {
+void _AtomicTest() {
   MyAtomicInt b;
 }
+
+struct VectorSizeLong {
+  VectorSizeLong() {}
+  __attribute__((__vector_size__(16))) long x;
+};
+
+void __vector_size__LongTest() {
+  // TODO: Warn for v.x.
+  VectorSizeLong v;
+  v.x[0] = 0;
+}