]> granicus.if.org Git - clang/commitdiff
add support for implicit cast from array to pointer that is not the element
authorChris Lattner <sabre@nondot.org>
Mon, 10 Dec 2007 19:50:32 +0000 (19:50 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 10 Dec 2007 19:50:32 +0000 (19:50 +0000)
type.

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

CodeGen/CodeGenModule.cpp
test/CodeGen/globalinit.c

index 2ce7f4e8371807a6772fa889b65b8dc49dec5a65..a5f7df18d41a985f583c2097ae8ab55c61e17890 100644 (file)
@@ -404,7 +404,14 @@ static llvm::Constant *GenerateConstantExpr(const Expr *Expression,
       llvm::Constant *Idx0 = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0);
       
       llvm::Constant *Ops[] = {Idx0, Idx0};
-      return llvm::ConstantExpr::getGetElementPtr(C, Ops, 2);
+      C = llvm::ConstantExpr::getGetElementPtr(C, Ops, 2);
+      
+      // The resultant pointer type can be implicitly casted to other pointer
+      // types as well, for example void*.
+      const llvm::Type *DestPTy = Types.ConvertType(type);
+      assert(isa<llvm::PointerType>(DestPTy) &&
+             "Only expect implicit cast to pointer");
+      return llvm::ConstantExpr::getBitCast(C, DestPTy);
     }
     
     // If this is an implicit cast of a string literal to an array type, this
index 55298bc07eef94027c2ef429e181e0e2e5046d6a..f47fd5c457754d9ab20aacf9bf7641c4fd7ba5ab 100644 (file)
@@ -10,7 +10,7 @@ void bar() { x[0] = 1; }
 
 
 extern int y[];
-//void *g = y;
+void *g = y;
 
 int latin_ptr2len (char *p);
 int (*mb_ptr2len) (char *p) = latin_ptr2len;