]> granicus.if.org Git - clang/commitdiff
[analyzer] PR41753: Include complex integer types in NonLoc::isCompoundType
authorKristof Umann <kristof.umann@ericsson.com>
Sat, 18 May 2019 12:34:08 +0000 (12:34 +0000)
committerKristof Umann <kristof.umann@ericsson.com>
Sat, 18 May 2019 12:34:08 +0000 (12:34 +0000)
https://bugs.llvm.org/show_bug.cgi?id=41753

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

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

include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
test/Analysis/complex.c
test/Analysis/cxx-uninitialized-object.cpp

index e859936621d0beee3175154f729fee682fa98eff..8861f1504814dbbf713206d92fcd1e4dd109e350 100644 (file)
@@ -303,7 +303,7 @@ public:
 
   static bool isCompoundType(QualType T) {
     return T->isArrayType() || T->isRecordType() ||
-           T->isComplexType() || T->isVectorType();
+           T->isAnyComplexType() || T->isVectorType();
   }
 
 private:
index 1f61b141cb31934f1ca1243b64bd275ceab46f53..fab61bf71447f7059572dd48faa4b0f754f5715d 100644 (file)
@@ -1,9 +1,13 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-store=region -verify -Wno-unreachable-code -ffreestanding %s
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -Wno-unreachable-code -ffreestanding \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=debug.ExprInspection
 
 #include <stdint.h>
 
+int clang_analyzer_eval(int);
+
 void f1(int * p) {
-  
   // This branch should be infeasible
   // because __imag__ p is 0.
   if (!p && __imag__ (intptr_t) p)
@@ -15,3 +19,25 @@ void f1(int * p) {
     
   *p = 2; // expected-warning{{Dereference of null pointer}}
 }
+
+void complexFloat(__complex__ float f) {
+  clang_analyzer_eval(__real__(f) == 1); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(__imag__(f) == 1); // expected-warning{{UNKNOWN}}
+
+  __real__(f) = 1;
+  __imag__(f) = 1;
+
+  clang_analyzer_eval(__real__(f) == 1); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(__imag__(f) == 1); // expected-warning{{UNKNOWN}}
+}
+
+void complexInt(__complex__ int f) {
+  clang_analyzer_eval(__real__(f) == 1); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(__imag__(f) == 1); // expected-warning{{UNKNOWN}}
+
+  __real__(f) = 1;
+  __imag__(f) = 1;
+
+  clang_analyzer_eval(__real__(f) == 1); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(__imag__(f) == 1); // expected-warning{{UNKNOWN}}
+}
index dde99dc95405f4a7aab3cfd1a04a91acfeb27e28..e3fa8ae8d7f2957f62c280c6b6b4c9ab1238e6ae 100644 (file)
@@ -1167,20 +1167,17 @@ struct ComplexUninitTest {
   __complex__ int y;
 };
 
-// FIXME: Currently this causes (unrelated to this checker) an assertion
-// failure.
-//
-//struct ComplexInitTest {
-//  ComplexInitTest() {
-//    x = {1.0f, 1.0f};
-//    y = {1, 1};
-//  }
-//  __complex__ float x;
-//  __complex__ int y;
-//};
+struct ComplexInitTest {
+  ComplexInitTest() {
+    x = {1.0f, 1.0f};
+    y = {1, 1};
+  }
+  __complex__ float x;
+  __complex__ int y;
+};
 
 void fComplexTest() {
-//  ComplexInitTest x;
+  ComplexInitTest x;
 
   // TODO: we should emit a warning for x2.x and x2.y.
   ComplexUninitTest x2;