From a64378048341b174d40552b7b0b3e79daf72cdad Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Fri, 5 Feb 2010 21:10:36 +0000 Subject: [PATCH] Revert r95393, which broke Clang's self-host. llvm-svn: 95430 --- clang/lib/CodeGen/CGDecl.cpp | 24 +++++++++++++++--------- clang/lib/CodeGen/CGExpr.cpp | 5 +++-- clang/lib/CodeGen/CGStmt.cpp | 5 +++-- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index d18b87fb9ac6..e27c5e4e51ae 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -690,19 +690,25 @@ void CodeGenFunction::EmitParmDecl(const VarDecl &D, llvm::Value *Arg) { CanQualType CTy = getContext().getCanonicalType(Ty); llvm::Value *DeclPtr; - // If this is an aggregate or variable sized value, reuse the input pointer. - if (!Ty->isConstantSizeType() || - CodeGenFunction::hasAggregateLLVMType(Ty)) { + if (!Ty->isConstantSizeType()) { + // Variable sized values always are passed by-reference. DeclPtr = Arg; } else { - // Otherwise, create a temporary to hold the value. - DeclPtr = CreateTempAlloca(ConvertTypeForMem(Ty)); - DeclPtr->setName(D.getName() + ".addr"); + // A fixed sized single-value variable becomes an alloca in the entry block. + const llvm::Type *LTy = ConvertTypeForMem(Ty); + if (LTy->isSingleValueType()) { + // TODO: Alignment + DeclPtr = CreateTempAlloca(LTy); + DeclPtr->setName(D.getNameAsString() + llvm::StringRef(".addr")); - // Store the initial value into the alloca. - EmitStoreOfScalar(Arg, DeclPtr, CTy.isVolatileQualified(), Ty); + // Store the initial value into the alloca. + EmitStoreOfScalar(Arg, DeclPtr, CTy.isVolatileQualified(), Ty); + } else { + // Otherwise, if this is an aggregate, just use the input pointer. + DeclPtr = Arg; + } + Arg->setName(D.getNameAsString()); } - Arg->setName(D.getName()); llvm::Value *&DMEntry = LocalDeclMap[&D]; assert(DMEntry == 0 && "Decl already exists in localdeclmap!"); diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 2684eb6e3ce1..7fb79e958552 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -549,13 +549,14 @@ RValue CodeGenFunction::EmitLoadOfLValue(LValue LV, QualType ExprType) { if (LV.isSimple()) { llvm::Value *Ptr = LV.getAddress(); + const llvm::Type *EltTy = + cast(Ptr->getType())->getElementType(); // Simple scalar l-value. - if (!CodeGenFunction::hasAggregateLLVMType(ExprType)) + if (EltTy->isSingleValueType()) return RValue::get(EmitLoadOfScalar(Ptr, LV.isVolatileQualified(), ExprType)); - // FIXME: This case shouldn't be necessary? assert(ExprType->isFunctionType() && "Unknown scalar value"); return RValue::get(Ptr); } diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp index 008a480b9c12..7ea8b08c238e 100644 --- a/clang/lib/CodeGen/CGStmt.cpp +++ b/clang/lib/CodeGen/CGStmt.cpp @@ -861,13 +861,14 @@ llvm::Value* CodeGenFunction::EmitAsmInput(const AsmStmt &S, std::string &ConstraintStr) { llvm::Value *Arg; if (Info.allowsRegister() || !Info.allowsMemory()) { - if (!CodeGenFunction::hasAggregateLLVMType(InputExpr->getType())) { + const llvm::Type *Ty = ConvertType(InputExpr->getType()); + + if (Ty->isSingleValueType()) { Arg = EmitScalarExpr(InputExpr); } else { InputExpr = InputExpr->IgnoreParenNoopCasts(getContext()); LValue Dest = EmitLValue(InputExpr); - const llvm::Type *Ty = ConvertType(InputExpr->getType()); uint64_t Size = CGM.getTargetData().getTypeSizeInBits(Ty); if (Size <= 64 && llvm::isPowerOf2_64(Size)) { Ty = llvm::IntegerType::get(VMContext, Size);