]> granicus.if.org Git - clang/commitdiff
Hand materialization of temporary expressions when emitting a scalar
authorDouglas Gregor <dgregor@apple.com>
Tue, 9 Aug 2011 00:37:14 +0000 (00:37 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 9 Aug 2011 00:37:14 +0000 (00:37 +0000)
expression. Fxies PR10592.

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

lib/CodeGen/CGExprScalar.cpp
test/CodeGenCXX/reference-cast.cpp

index 524d79e131da8e8a5b164c13d184f31be278287e..4038be279263cd78ddddce791e85ca4781b1bdf3 100644 (file)
@@ -343,6 +343,11 @@ public:
   }
     
   // C++
+  Value *VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E) {
+    RValue RV = CGF.EmitLoadOfLValue(CGF.EmitLValue(E->GetTemporaryExpr()));
+    return RV.getScalarVal();
+  }
+    
   Value *VisitCXXDefaultArgExpr(CXXDefaultArgExpr *DAE) {
     return Visit(DAE->getExpr());
   }
index 585d1dbd4084b18af6646d93ce1dff7733586dd6..549434e941478d4c43bf6e96a411312e3a7bba2c 100644 (file)
@@ -168,3 +168,16 @@ const _Complex float &f1() {
   // CHECK: store float
   return get_complex_double();
 }
+
+// CHECK: define i32 @_Z7pr10592RKi(i32*
+unsigned pr10592(const int &v) {
+  // CHECK: [[VADDR:%[a-zA-Z0-9.]+]] = alloca i32*
+  // CHECK-NEXT: [[REFTMP:%[a-zA-Z0-9.]+]] = alloca i32
+  // CHECK-NEXT: store i32* [[V:%[a-zA-Z0-9.]+]], i32** [[VADDR]]
+  // CHECK-NEXT: [[VADDR_1:%[a-zA-Z0-9.]+]] = load i32** [[VADDR]]
+  // CHECK-NEXT: [[VVAL:%[a-zA-Z0-9.]+]] = load i32* [[VADDR_1]]
+  // CHECK-NEXT: store i32 [[VVAL]], i32* [[REFTMP]]
+  // CHECK-NEXT: [[VVAL_I:%[a-zA-Z0-9.]+]] = load i32* [[REFTMP]]
+  // CHECK-NEXT: ret i32 [[VVAL_I]]
+  return static_cast<const unsigned &>(v);
+}