[cfe-commits] r102762 - in /cfe/trunk: lib/AST/Expr.cpp lib/Sema/TreeTransform.h test/Sema/offsetof.c

Douglas Gregor dgregor at apple.com
Fri Apr 30 13:35:01 PDT 2010


Author: dgregor
Date: Fri Apr 30 15:35:01 2010
New Revision: 102762

URL: http://llvm.org/viewvc/llvm-project?rev=102762&view=rev
Log:
Fix a thinko that caused us not to compute __builtin_offset as a
constant expression in C. 

Modified:
    cfe/trunk/lib/AST/Expr.cpp
    cfe/trunk/lib/Sema/TreeTransform.h
    cfe/trunk/test/Sema/offsetof.c

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=102762&r1=102761&r2=102762&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Fri Apr 30 15:35:01 2010
@@ -1943,7 +1943,6 @@
     case UnaryOperator::AddrOf:
     case UnaryOperator::Deref:
       return ICEDiag(2, E->getLocStart());
-    case UnaryOperator::OffsetOf:
     case UnaryOperator::Extension:
     case UnaryOperator::LNot:
     case UnaryOperator::Plus:
@@ -1952,7 +1951,11 @@
     case UnaryOperator::Real:
     case UnaryOperator::Imag:
       return CheckICE(Exp->getSubExpr(), Ctx);
+    case UnaryOperator::OffsetOf:
+      break;
     }
+    
+    // OffsetOf falls through here.
   }
   case Expr::OffsetOfExprClass: {
       // Note that per C99, offsetof must be an ICE. And AFAIK, using

Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=102762&r1=102761&r2=102762&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Fri Apr 30 15:35:01 2010
@@ -4202,6 +4202,7 @@
   for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
     const Node &ON = E->getComponent(I);
     Component Comp;
+    Comp.isBrackets = true;
     Comp.LocStart = ON.getRange().getBegin();
     Comp.LocEnd = ON.getRange().getEnd();
     switch (ON.getKind()) {

Modified: cfe/trunk/test/Sema/offsetof.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/offsetof.c?rev=102762&r1=102761&r2=102762&view=diff
==============================================================================
--- cfe/trunk/test/Sema/offsetof.c (original)
+++ cfe/trunk/test/Sema/offsetof.c Fri Apr 30 15:35:01 2010
@@ -62,3 +62,6 @@
 };
 
 int test3 = __builtin_offsetof(struct has_bitfields, j); // expected-error{{cannot compute offset of bit-field 'j'}}
+
+typedef struct Array { int array[1]; } Array;
+int test4 = __builtin_offsetof(Array, array);





More information about the cfe-commits mailing list