[cfe-commits] r62936 - in /cfe/trunk: include/clang/Basic/DiagnosticKinds.def lib/Sema/SemaExpr.cpp test/Sema/exprs.c

Chris Lattner sabre at nondot.org
Sat Jan 24 13:29:22 PST 2009


Author: lattner
Date: Sat Jan 24 15:29:22 2009
New Revision: 62936

URL: http://llvm.org/viewvc/llvm-project?rev=62936&view=rev
Log:
Implement C99 6.5.3.4p1, rejecting sizeof(bitfield)


Modified:
    cfe/trunk/include/clang/Basic/DiagnosticKinds.def
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/Sema/exprs.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=62936&r1=62935&r2=62936&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Sat Jan 24 15:29:22 2009
@@ -1192,8 +1192,8 @@
      "invalid application of 'sizeof' to an incomplete type %0")
 DIAG(err_alignof_incomplete_type, ERROR,
      "invalid application of '__alignof' to an incomplete type %0")
-DIAG(err_alignof_bitfield, ERROR,
-     "invalid application of '__alignof' to bitfield")
+DIAG(err_sizeof_alignof_bitfield, ERROR,
+     "invalid application of '%select{sizeof|__alignof}0' to bitfield")
 DIAG(err_offsetof_record_type, ERROR,
      "offsetof requires struct, union, or class type, %0 invalid")
 DIAG(err_offsetof_array_type, ERROR,

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=62936&r1=62935&r2=62936&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sat Jan 24 15:29:22 2009
@@ -1046,7 +1046,7 @@
   if (MemberExpr *ME = dyn_cast<MemberExpr>(E)) {
     if (FieldDecl *FD = dyn_cast<FieldDecl>(ME->getMemberDecl())) {
       if (FD->isBitField()) {
-        Diag(OpLoc, diag::err_alignof_bitfield) << ExprRange;
+        Diag(OpLoc, diag::err_sizeof_alignof_bitfield) << 1 << ExprRange;
         return true;
       }
       // Other fields are ok.
@@ -1082,10 +1082,14 @@
     
     // Verify that the operand is valid.
     bool isInvalid;
-    if (isSizeof)
-      isInvalid = CheckSizeOfAlignOfOperand(ArgTy, OpLoc, Range, true);
-    else
+    if (!isSizeof) {
       isInvalid = CheckAlignOfExpr(ArgEx, OpLoc, Range);
+    } else if (ArgEx->isBitField()) {  // C99 6.5.3.4p1.
+      Diag(OpLoc, diag::err_sizeof_alignof_bitfield) << 0;
+      isInvalid = true;
+    } else {
+      isInvalid = CheckSizeOfAlignOfOperand(ArgTy, OpLoc, Range, true);
+    }
     
     if (isInvalid) {
       DeleteExpr(ArgEx);

Modified: cfe/trunk/test/Sema/exprs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/exprs.c?rev=62936&r1=62935&r2=62936&view=diff

==============================================================================
--- cfe/trunk/test/Sema/exprs.c (original)
+++ cfe/trunk/test/Sema/exprs.c Sat Jan 24 15:29:22 2009
@@ -50,7 +50,10 @@
 // PR3386
 struct f { int x : 4;  float y[]; };
 int test9(struct f *P) {
-  return __alignof(P->x) +  // expected-error {{invalid application of '__alignof' to bitfield}} expected-warning {{extension used}}
-         __alignof(P->y);   // ok. expected-warning {{extension used}}
+  int R;
+  R = __alignof(P->x);  // expected-error {{invalid application of '__alignof' to bitfield}} expected-warning {{extension used}}
+  R = __alignof(P->y);   // ok. expected-warning {{extension used}}
+  R = sizeof(P->x); // expected-error {{invalid application of 'sizeof' to bitfield}}
+  return R;
 }
 





More information about the cfe-commits mailing list