]> granicus.if.org Git - clang/commitdiff
Re-add objectsize function/incomplete type checks.
authorGeorge Burgess IV <george.burgess.iv@gmail.com>
Tue, 3 Jan 2017 23:35:19 +0000 (23:35 +0000)
committerGeorge Burgess IV <george.burgess.iv@gmail.com>
Tue, 3 Jan 2017 23:35:19 +0000 (23:35 +0000)
I accidentally omitted these when refactoring this code. This caused
problems when building parts of the test-suite on MacOS.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290916 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ExprConstant.cpp
test/CodeGen/object-size.c

index b3f8925b64643ae6552592ac2134e3b1f34a6b5a..6dcb705c44d37aaf291568bd9f9604476717c076 100644 (file)
@@ -7192,6 +7192,12 @@ static bool determineEndOffset(EvalInfo &Info, SourceLocation ExprLoc,
                                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 &Info, SourceLocation ExprLoc,
       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 &Info, SourceLocation ExprLoc,
   }
 
   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
index a3f3bce9295626ddb46292a8c15c3f109bf62e53..fe4c1859a272c013099a23d97da75674a071eaa5 100644 (file)
@@ -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);
+}