]> granicus.if.org Git - clang/commitdiff
Perform an lvalue-to-rvalue conversion on an array index in a __builtin_offsetof...
authorRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 17 Oct 2011 05:48:07 +0000 (05:48 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 17 Oct 2011 05:48:07 +0000 (05:48 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142179 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/Sema/offsetof.c

index 83002d56956e82588fc7ce3db80b25ea60dd912c..ddcbb6d6b1b4eda4b96a5b65d2e01f2820b49032 100644 (file)
@@ -8383,10 +8383,14 @@ ExprResult Sema::BuildBuiltinOffsetOf(SourceLocation BuiltinLoc,
         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;
     }
     
index 5026193943fff0285e1ad27d33bbc68445f85c91..46fb515c7f2ed60df9ed1107bddf189bb219c572 100644 (file)
@@ -65,3 +65,7 @@ int test3 = __builtin_offsetof(struct has_bitfields, j); // expected-error{{cann
 
 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}}
+}