summaryrefslogtreecommitdiffstats
path: root/test/Sema/constant-conversion.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/Sema/constant-conversion.c')
-rw-r--r--test/Sema/constant-conversion.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/test/Sema/constant-conversion.c b/test/Sema/constant-conversion.c
index 7c6b9b8..1376333 100644
--- a/test/Sema/constant-conversion.c
+++ b/test/Sema/constant-conversion.c
@@ -31,8 +31,8 @@ void test3() {
int bar : 2;
};
- struct A a = { 0, 10 }; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 10 to 2}}
- struct A b[] = { 0, 10, 0, 0 }; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 10 to 2}}
+ struct A a = { 0, 10 }; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 10 to -2}}
+ struct A b[] = { 0, 10, 0, 0 }; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 10 to -2}}
struct A c[] = {{10, 0}}; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 10 to 2}}
struct A d = (struct A) { 10, 0 }; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 10 to 2}}
struct A e = { .foo = 10 }; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 10 to 2}}
@@ -55,3 +55,28 @@ void test5() {
// don't warn about it just because it's a bitfield.
a.b = 100;
}
+
+void test6() {
+ // Test that unreachable code doesn't trigger the truncation warning.
+ unsigned char x = 0 ? 65535 : 1; // no-warning
+ unsigned char y = 1 ? 65535 : 1; // expected-warning {{changes value}}
+}
+
+void test7() {
+ struct {
+ unsigned int twoBits1:2;
+ unsigned int twoBits2:2;
+ unsigned int reserved:28;
+ } f;
+
+ f.twoBits1 = ~1; // expected-warning {{implicit truncation from 'int' to bitfield changes value from -2 to 2}}
+ f.twoBits2 = ~2; // expected-warning {{implicit truncation from 'int' to bitfield changes value from -3 to 1}}
+ f.twoBits1 &= ~1; // no-warning
+ f.twoBits2 &= ~2; // no-warning
+}
+
+void test8() {
+ enum E { A, B, C };
+ struct { enum E x : 1; } f;
+ f.x = C; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 2 to 0}}
+}
OpenPOWER on IntegriCloud