[cfe-commits] r53946 - in /cfe/trunk: lib/CodeGen/CGExprScalar.cpp test/CodeGen/pointer-to-int.c

Chris Lattner sabre at nondot.org
Tue Jul 22 23:31:27 PDT 2008


Author: lattner
Date: Wed Jul 23 01:31:27 2008
New Revision: 53946

URL: http://llvm.org/viewvc/llvm-project?rev=53946&view=rev
Log:
Fix a codegen crash on:

int foo(void) {
  float x[2];
  return x;
}

rdar://6093986

Modified:
    cfe/trunk/lib/CodeGen/CGExprScalar.cpp
    cfe/trunk/test/CodeGen/pointer-to-int.c

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=53946&r1=53945&r2=53946&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Wed Jul 23 01:31:27 2008
@@ -533,12 +533,16 @@
     V = Builder.CreateStructGEP(V, 0, "arraydecay");
     
     // The resultant pointer type can be implicitly casted to other pointer
-    // types as well, for example void*.
-    const llvm::Type *DestPTy = ConvertType(E->getType());
-    assert(isa<llvm::PointerType>(DestPTy) &&
-           "Only expect implicit cast to pointer");
-    if (V->getType() != DestPTy)
-      V = Builder.CreateBitCast(V, DestPTy, "ptrconv");
+    // types as well (e.g. void*) and can be implicitly converted to integer.
+    const llvm::Type *DestTy = ConvertType(E->getType());
+    if (V->getType() != DestTy) {
+      if (isa<llvm::PointerType>(DestTy))
+        V = Builder.CreateBitCast(V, DestTy, "ptrconv");
+      else {
+        assert(isa<llvm::IntegerType>(DestTy) && "Unknown array decay");
+        V = Builder.CreatePtrToInt(V, DestTy, "ptrconv");
+      }
+    }
     return V;
     
   } else if (E->getType()->isReferenceType()) {

Modified: cfe/trunk/test/CodeGen/pointer-to-int.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/pointer-to-int.c?rev=53946&r1=53945&r2=53946&view=diff

==============================================================================
--- cfe/trunk/test/CodeGen/pointer-to-int.c (original)
+++ cfe/trunk/test/CodeGen/pointer-to-int.c Wed Jul 23 01:31:27 2008
@@ -1,6 +1,13 @@
-// RUN: clang -emit-llvm %s
+// RUN: clang -emit-llvm %s -o -
 
 int test(void* i)
 {
   return (int)i;
 }
+
+// rdar://6093986
+int test2(void) {
+  float x[2];
+  return x;
+}
+





More information about the cfe-commits mailing list