diff options
| author | Eli Friedman <eli.friedman@gmail.com> | 2013-07-20 00:40:58 +0000 |
|---|---|---|
| committer | Eli Friedman <eli.friedman@gmail.com> | 2013-07-20 00:40:58 +0000 |
| commit | 75807f239e06e94cb177eed61955790e6dc6e306 (patch) | |
| tree | 1a5218c565964125bfd63cdbdfcbc53f93677110 /clang/lib/Sema | |
| parent | 19b4986b80c92dfdf55af1320c888dbc3bde8d5a (diff) | |
| download | bcm5719-llvm-75807f239e06e94cb177eed61955790e6dc6e306.tar.gz bcm5719-llvm-75807f239e06e94cb177eed61955790e6dc6e306.zip | |
Make IgnoreParens() look through ChooseExprs.
This is the same way GenericSelectionExpr works, and it's generally a
more consistent approach.
A large part of this patch is devoted to caching the value of the condition
of a ChooseExpr; it's needed to avoid threading an ASTContext into
IgnoreParens().
Fixes <rdar://problem/14438917>.
llvm-svn: 186738
Diffstat (limited to 'clang/lib/Sema')
| -rw-r--r-- | clang/lib/Sema/SemaExceptionSpec.cpp | 2 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 6 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaPseudoObject.cpp | 19 |
3 files changed, 24 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaExceptionSpec.cpp b/clang/lib/Sema/SemaExceptionSpec.cpp index 0385c7783e3..0d662c8f393 100644 --- a/clang/lib/Sema/SemaExceptionSpec.cpp +++ b/clang/lib/Sema/SemaExceptionSpec.cpp @@ -1025,7 +1025,7 @@ CanThrowResult Sema::canThrow(const Expr *E) { case Expr::ChooseExprClass: if (E->isTypeDependent() || E->isValueDependent()) return CT_Dependent; - return canThrow(cast<ChooseExpr>(E)->getChosenSubExpr(Context)); + return canThrow(cast<ChooseExpr>(E)->getChosenSubExpr()); case Expr::GenericSelectionExprClass: if (cast<GenericSelectionExpr>(E)->isResultDependent()) diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index f397c5bb2ef..2c933147f44 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -9868,6 +9868,7 @@ ExprResult Sema::ActOnChooseExpr(SourceLocation BuiltinLoc, ExprObjectKind OK = OK_Ordinary; QualType resType; bool ValueDependent = false; + bool CondIsTrue = false; if (CondExpr->isTypeDependent() || CondExpr->isValueDependent()) { resType = Context.DependentTy; ValueDependent = true; @@ -9880,9 +9881,10 @@ ExprResult Sema::ActOnChooseExpr(SourceLocation BuiltinLoc, if (CondICE.isInvalid()) return ExprError(); CondExpr = CondICE.take(); + CondIsTrue = condEval.getZExtValue(); // If the condition is > zero, then the AST type is the same as the LSHExpr. - Expr *ActiveExpr = condEval.getZExtValue() ? LHSExpr : RHSExpr; + Expr *ActiveExpr = CondIsTrue ? LHSExpr : RHSExpr; resType = ActiveExpr->getType(); ValueDependent = ActiveExpr->isValueDependent(); @@ -9891,7 +9893,7 @@ ExprResult Sema::ActOnChooseExpr(SourceLocation BuiltinLoc, } return Owned(new (Context) ChooseExpr(BuiltinLoc, CondExpr, LHSExpr, RHSExpr, - resType, VK, OK, RPLoc, + resType, VK, OK, RPLoc, CondIsTrue, resType->isDependentType(), ValueDependent)); } diff --git a/clang/lib/Sema/SemaPseudoObject.cpp b/clang/lib/Sema/SemaPseudoObject.cpp index a10612a8b07..106250fe0f5 100644 --- a/clang/lib/Sema/SemaPseudoObject.cpp +++ b/clang/lib/Sema/SemaPseudoObject.cpp @@ -101,6 +101,25 @@ namespace { resultIndex); } + if (ChooseExpr *ce = dyn_cast<ChooseExpr>(e)) { + assert(!ce->isConditionDependent()); + + Expr *LHS = ce->getLHS(), *RHS = ce->getRHS(); + Expr *&rebuiltExpr = ce->isConditionTrue() ? LHS : RHS; + rebuiltExpr = rebuild(rebuiltExpr); + + return new (S.Context) ChooseExpr(ce->getBuiltinLoc(), + ce->getCond(), + LHS, RHS, + rebuiltExpr->getType(), + rebuiltExpr->getValueKind(), + rebuiltExpr->getObjectKind(), + ce->getRParenLoc(), + ce->isConditionTrue(), + rebuiltExpr->isTypeDependent(), + rebuiltExpr->isValueDependent()); + } + llvm_unreachable("bad expression to rebuild!"); } }; |

