From c84d25821d54653102ea897a05b9c1fb9be294bf Mon Sep 17 00:00:00 2001 From: Kristof Umann Date: Sat, 18 May 2019 12:34:08 +0000 Subject: [PATCH] [analyzer] PR41753: Include complex integer types in NonLoc::isCompoundType 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 --- .../StaticAnalyzer/Core/PathSensitive/SVals.h | 2 +- test/Analysis/complex.c | 30 +++++++++++++++++-- test/Analysis/cxx-uninitialized-object.cpp | 21 ++++++------- 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h b/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h index e859936621..8861f15048 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h @@ -303,7 +303,7 @@ public: static bool isCompoundType(QualType T) { return T->isArrayType() || T->isRecordType() || - T->isComplexType() || T->isVectorType(); + T->isAnyComplexType() || T->isVectorType(); } private: diff --git a/test/Analysis/complex.c b/test/Analysis/complex.c index 1f61b141cb..fab61bf714 100644 --- a/test/Analysis/complex.c +++ b/test/Analysis/complex.c @@ -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 +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}} +} diff --git a/test/Analysis/cxx-uninitialized-object.cpp b/test/Analysis/cxx-uninitialized-object.cpp index dde99dc954..e3fa8ae8d7 100644 --- a/test/Analysis/cxx-uninitialized-object.cpp +++ b/test/Analysis/cxx-uninitialized-object.cpp @@ -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; -- 2.50.1