[cfe-commits] r44809 - in /cfe/trunk: CodeGen/CodeGenModule.cpp test/CodeGen/globalinit.c
Chris Lattner
sabre at nondot.org
Mon Dec 10 11:50:32 PST 2007
Author: lattner
Date: Mon Dec 10 13:50:32 2007
New Revision: 44809
URL: http://llvm.org/viewvc/llvm-project?rev=44809&view=rev
Log:
add support for implicit cast from array to pointer that is not the element
type.
Modified:
cfe/trunk/CodeGen/CodeGenModule.cpp
cfe/trunk/test/CodeGen/globalinit.c
Modified: cfe/trunk/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenModule.cpp?rev=44809&r1=44808&r2=44809&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/CodeGen/CodeGenModule.cpp Mon Dec 10 13:50:32 2007
@@ -404,7 +404,14 @@
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
Modified: cfe/trunk/test/CodeGen/globalinit.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/globalinit.c?rev=44809&r1=44808&r2=44809&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/globalinit.c (original)
+++ cfe/trunk/test/CodeGen/globalinit.c Mon Dec 10 13:50:32 2007
@@ -10,7 +10,7 @@
extern int y[];
-//void *g = y;
+void *g = y;
int latin_ptr2len (char *p);
int (*mb_ptr2len) (char *p) = latin_ptr2len;
More information about the cfe-commits
mailing list