blob: 757eb6da6623682a5c21fea801beb90bdfcd03d5 [file] [log] [blame]
Dominic Chen184c6242017-03-03 18:02:02 +00001// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-store=region -verify %s
Jordan Rose36bc6b42013-09-18 18:58:58 +00002
3bool PR14634(int x) {
4 double y = (double)x;
5 return !y;
6}
7
8bool PR14634_implicit(int x) {
9 double y = (double)x;
10 return y;
11}
Jordan Rose7ae33622013-12-19 22:32:39 +000012
13void intAsBoolAsSwitchCondition(int c) {
Jordan Rose821f1022013-12-19 23:05:40 +000014 switch ((bool)c) { // expected-warning {{switch condition has boolean value}}
Jordan Rose7ae33622013-12-19 22:32:39 +000015 case 0:
16 break;
17 }
Jordan Rose821f1022013-12-19 23:05:40 +000018
19 switch ((int)(bool)c) { // no-warning
20 case 0:
21 break;
22 }
Jordan Rose7ae33622013-12-19 22:32:39 +000023}
Artem Dergachev2fd6aa72018-05-04 21:39:25 +000024
25int *&castToIntPtrLValueRef(char *p) {
26 return (int *&)*(int *)p;
27}
28bool testCastToIntPtrLValueRef(char *p, int *s) {
29 return castToIntPtrLValueRef(p) != s; // no-crash
30}
31
32int *&&castToIntPtrRValueRef(char *p) {
33 return (int *&&)*(int *)p;
34}
35bool testCastToIntPtrRValueRef(char *p, int *s) {
36 return castToIntPtrRValueRef(p) != s; // no-crash
37}
Artem Dergachev35dbd0b2018-07-17 00:42:35 +000038
39bool retrievePointerFromBoolean(int *p) {
40 bool q;
41 *reinterpret_cast<int **>(&q) = p;
42 return q;
43}