diff options
| author | Richard Trieu <rtrieu@google.com> | 2016-08-05 02:39:30 +0000 |
|---|---|---|
| committer | Richard Trieu <rtrieu@google.com> | 2016-08-05 02:39:30 +0000 |
| commit | 7561ed01cb762d336d60dc2b05faab6c948e11fd (patch) | |
| tree | 860d64bcc17e554b261176f6935f726ce28849b6 /clang/test | |
| parent | a425623dd9907bf5433e2bf0f64b7e0dcb2b4a8a (diff) | |
| download | bcm5719-llvm-7561ed01cb762d336d60dc2b05faab6c948e11fd.tar.gz bcm5719-llvm-7561ed01cb762d336d60dc2b05faab6c948e11fd.zip | |
Allow -1 to assign max value to unsigned bitfields.
Silence the -Wbitfield-constant-conversion warning for when -1 or other
negative values are assigned to unsigned bitfields, provided that the bitfield
is wider than the minimum number of bits needed to encode the negative value.
llvm-svn: 277796
Diffstat (limited to 'clang/test')
| -rw-r--r-- | clang/test/Sema/bitfield.c | 2 | ||||
| -rw-r--r-- | clang/test/Sema/constant-conversion.c | 12 |
2 files changed, 13 insertions, 1 deletions
diff --git a/clang/test/Sema/bitfield.c b/clang/test/Sema/bitfield.c index 810dc798eaa..d625366e4e1 100644 --- a/clang/test/Sema/bitfield.c +++ b/clang/test/Sema/bitfield.c @@ -64,7 +64,7 @@ typedef signed Signed; struct Test5 { unsigned n : 2; } t5; // Bitfield is unsigned -struct Test5 sometest5 = {-1}; // expected-warning {{implicit truncation from 'int' to bitfield changes value from -1 to 3}} +struct Test5 sometest5 = {-1}; typedef __typeof__(+t5.n) Signed; // ... but promotes to signed. typedef __typeof__(t5.n + 0) Signed; // Arithmetic promotes. diff --git a/clang/test/Sema/constant-conversion.c b/clang/test/Sema/constant-conversion.c index b717f932533..203e7373897 100644 --- a/clang/test/Sema/constant-conversion.c +++ b/clang/test/Sema/constant-conversion.c @@ -113,3 +113,15 @@ void test9() { char array_init[] = { 255, 127, 128, 129, 0 }; } + +void test10() { + struct S { + unsigned a : 4; + } s; + s.a = -1; + s.a = 15; + s.a = -8; + + s.a = -9; // expected-warning{{implicit truncation from 'int' to bitfield changes value from -9 to 7}} + s.a = 16; // expected-warning{{implicit truncation from 'int' to bitfield changes value from 16 to 0}} +} |

