aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2011-11-02 22:53:43 +0000
committerFariborz Jahanian <fjahanian@apple.com>2011-11-02 22:53:43 +0000
commitc637d738897b1745af3bad7fc551f26b98da838c (patch)
treebe57c8ba60d86cd3b341f5c680b5010d9d726b9c
parent3c24cab4076feb6f3f6bc260080f71f802400306 (diff)
back out changes in r143399 and r143475.
rvale-references are captured by reference in blocks. // rdar://9971124. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143583 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/CGBlocks.cpp24
-rw-r--r--lib/CodeGen/CGExpr.cpp4
-rw-r--r--lib/Sema/SemaExpr.cpp3
-rw-r--r--test/CodeGenCXX/block-rvalue-reference-capture.cpp31
4 files changed, 10 insertions, 52 deletions
diff --git a/lib/CodeGen/CGBlocks.cpp b/lib/CodeGen/CGBlocks.cpp
index 19262ec54f..076e20c5fb 100644
--- a/lib/CodeGen/CGBlocks.cpp
+++ b/lib/CodeGen/CGBlocks.cpp
@@ -380,12 +380,9 @@ static void computeBlockInfo(CodeGenModule &CGM, CGBlockInfo &info) {
}
}
- bool IsRValReference = variable->getType()->isRValueReferenceType();
- QualType VT =
- IsRValReference ? variable->getType()->getPointeeType()
- : variable->getType();
+ QualType VT = variable->getType();
CharUnits size = C.getTypeSizeInChars(VT);
- CharUnits align = C.getDeclAlign(variable, IsRValReference);
+ CharUnits align = C.getDeclAlign(variable);
maxFieldAlign = std::max(maxFieldAlign, align);
@@ -599,32 +596,30 @@ llvm::Value *CodeGenFunction::EmitBlockLiteral(const BlockExpr *blockExpr) {
EmitSynthesizedCXXCopyCtor(blockField, src, copyExpr);
// If it's a reference variable, copy the reference into the block field.
- } else if (type->isReferenceType() && !type->isRValueReferenceType()) {
+ } else if (type->isReferenceType()) {
Builder.CreateStore(Builder.CreateLoad(src, "ref.val"), blockField);
// Otherwise, fake up a POD copy into the block field.
} else {
- QualType VT =
- (!type->isRValueReferenceType()) ? type : type->getPointeeType();
// Fake up a new variable so that EmitScalarInit doesn't think
// we're referring to the variable in its own initializer.
ImplicitParamDecl blockFieldPseudoVar(/*DC*/ 0, SourceLocation(),
- /*name*/ 0, VT);
+ /*name*/ 0, type);
// We use one of these or the other depending on whether the
// reference is nested.
- DeclRefExpr notNested(const_cast<VarDecl*>(variable), VT, VK_LValue,
+ DeclRefExpr notNested(const_cast<VarDecl*>(variable), type, VK_LValue,
SourceLocation());
- BlockDeclRefExpr nested(const_cast<VarDecl*>(variable), VT,
+ BlockDeclRefExpr nested(const_cast<VarDecl*>(variable), type,
VK_LValue, SourceLocation(), /*byref*/ false);
Expr *declRef =
(ci->isNested() ? static_cast<Expr*>(&nested) : &notNested);
- ImplicitCastExpr l2r(ImplicitCastExpr::OnStack, VT, CK_LValueToRValue,
+ ImplicitCastExpr l2r(ImplicitCastExpr::OnStack, type, CK_LValueToRValue,
declRef, VK_RValue);
EmitExprAsInit(&l2r, &blockFieldPseudoVar,
- MakeAddrLValue(blockField, VT,
+ MakeAddrLValue(blockField, type,
getContext().getDeclAlign(variable)
.getQuantity()),
/*captured by init*/ false);
@@ -796,8 +791,7 @@ llvm::Value *CodeGenFunction::GetAddrOfBlockDecl(const VarDecl *variable,
variable->getNameAsString());
}
- if (variable->getType()->isReferenceType() &&
- !variable->getType()->isRValueReferenceType())
+ if (variable->getType()->isReferenceType())
addr = Builder.CreateLoad(addr, "ref.tmp");
return addr;
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index 9680185b7f..9ad3ae8352 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -1409,10 +1409,8 @@ LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) {
}
LValue CodeGenFunction::EmitBlockDeclRefLValue(const BlockDeclRefExpr *E) {
- bool RefAsPointee =
- E->getDecl()->getType()->isRValueReferenceType() ? true : false;
unsigned Alignment =
- getContext().getDeclAlign(E->getDecl(), RefAsPointee).getQuantity();
+ getContext().getDeclAlign(E->getDecl()).getQuantity();
return MakeAddrLValue(GetAddrOfBlockDecl(E), E->getType(), Alignment);
}
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index d4d08703d3..febd394eb3 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -1305,9 +1305,6 @@ static CaptureResult shouldCaptureValueReference(Sema &S, SourceLocation loc,
// Actually try to capture it.
QualType type = var->getType();
- if (type->isRValueReferenceType())
- type = type->getPointeeType();
-
// Prohibit variably-modified types.
if (type->isVariablyModifiedType()) {
S.Diag(loc, diag::err_ref_vm_type);
diff --git a/test/CodeGenCXX/block-rvalue-reference-capture.cpp b/test/CodeGenCXX/block-rvalue-reference-capture.cpp
deleted file mode 100644
index 997e14f851..0000000000
--- a/test/CodeGenCXX/block-rvalue-reference-capture.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-// RUN: %clang_cc1 %s -std=c++11 -fblocks -triple x86_64-apple-darwin -emit-llvm -o - | FileCheck %s
-// rdar://9971124
-
-int foo(int && i)
-{
- return ^{ return i; }();
-}
-
-int main() {
- return foo(100);
-}
-
-// CHECK: [[B:%.*]] = bitcast i8* [[BD:%.*]] to <{ {{.*}} i32 }>*
-// CHECK: [[C:%.*]] = getelementptr inbounds <{ {{.*}} i32 }>* [[B]]
-// CHECK: [[R:%.*]] = load i32* [[C]], align 4
-// CHECK: ret i32 [[R]]
-
-class S {
-public:
- S (const S &);
- S(int);
- int field;
-};
-
-int func(S && rv)
-{
- return ^{ return rv.field; }();
-}
-
-// CHECK: define i32 @_Z4funcO1S
-// CHECK: call void @_ZN1SC1ERKS_