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

Richard Smith richard-llvm at metafoo.co.uk
Sun Oct 16 22:48:08 PDT 2011


Author: rsmith
Date: Mon Oct 17 00:48:07 2011
New Revision: 142179

URL: http://llvm.org/viewvc/llvm-project?rev=142179&view=rev
Log:
Perform an lvalue-to-rvalue conversion on an array index in a __builtin_offsetof expression.

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

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=142179&r1=142178&r2=142179&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Oct 17 00:48:07 2011
@@ -8383,10 +8383,14 @@
         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(Idx);
+      Exprs.push_back(IdxRvalue.take());
       continue;
     }
     

Modified: cfe/trunk/test/Sema/offsetof.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/offsetof.c?rev=142179&r1=142178&r2=142179&view=diff
==============================================================================
--- cfe/trunk/test/Sema/offsetof.c (original)
+++ cfe/trunk/test/Sema/offsetof.c Mon Oct 17 00:48:07 2011
@@ -65,3 +65,7 @@
 
 typedef struct Array { int array[1]; } Array;
 int test4 = __builtin_offsetof(Array, array);
+
+int test5() {
+  return __builtin_offsetof(Array, array[*(int*)0]); // expected-warning{{indirection of non-volatile null pointer}} expected-note{{__builtin_trap}}
+}





More information about the cfe-commits mailing list