]> granicus.if.org Git - clang/commitdiff
fix PR10395 - array decay can produce an interesting type when
authorChris Lattner <sabre@nondot.org>
Wed, 20 Jul 2011 04:31:01 +0000 (04:31 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 20 Jul 2011 04:31:01 +0000 (04:31 +0000)
decaying an array of incomplete type (which has type [0 x i8]*) to a
normal pointer (which has incompletetype*).

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

lib/CodeGen/CGExprScalar.cpp
test/CodeGenCXX/init-incomplete-type.cpp

index 37d424a2b35868b4b5e4a04d5882bae63c0f6607..f64e98ef684364f68fdc16b23bc7adeb3d21f7bb 100644 (file)
@@ -1075,7 +1075,10 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
       V = Builder.CreateStructGEP(V, 0, "arraydecay");
     }
 
-    return V;
+    // Make sure the array decay ends up being the right type.  This matters if
+    // the array type was of an incomplete type.
+    return CGF.Builder.CreateBitCast(V, 
+                              CGF.getTypes().ConvertTypeForMem(CE->getType()));
   }
   case CK_FunctionToPointerDecay:
     return EmitLValue(E).getAddress();
index 1755dfb7beb18293a6621ac999bf4f60d4eb4f4a..4f37eeb97549019f18ddca663e20bce301a3cb36 100644 (file)
@@ -28,4 +28,10 @@ namespace incomplete_type_refs {
     return &g[1];
   }
 
-}
\ No newline at end of file
+}
+
+namespace PR10395 {
+  struct T;
+  extern T x[];
+  T* f() { return x; }
+}