From: Chris Lattner Date: Wed, 20 Jul 2011 04:31:01 +0000 (+0000) Subject: fix PR10395 - array decay can produce an interesting type when X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=410b12e55395216a02a848a791a38b0f153eba87;p=clang fix PR10395 - array decay can produce an interesting type when 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 --- diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index 37d424a2b3..f64e98ef68 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -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(); diff --git a/test/CodeGenCXX/init-incomplete-type.cpp b/test/CodeGenCXX/init-incomplete-type.cpp index 1755dfb7be..4f37eeb975 100644 --- a/test/CodeGenCXX/init-incomplete-type.cpp +++ b/test/CodeGenCXX/init-incomplete-type.cpp @@ -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; } +}