summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaPseudoObject.cpp
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2015-08-22 00:35:27 +0000
committerJohn McCall <rjmccall@apple.com>2015-08-22 00:35:27 +0000
commitee04aebbdbeadf2722a506336f0b14f481c6faf9 (patch)
tree72b1ce96730829010c71fdddfd28456b6e2a8b7a /clang/lib/Sema/SemaPseudoObject.cpp
parent8e38c71cb79e022b1b40e30ba647e89dad97b106 (diff)
downloadbcm5719-llvm-ee04aebbdbeadf2722a506336f0b14f481c6faf9.tar.gz
bcm5719-llvm-ee04aebbdbeadf2722a506336f0b14f481c6faf9.zip
When building a pseudo-object assignment, and the RHS is
a contextually-typed expression that semantic analysis will probably need to invasively rewrite, don't include the RHS OVE as a separate semantic expression, and check the operation with the original RHS expression. There are two contextually-typed expressions that can survive to here: overloaded function references, which are at least safe to double-emit, and C++11 initializer list expressions, which are not at all safe to double-emit and which often don't update the original syntactic InitListExpr with implicit conversions to member types, etc. This means that the original RHS may appear, undecorated by an OVE, in the semantic expressions. Fortunately, it will only ever be used in a single place there, and I don't believe there are clients that rely on being able to pick out the original RHS from the semantic expressions. But this could be problematic if there are clients that do visit the entire tree and rely on not seeing the same expression multiple times, once in the syntactic and once in the semantic expressions. This is a very fiddly part of the compiler. rdar://21801088 llvm-svn: 245771
Diffstat (limited to 'clang/lib/Sema/SemaPseudoObject.cpp')
-rw-r--r--clang/lib/Sema/SemaPseudoObject.cpp31
1 files changed, 14 insertions, 17 deletions
diff --git a/clang/lib/Sema/SemaPseudoObject.cpp b/clang/lib/Sema/SemaPseudoObject.cpp
index fec97488f53..a7029fa07c6 100644
--- a/clang/lib/Sema/SemaPseudoObject.cpp
+++ b/clang/lib/Sema/SemaPseudoObject.cpp
@@ -406,19 +406,27 @@ PseudoOpBuilder::buildAssignmentOperation(Scope *Sc, SourceLocation opcLoc,
BinaryOperatorKind opcode,
Expr *LHS, Expr *RHS) {
assert(BinaryOperator::isAssignmentOp(opcode));
-
- // Recover from user error
- if (isa<UnresolvedLookupExpr>(RHS))
- return ExprError();
Expr *syntacticLHS = rebuildAndCaptureObject(LHS);
OpaqueValueExpr *capturedRHS = capture(RHS);
+ // In some very specific cases, semantic analysis of the RHS as an
+ // expression may require it to be rewritten. In these cases, we
+ // cannot safely keep the OVE around. Fortunately, we don't really
+ // need to: we don't use this particular OVE in multiple places, and
+ // no clients rely that closely on matching up expressions in the
+ // semantic expression with expressions from the syntactic form.
+ Expr *semanticRHS = capturedRHS;
+ if (RHS->hasPlaceholderType() || isa<InitListExpr>(RHS)) {
+ semanticRHS = RHS;
+ Semantics.pop_back();
+ }
+
Expr *syntactic;
ExprResult result;
if (opcode == BO_Assign) {
- result = capturedRHS;
+ result = semanticRHS;
syntactic = new (S.Context) BinaryOperator(syntacticLHS, capturedRHS,
opcode, capturedRHS->getType(),
capturedRHS->getValueKind(),
@@ -430,8 +438,7 @@ PseudoOpBuilder::buildAssignmentOperation(Scope *Sc, SourceLocation opcLoc,
// Build an ordinary, non-compound operation.
BinaryOperatorKind nonCompound =
BinaryOperator::getOpForCompoundAssignment(opcode);
- result = S.BuildBinOp(Sc, opcLoc, nonCompound,
- opLHS.get(), capturedRHS);
+ result = S.BuildBinOp(Sc, opcLoc, nonCompound, opLHS.get(), semanticRHS);
if (result.isInvalid()) return ExprError();
syntactic =
@@ -745,16 +752,6 @@ ExprResult ObjCPropertyOpBuilder::buildSet(Expr *op, SourceLocation opcLoc,
op = opResult.get();
assert(op && "successful assignment left argument invalid?");
}
- else if (OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(op)) {
- Expr *Initializer = OVE->getSourceExpr();
- // passing C++11 style initialized temporaries to objc++ properties
- // requires special treatment by removing OpaqueValueExpr so type
- // conversion takes place and adding the OpaqueValueExpr later on.
- if (isa<InitListExpr>(Initializer) &&
- Initializer->getType()->isVoidType()) {
- op = Initializer;
- }
- }
}
// Arguments.
OpenPOWER on IntegriCloud