1 // RUN: %clang_cc1 -Wno-conversion -analyze -analyzer-checker=core,alpha.core.Conversion -verify %s
6 void assign(unsigned U, signed S) {
8 U8 = S; // expected-warning {{Loss of sign in implicit conversion}}
10 S8 = U; // expected-warning {{Loss of precision in implicit conversion}}
18 long long A = 1LL << 60;
19 short X = A; // expected-warning {{Loss of precision in implicit conversion}}
22 void relational(unsigned U, signed S) {
28 if (U < S) { // expected-warning {{Loss of sign in implicit conversion}}
33 void multiplication(unsigned U, signed S) {
37 S = U * S; // expected-warning {{Loss of sign}}
40 void division(unsigned U, signed S) {
44 S = U / S; // expected-warning {{Loss of sign}}
47 void dontwarn1(unsigned U, signed S) {
48 U8 = S; // It might be known that S is always 0x00-0xff.
49 S8 = U; // It might be known that U is always 0x00-0xff.
51 U8 = -1; // Explicit conversion.
52 S8 = ~0U; // Explicit conversion.
54 U8 &= U; // No loss of precision since there is &=.
57 void dontwarn2(unsigned int U) {
58 if (U <= 4294967295) {
60 if (U <= (2147483647 * 2U + 1U)) {
64 void dontwarn3(int X) {
68 // don't warn for macros
69 #define DOSTUFF ({ unsigned X = 1000; U8 = X; })
74 // don't warn for calculations
75 // seen some fp. For instance: c2 = (c2 >= 'A' && c2 <= 'Z') ? c2 - 'A' + 'a' : c2;
76 // there is a todo in the checker to handle calculations
86 void falsePositive1() {
90 // FIXME: should not warn here:
91 kb2[0] = X; // expected-warning {{Loss of precision}}
96 typedef struct FILE {} FILE; int getc(FILE *stream);
98 char reply_string[8192];
100 extern int dostuff (void);
101 int falsePositive2() {
104 char *cp = reply_string;
110 while ((c = getc(cin)) != '\n') {
111 if (dig < 4 && dostuff())
112 code = code * 10 + (c - '0');
113 if (!pflag && code == 227)
119 if (cp < &reply_string[sizeof(reply_string) - 1])
120 // FIXME: should not warn here:
121 *cp++ = c; // expected-warning {{Loss of precision}}