[cfe-commits] r142308 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaCXX/offsetof.cpp

Richard Smith richard-llvm at metafoo.co.uk
Mon Oct 17 16:29:39 PDT 2011


Author: rsmith
Date: Mon Oct 17 18:29:39 2011
New Revision: 142308

URL: http://llvm.org/viewvc/llvm-project?rev=142308&view=rev
Log:
Perform lvalue-to-rvalue conversions on __builtin_offsetof array argument index
before typechecking, as suggested by John.

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaCXX/offsetof.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=142308&r1=142307&r2=142308&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Oct 17 18:29:39 2011
@@ -8393,22 +8393,22 @@
       } else
         CurrentType = Context.DependentTy;
       
+      ExprResult IdxRval = DefaultLvalueConversion(static_cast<Expr*>(OC.U.E));
+      if (IdxRval.isInvalid())
+        return ExprError();
+      Expr *Idx = IdxRval.take();
+
       // The expression must be an integral expression.
       // FIXME: An integral constant expression?
-      Expr *Idx = static_cast<Expr*>(OC.U.E);
       if (!Idx->isTypeDependent() && !Idx->isValueDependent() &&
           !Idx->getType()->isIntegerType())
         return ExprError(Diag(Idx->getLocStart(),
                               diag::err_typecheck_subscript_not_integer)
                          << Idx->getSourceRange());
 
-      ExprResult IdxRvalue = DefaultLvalueConversion(Idx);
-      if (IdxRvalue.isInvalid())
-        return ExprError();
-      
       // Record this array index.
       Comps.push_back(OffsetOfNode(OC.LocStart, Exprs.size(), OC.LocEnd));
-      Exprs.push_back(IdxRvalue.take());
+      Exprs.push_back(Idx);
       continue;
     }
     

Modified: cfe/trunk/test/SemaCXX/offsetof.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/offsetof.cpp?rev=142308&r1=142307&r2=142308&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/offsetof.cpp (original)
+++ cfe/trunk/test/SemaCXX/offsetof.cpp Mon Oct 17 18:29:39 2011
@@ -66,3 +66,10 @@
 };
 
 int anonstruct[__builtin_offsetof(bar, x) == 0 ? 1 : -1];
+
+struct LtoRCheck {
+  int a[10];
+  int f();
+};
+int ltor = __builtin_offsetof(struct LtoRCheck, a[LtoRCheck().f]); // \
+  expected-error {{reference to non-static member function must be called}}





More information about the cfe-commits mailing list