Dominic Chen | 184c624 | 2017-03-03 18:02:02 +0000 | [diff] [blame] | 1 | // RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-store=region -verify %s |
Jordan Rose | 36bc6b4 | 2013-09-18 18:58:58 +0000 | [diff] [blame] | 2 | |
| 3 | bool PR14634(int x) { |
| 4 | double y = (double)x; |
| 5 | return !y; |
| 6 | } |
| 7 | |
| 8 | bool PR14634_implicit(int x) { |
| 9 | double y = (double)x; |
| 10 | return y; |
| 11 | } |
Jordan Rose | 7ae3362 | 2013-12-19 22:32:39 +0000 | [diff] [blame] | 12 | |
| 13 | void intAsBoolAsSwitchCondition(int c) { |
Jordan Rose | 821f102 | 2013-12-19 23:05:40 +0000 | [diff] [blame] | 14 | switch ((bool)c) { // expected-warning {{switch condition has boolean value}} |
Jordan Rose | 7ae3362 | 2013-12-19 22:32:39 +0000 | [diff] [blame] | 15 | case 0: |
| 16 | break; |
| 17 | } |
Jordan Rose | 821f102 | 2013-12-19 23:05:40 +0000 | [diff] [blame] | 18 | |
| 19 | switch ((int)(bool)c) { // no-warning |
| 20 | case 0: |
| 21 | break; |
| 22 | } |
Jordan Rose | 7ae3362 | 2013-12-19 22:32:39 +0000 | [diff] [blame] | 23 | } |
Artem Dergachev | 2fd6aa7 | 2018-05-04 21:39:25 +0000 | [diff] [blame] | 24 | |
| 25 | int *&castToIntPtrLValueRef(char *p) { |
| 26 | return (int *&)*(int *)p; |
| 27 | } |
| 28 | bool testCastToIntPtrLValueRef(char *p, int *s) { |
| 29 | return castToIntPtrLValueRef(p) != s; // no-crash |
| 30 | } |
| 31 | |
| 32 | int *&&castToIntPtrRValueRef(char *p) { |
| 33 | return (int *&&)*(int *)p; |
| 34 | } |
| 35 | bool testCastToIntPtrRValueRef(char *p, int *s) { |
| 36 | return castToIntPtrRValueRef(p) != s; // no-crash |
| 37 | } |
Artem Dergachev | 35dbd0b | 2018-07-17 00:42:35 +0000 | [diff] [blame^] | 38 | |
| 39 | bool retrievePointerFromBoolean(int *p) { |
| 40 | bool q; |
| 41 | *reinterpret_cast<int **>(&q) = p; |
| 42 | return q; |
| 43 | } |