blob: 9b3e294c7792f52235de41f6a115dcadbf8ba3a5 [file] [log] [blame]
Artem Dergachev4e864b82018-08-29 22:43:31 +00001// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-store=region -verify %s
2
3void clang_analyzer_eval(bool);
Jordan Rose36bc6b42013-09-18 18:58:58 +00004
5bool PR14634(int x) {
6 double y = (double)x;
7 return !y;
8}
9
10bool PR14634_implicit(int x) {
11 double y = (double)x;
12 return y;
13}
Jordan Rose7ae33622013-12-19 22:32:39 +000014
15void intAsBoolAsSwitchCondition(int c) {
Jordan Rose821f1022013-12-19 23:05:40 +000016 switch ((bool)c) { // expected-warning {{switch condition has boolean value}}
Jordan Rose7ae33622013-12-19 22:32:39 +000017 case 0:
18 break;
19 }
Jordan Rose821f1022013-12-19 23:05:40 +000020
21 switch ((int)(bool)c) { // no-warning
22 case 0:
23 break;
24 }
Jordan Rose7ae33622013-12-19 22:32:39 +000025}
Artem Dergachev2fd6aa72018-05-04 21:39:25 +000026
27int *&castToIntPtrLValueRef(char *p) {
28 return (int *&)*(int *)p;
29}
30bool testCastToIntPtrLValueRef(char *p, int *s) {
31 return castToIntPtrLValueRef(p) != s; // no-crash
32}
33
34int *&&castToIntPtrRValueRef(char *p) {
35 return (int *&&)*(int *)p;
36}
37bool testCastToIntPtrRValueRef(char *p, int *s) {
38 return castToIntPtrRValueRef(p) != s; // no-crash
39}
Artem Dergachev35dbd0b2018-07-17 00:42:35 +000040
41bool retrievePointerFromBoolean(int *p) {
42 bool q;
43 *reinterpret_cast<int **>(&q) = p;
44 return q;
45}
Artem Dergachev4e864b82018-08-29 22:43:31 +000046
47namespace base_to_derived {
48struct A {};
49struct B : public A{};
50
51void foo(A* a) {
52 B* b = (B* ) a;
53 A* a2 = (A *) b;
54 clang_analyzer_eval(a2 == a); // expected-warning{{TRUE}}
55}
56}
57
58namespace base_to_derived_double_inheritance {
59struct A {
60 int x;
61};
62struct B {
63 int y;
64};
65struct C : A, B {};
66
67void foo(B *b) {
68 C *c = (C *)b;
69 b->y = 1;
70 clang_analyzer_eval(c->x); // expected-warning{{UNKNOWN}}
71 clang_analyzer_eval(c->y); // expected-warning{{TRUE}}
72}
73}
74