]> granicus.if.org Git - clang/commitdiff
Fix a bug handling function -> pointer decay and avoid emitting a noop
authorChris Lattner <sabre@nondot.org>
Fri, 10 Aug 2007 16:33:59 +0000 (16:33 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 10 Aug 2007 16:33:59 +0000 (16:33 +0000)
bitcast.

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

CodeGen/CGExpr.cpp

index 1b0cbca94a8d69b7ca160cc411969301502ba15b..65d03c2d1ea89b01ee7ac8569016edd1942c7a1b 100644 (file)
@@ -91,6 +91,9 @@ RValue CodeGenFunction::EmitConversion(RValue Val, QualType ValTy,
   if (isa<PointerType>(DstTy)) {
     const llvm::Type *DestTy = ConvertType(DstTy);
     
+    if (Val.getVal()->getType() == DestTy)
+      return Val;
+    
     // The source value may be an integer, or a pointer.
     assert(Val.isScalar() && "Can only convert from integer or pointer");
     if (isa<llvm::PointerType>(Val.getVal()->getType()))
@@ -260,8 +263,6 @@ LValue CodeGenFunction::EmitLValue(const Expr *E) {
 /// this method emits the address of the lvalue, then loads the result as an
 /// rvalue, returning the rvalue.
 RValue CodeGenFunction::EmitLoadOfLValue(LValue LV, QualType ExprType) {
-  ExprType = ExprType.getCanonicalType();
-  
   if (LV.isSimple()) {
     llvm::Value *Ptr = LV.getAddress();
     const llvm::Type *EltTy =
@@ -271,6 +272,9 @@ RValue CodeGenFunction::EmitLoadOfLValue(LValue LV, QualType ExprType) {
     if (EltTy->isFirstClassType())
       return RValue::get(Builder.CreateLoad(Ptr, "tmp"));
     
+    if (ExprType->isFunctionType())
+      return RValue::get(Ptr);
+    
     // Otherwise, we have an aggregate lvalue.
     return RValue::getAggregate(Ptr);
   }