]> granicus.if.org Git - clang/commitdiff
Fix a codegen crash on:
authorChris Lattner <sabre@nondot.org>
Wed, 23 Jul 2008 06:31:27 +0000 (06:31 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 23 Jul 2008 06:31:27 +0000 (06:31 +0000)
int foo(void) {
  float x[2];
  return x;
}

rdar://6093986

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

lib/CodeGen/CGExprScalar.cpp
test/CodeGen/pointer-to-int.c

index f3ac6a61f46869403fbb8e3a6297a55408f84fdd..5a75e536692082460cd5d38badfbf036b8542f0a 100644 (file)
@@ -533,12 +533,16 @@ Value *ScalarExprEmitter::VisitImplicitCastExpr(const ImplicitCastExpr *E) {
     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()) {
index 7599e0d4abea4135befc22687dd0ede0e6299987..a3eaf91bc161c7769c72294f124f91483516fa02 100644 (file)
@@ -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;
+}
+