summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/Expr.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2012-08-07 05:18:29 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2012-08-07 05:18:29 +0000
commita33e4fe603d8e9a06606aac8c790296b22375c87 (patch)
tree8c18f1adb2f76d52f79b76b5690bb540009164fd /clang/lib/AST/Expr.cpp
parentb8146afcd15577e2140ea74253d52078877f50f6 (diff)
downloadbcm5719-llvm-a33e4fe603d8e9a06606aac8c790296b22375c87.tar.gz
bcm5719-llvm-a33e4fe603d8e9a06606aac8c790296b22375c87.zip
Update documentation of HasSideEffects to match its callers' expectations, and
update implementation to match. An elidable, non-trivial constructor call is a side-effect under this definition, but wasn't under the old one, because we are not required to evaluate it even though it may have an effect. Also rationalize checking for volatile reads: just look for lvalue-to-rvalue conversions on volatile glvalues, and ignore whether a DeclRefExpr etc is for a volatile variable. llvm-svn: 161393
Diffstat (limited to 'clang/lib/AST/Expr.cpp')
-rw-r--r--clang/lib/AST/Expr.cpp38
1 files changed, 18 insertions, 20 deletions
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index faba404b9ac..9df850d6bd5 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -2643,6 +2643,8 @@ bool Expr::HasSideEffects(const ASTContext &Ctx) const {
case SubstNonTypeTemplateParmPackExprClass:
llvm_unreachable("shouldn't see dependent / unresolved nodes here");
+ case DeclRefExprClass:
+ case ObjCIvarRefExprClass:
case PredefinedExprClass:
case IntegerLiteralClass:
case FloatingLiteralClass:
@@ -2696,16 +2698,10 @@ bool Expr::HasSideEffects(const ASTContext &Ctx) const {
case MemberExprClass:
case ConditionalOperatorClass:
case BinaryConditionalOperatorClass:
- case ImplicitCastExprClass:
- case CStyleCastExprClass:
case CompoundLiteralExprClass:
case ExtVectorElementExprClass:
case DesignatedInitExprClass:
case ParenListExprClass:
- case CXXStaticCastExprClass:
- case CXXReinterpretCastExprClass:
- case CXXConstCastExprClass:
- case CXXFunctionalCastExprClass:
case CXXPseudoDestructorExprClass:
case SubstNonTypeTemplateParmExprClass:
case MaterializeTemporaryExprClass:
@@ -2714,24 +2710,16 @@ bool Expr::HasSideEffects(const ASTContext &Ctx) const {
// These have a side-effect if any subexpression does.
break;
- case UnaryOperatorClass: {
- const UnaryOperator *UO = cast<UnaryOperator>(this);
- if (UO->isIncrementDecrementOp())
- return true;
- if (UO->getOpcode() == UO_Deref && UO->getType().isVolatileQualified())
+ case UnaryOperatorClass:
+ if (cast<UnaryOperator>(this)->isIncrementDecrementOp())
return true;
break;
- }
case BinaryOperatorClass:
if (cast<BinaryOperator>(this)->isAssignmentOp())
return true;
break;
- case DeclRefExprClass:
- case ObjCIvarRefExprClass:
- return getType().isVolatileQualified();
-
case InitListExprClass:
// FIXME: The children for an InitListExpr doesn't include the array filler.
if (const Expr *E = cast<InitListExpr>(this)->getArrayFiller())
@@ -2755,7 +2743,17 @@ bool Expr::HasSideEffects(const ASTContext &Ctx) const {
if (DCE->getTypeAsWritten()->isReferenceType() &&
DCE->getCastKind() == CK_Dynamic)
return true;
- // Also has side-effects if the subexpression does.
+ } // Fall through.
+ case ImplicitCastExprClass:
+ case CStyleCastExprClass:
+ case CXXStaticCastExprClass:
+ case CXXReinterpretCastExprClass:
+ case CXXConstCastExprClass:
+ case CXXFunctionalCastExprClass: {
+ const CastExpr *CE = cast<CastExpr>(this);
+ if (CE->getCastKind() == CK_LValueToRValue &&
+ CE->getSubExpr()->getType().isVolatileQualified())
+ return true;
break;
}
@@ -2779,10 +2777,10 @@ bool Expr::HasSideEffects(const ASTContext &Ctx) const {
case CXXConstructExprClass:
case CXXTemporaryObjectExprClass: {
const CXXConstructExpr *CE = cast<CXXConstructExpr>(this);
- if (!CE->isElidable() && !CE->getConstructor()->isTrivial())
+ if (!CE->getConstructor()->isTrivial())
return true;
- // An elidable or trivial constructor does not add any side-effects of its
- // own. Just look at its arguments.
+ // A trivial constructor does not add any side-effects of its own. Just look
+ // at its arguments.
break;
}
OpenPOWER on IntegriCloud