r290916 - Re-add objectsize function/incomplete type checks.

George Burgess IV via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 3 15:35:20 PST 2017


Author: gbiv
Date: Tue Jan  3 17:35:19 2017
New Revision: 290916

URL: http://llvm.org/viewvc/llvm-project?rev=290916&view=rev
Log:
Re-add objectsize function/incomplete type checks.

I accidentally omitted these when refactoring this code. This caused
problems when building parts of the test-suite on MacOS.

Modified:
    cfe/trunk/lib/AST/ExprConstant.cpp
    cfe/trunk/test/CodeGen/object-size.c

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=290916&r1=290915&r2=290916&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Tue Jan  3 17:35:19 2017
@@ -7192,6 +7192,12 @@ static bool determineEndOffset(EvalInfo
                                CharUnits &EndOffset) {
   bool DetermineForCompleteObject = refersToCompleteObject(LVal);
 
+  auto CheckedHandleSizeof = [&](QualType Ty, CharUnits &Result) {
+    if (Ty.isNull() || Ty->isIncompleteType() || Ty->isFunctionType())
+      return false;
+    return HandleSizeof(Info, ExprLoc, Ty, Result);
+  };
+
   // We want to evaluate the size of the entire object. This is a valid fallback
   // for when Type=1 and the designator is invalid, because we're asked for an
   // upper-bound.
@@ -7209,7 +7215,7 @@ static bool determineEndOffset(EvalInfo
       return false;
 
     QualType BaseTy = getObjectType(LVal.getLValueBase());
-    return !BaseTy.isNull() && HandleSizeof(Info, ExprLoc, BaseTy, EndOffset);
+    return CheckedHandleSizeof(BaseTy, EndOffset);
   }
 
   // We want to evaluate the size of a subobject.
@@ -7238,7 +7244,7 @@ static bool determineEndOffset(EvalInfo
   }
 
   CharUnits BytesPerElem;
-  if (!HandleSizeof(Info, ExprLoc, Designator.MostDerivedType, BytesPerElem))
+  if (!CheckedHandleSizeof(Designator.MostDerivedType, BytesPerElem))
     return false;
 
   // According to the GCC documentation, we want the size of the subobject

Modified: cfe/trunk/test/CodeGen/object-size.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/object-size.c?rev=290916&r1=290915&r2=290916&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/object-size.c (original)
+++ cfe/trunk/test/CodeGen/object-size.c Tue Jan  3 17:35:19 2017
@@ -536,3 +536,16 @@ void PR30346() {
   // CHECK: store i32 14
   gi = __builtin_object_size(sa->sa_data, 3);
 }
+
+extern char incomplete_char_array[];
+// CHECK-LABEL: @incomplete_and_function_types
+int incomplete_and_function_types() {
+  // CHECK: call i64 @llvm.objectsize.i64.p0i8
+  gi = __builtin_object_size(incomplete_char_array, 0);
+  // CHECK: call i64 @llvm.objectsize.i64.p0i8
+  gi = __builtin_object_size(incomplete_char_array, 1);
+  // CHECK: call i64 @llvm.objectsize.i64.p0i8
+  gi = __builtin_object_size(incomplete_char_array, 2);
+  // CHECK: store i32 0
+  gi = __builtin_object_size(incomplete_char_array, 3);
+}




More information about the cfe-commits mailing list