xref: /llvm-project/clang/test/Analysis/complex.c (revision f40c18b628f3b0008acf4f9ac0102f103b690cc2)
1 // RUN: %clang_analyze_cc1 -verify %s \
2 // RUN:   -Wno-unreachable-code -ffreestanding \
3 // RUN:   -analyzer-checker=core \
4 // RUN:   -analyzer-checker=debug.ExprInspection
5 
6 #include <stdint.h>
7 
8 int clang_analyzer_eval(int);
9 
f1(int * p)10 void f1(int * p) {
11   // This branch should be infeasible
12   // because __imag__ p is 0.
13   if (!p && __imag__ (intptr_t) p)
14     *p = 1; // no-warning
15 
16   // If p != 0 then this branch is feasible; otherwise it is not.
17   if (__real__ (intptr_t) p)
18     *p = 1; // no-warning
19 
20   *p = 2; // expected-warning{{Dereference of null pointer}}
21 }
22 
complexFloat(__complex__ float f)23 void complexFloat(__complex__ float f) {
24   clang_analyzer_eval(__real__(f) == 1); // expected-warning{{UNKNOWN}}
25   clang_analyzer_eval(__imag__(f) == 1); // expected-warning{{UNKNOWN}}
26 
27   __real__(f) = 1;
28   __imag__(f) = 1;
29 
30   clang_analyzer_eval(__real__(f) == 1); // expected-warning{{UNKNOWN}}
31   clang_analyzer_eval(__imag__(f) == 1); // expected-warning{{UNKNOWN}}
32 }
33 
complexInt(__complex__ int f)34 void complexInt(__complex__ int f) {
35   clang_analyzer_eval(__real__(f) == 1); // expected-warning{{UNKNOWN}}
36   clang_analyzer_eval(__imag__(f) == 1); // expected-warning{{UNKNOWN}}
37 
38   __real__(f) = 1;
39   __imag__(f) = 1;
40 
41   clang_analyzer_eval(__real__(f) == 1); // expected-warning{{UNKNOWN}}
42   clang_analyzer_eval(__imag__(f) == 1); // expected-warning{{UNKNOWN}}
43 }
44