[cfe-commits] r41202 - in /cfe/trunk: CodeGen/CGExpr.cpp CodeGen/CodeGenFunction.h test/CodeGen/array.c
Chris Lattner
sabre at nondot.org
Mon Aug 20 15:37:11 PDT 2007
Author: lattner
Date: Mon Aug 20 17:37:10 2007
New Revision: 41202
URL: http://llvm.org/viewvc/llvm-project?rev=41202&view=rev
Log:
Fix array->pointer decay. This unbreaks test/CodeGen/array.c
Added:
cfe/trunk/test/CodeGen/array.c
Modified:
cfe/trunk/CodeGen/CGExpr.cpp
cfe/trunk/CodeGen/CodeGenFunction.h
Modified: cfe/trunk/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExpr.cpp?rev=41202&r1=41201&r2=41202&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/CodeGen/CGExpr.cpp Mon Aug 20 17:37:10 2007
@@ -586,7 +586,7 @@
E->getType(),
cast<SizeOfAlignOfTypeExpr>(E)->isSizeOf());
case Expr::ImplicitCastExprClass:
- return EmitCastExpr(cast<ImplicitCastExpr>(E)->getSubExpr(), E->getType());
+ return EmitImplicitCastExpr(cast<ImplicitCastExpr>(E));
case Expr::CastExprClass:
return EmitCastExpr(cast<CastExpr>(E)->getSubExpr(), E->getType());
case Expr::CallExprClass:
@@ -660,6 +660,31 @@
return EmitConversion(Src, Op->getType(), DestTy);
}
+/// EmitImplicitCastExpr - Implicit casts are the same as normal casts, but also
+/// handle things like function to pointer-to-function decay, and array to
+/// pointer decay.
+RValue CodeGenFunction::EmitImplicitCastExpr(const ImplicitCastExpr *E) {
+ const Expr *Op = E->getSubExpr();
+ QualType OpTy = Op->getType().getCanonicalType();
+
+ // If this is due to array->pointer conversion, emit the array expression as
+ // an l-value.
+ if (isa<ArrayType>(OpTy)) {
+ // FIXME: For now we assume that all source arrays map to LLVM arrays. This
+ // will not true when we add support for VLAs.
+ llvm::Value *V = EmitLValue(Op).getAddress(); // Bitfields can't be arrays.
+
+ assert(isa<llvm::PointerType>(V->getType()) &&
+ isa<llvm::ArrayType>(cast<llvm::PointerType>(V->getType())
+ ->getElementType()) &&
+ "Doesn't support VLAs yet!");
+ llvm::Constant *Idx0 = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0);
+ return RValue::get(Builder.CreateGEP(V, Idx0, Idx0, "arraydecay"));
+ }
+
+ return EmitCastExpr(Op, E->getType());
+}
+
RValue CodeGenFunction::EmitCallExpr(const CallExpr *E) {
if (const ImplicitCastExpr *IcExpr =
dyn_cast<const ImplicitCastExpr>(E->getCallee()))
Modified: cfe/trunk/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenFunction.h?rev=41202&r1=41201&r2=41202&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/CodeGen/CodeGenFunction.h Mon Aug 20 17:37:10 2007
@@ -50,6 +50,7 @@
class CharacterLiteral;
class TypesCompatibleExpr;
+ class ImplicitCastExpr;
class CastExpr;
class CallExpr;
class UnaryOperator;
@@ -350,6 +351,7 @@
RValue EmitCharacterLiteral(const CharacterLiteral *E);
RValue EmitTypesCompatibleExpr(const TypesCompatibleExpr *E);
+ RValue EmitImplicitCastExpr(const ImplicitCastExpr *Op);
RValue EmitCastExpr(const Expr *Op, QualType DestTy);
RValue EmitCallExpr(const CallExpr *E);
RValue EmitBuiltinExpr(unsigned builtinID, const CallExpr *E);
Added: cfe/trunk/test/CodeGen/array.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/array.c?rev=41202&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/array.c (added)
+++ cfe/trunk/test/CodeGen/array.c Mon Aug 20 17:37:10 2007
@@ -0,0 +1,6 @@
+// RUN: clang -emit-llvm %s
+
+int f() {
+ int a[2];
+ a[0] = 0;
+}
More information about the cfe-commits
mailing list