diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2009-01-20 17:46:04 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2009-01-20 17:46:04 +0000 |
commit | 4fd0aa5803357d8c72eeac2cae15e12649ea08fe (patch) | |
tree | 8c1af2d6cf9dabb266227b5f5bb02cb7999c70b3 | |
parent | c96c0511501190b631664ca556c0bf85537095d3 (diff) |
Slight cleanup, and fix for va_arg on architectures where va_list is a
struct.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62585 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/CGBuiltin.cpp | 17 | ||||
-rw-r--r-- | lib/CodeGen/CGExprScalar.cpp | 2 | ||||
-rw-r--r-- | lib/CodeGen/CodeGenFunction.cpp | 7 | ||||
-rw-r--r-- | lib/CodeGen/CodeGenFunction.h | 5 |
4 files changed, 16 insertions, 15 deletions
diff --git a/lib/CodeGen/CGBuiltin.cpp b/lib/CodeGen/CGBuiltin.cpp index 043f284398..30f8c34c58 100644 --- a/lib/CodeGen/CGBuiltin.cpp +++ b/lib/CodeGen/CGBuiltin.cpp @@ -53,12 +53,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E) { case Builtin::BI__builtin_stdarg_start: case Builtin::BI__builtin_va_start: case Builtin::BI__builtin_va_end: { - Value *ArgValue; - if (CGM.getContext().getBuiltinVaListType()->isArrayType()) { - ArgValue = EmitScalarExpr(E->getArg(0)); - } else { - ArgValue = EmitLValue(E->getArg(0)).getAddress(); - } + Value *ArgValue = EmitVAListRef(E->getArg(0));; const llvm::Type *DestType = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); if (ArgValue->getType() != DestType) @@ -70,14 +65,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E) { return RValue::get(Builder.CreateCall(CGM.getIntrinsic(inst), ArgValue)); } case Builtin::BI__builtin_va_copy: { - Value *DstPtr, *SrcPtr; - if (CGM.getContext().getBuiltinVaListType()->isArrayType()) { - DstPtr = EmitScalarExpr(E->getArg(0)); - SrcPtr = EmitScalarExpr(E->getArg(1)); - } else { - DstPtr = EmitLValue(E->getArg(0)).getAddress(); - SrcPtr = EmitLValue(E->getArg(1)).getAddress(); - } + Value *DstPtr = EmitVAListRef(E->getArg(0)); + Value *SrcPtr = EmitVAListRef(E->getArg(1)); const llvm::Type *Type = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index e6eb9c0b65..f21373a538 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -1286,7 +1286,7 @@ Value *ScalarExprEmitter::VisitOverloadExpr(OverloadExpr *E) { } Value *ScalarExprEmitter::VisitVAArgExpr(VAArgExpr *VE) { - llvm::Value *ArgValue = EmitLValue(VE->getSubExpr()).getAddress(); + llvm::Value *ArgValue = CGF.EmitVAListRef(VE->getSubExpr()); llvm::Value *ArgPtr = CGF.EmitVAArg(ArgValue, VE->getType()); diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp index c1a34389b8..2fd8d638d6 100644 --- a/lib/CodeGen/CodeGenFunction.cpp +++ b/lib/CodeGen/CodeGenFunction.cpp @@ -460,3 +460,10 @@ llvm::Value *CodeGenFunction::EmitVLASize(QualType Ty) return 0; } + +llvm::Value* CodeGenFunction::EmitVAListRef(const Expr* E) { + if (CGM.getContext().getBuiltinVaListType()->isArrayType()) { + return EmitScalarExpr(E); + } + return EmitLValue(E).getAddress(); +} diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h index 3d0c2a2fdb..f469b970dc 100644 --- a/lib/CodeGen/CodeGenFunction.h +++ b/lib/CodeGen/CodeGenFunction.h @@ -314,6 +314,11 @@ public: RValue EmitAnyExpr(const Expr *E, llvm::Value *AggLoc = 0, bool isAggLocVolatile = false); + // EmitVAListRef - Emit a "reference" to a va_list; this is either the + // address or the value of the expression, depending on how va_list is + // defined. + llvm::Value *EmitVAListRef(const Expr *E); + /// EmitAnyExprToTemp - Similary to EmitAnyExpr(), however, the result /// will always be accessible even if no aggregate location is /// provided. |