aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2011-07-20 04:31:01 +0000
committerChris Lattner <sabre@nondot.org>2011-07-20 04:31:01 +0000
commit410b12e55395216a02a848a791a38b0f153eba87 (patch)
tree77d6fe06fbb5e403e7d393be3287c9a40e09a58a
parent14ad03b6f4350f062256757efc4149a7df94bdf9 (diff)
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
-rw-r--r--lib/CodeGen/CGExprScalar.cpp5
-rw-r--r--test/CodeGenCXX/init-incomplete-type.cpp8
2 files changed, 11 insertions, 2 deletions
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; }
+}