[cfe-commits] r135565 - in /cfe/trunk: lib/CodeGen/CGExprScalar.cpp test/CodeGenCXX/init-incomplete-type.cpp

Chris Lattner sabre at nondot.org
Tue Jul 19 21:31:01 PDT 2011


Author: lattner
Date: Tue Jul 19 23:31:01 2011
New Revision: 135565

URL: http://llvm.org/viewvc/llvm-project?rev=135565&view=rev
Log:
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*).

Modified:
    cfe/trunk/lib/CodeGen/CGExprScalar.cpp
    cfe/trunk/test/CodeGenCXX/init-incomplete-type.cpp

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=135565&r1=135564&r2=135565&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Tue Jul 19 23:31:01 2011
@@ -1075,7 +1075,10 @@
       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();

Modified: cfe/trunk/test/CodeGenCXX/init-incomplete-type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/init-incomplete-type.cpp?rev=135565&r1=135564&r2=135565&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/init-incomplete-type.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/init-incomplete-type.cpp Tue Jul 19 23:31:01 2011
@@ -28,4 +28,10 @@
     return &g[1];
   }
 
-}
\ No newline at end of file
+}
+
+namespace PR10395 {
+  struct T;
+  extern T x[];
+  T* f() { return x; }
+}





More information about the cfe-commits mailing list