r235816 - [Sema] Don't allow unverified bitfields in FieldDecls

David Majnemer david.majnemer at gmail.com
Sat Apr 25 21:58:18 PDT 2015


Author: majnemer
Date: Sat Apr 25 23:58:18 2015
New Revision: 235816

URL: http://llvm.org/viewvc/llvm-project?rev=235816&view=rev
Log:
[Sema] Don't allow unverified bitfields in FieldDecls

VerifyBitField must be called if we are to form a bitfield FieldDecl.
We will not verify the bitfield if the decl is known to be malformed in
other ways; pretend that we don't have a bitfield if this happens.

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/Sema/bitfield.c

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=235816&r1=235815&r2=235816&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sat Apr 25 23:58:18 2015
@@ -12481,8 +12481,10 @@ FieldDecl *Sema::CheckFieldDecl(Declarat
     InvalidDecl = true;
 
   bool ZeroWidth = false;
+  if (InvalidDecl)
+    BitWidth = nullptr;
   // If this is declared as a bit-field, check the bit-field.
-  if (!InvalidDecl && BitWidth) {
+  if (BitWidth) {
     BitWidth = VerifyBitField(Loc, II, T, Record->isMsStruct(Context), BitWidth,
                               &ZeroWidth).get();
     if (!BitWidth) {

Modified: cfe/trunk/test/Sema/bitfield.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/bitfield.c?rev=235816&r1=235815&r2=235816&view=diff
==============================================================================
--- cfe/trunk/test/Sema/bitfield.c (original)
+++ cfe/trunk/test/Sema/bitfield.c Sat Apr 25 23:58:18 2015
@@ -74,3 +74,7 @@ typedef __typeof__(+(--t5.n)) Signed; //
 
 typedef __typeof__(+(t5.n++)) Unsigned; // Post-increment is underspecified, but seems to
 typedef __typeof__(+(t5.n--)) Unsigned; // also act like compound-assignment.
+
+struct Test6 {
+  : 0.0; // expected-error{{type name requires a specifier or qualifier}}
+};





More information about the cfe-commits mailing list