summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/Expr.cpp
diff options
context:
space:
mode:
authorMichael Kuperstein <michael.m.kuperstein@intel.com>2015-04-06 13:22:01 +0000
committerMichael Kuperstein <michael.m.kuperstein@intel.com>2015-04-06 13:22:01 +0000
commitaed5ccdeed778342b9ff0a5e7d089067e4ffdef0 (patch)
treed7fdc2945b0579a6fb18d4d01dbcfdc5e407a002 /clang/lib/AST/Expr.cpp
parent1931b6263215f84f1096eb338ad56e564b21cb37 (diff)
downloadbcm5719-llvm-aed5ccdeed778342b9ff0a5e7d089067e4ffdef0.tar.gz
bcm5719-llvm-aed5ccdeed778342b9ff0a5e7d089067e4ffdef0.zip
HasSideEffects() should return false for calls to pure and const functions.
Differential Revision: http://reviews.llvm.org/D8548 llvm-svn: 234152
Diffstat (limited to 'clang/lib/AST/Expr.cpp')
-rw-r--r--clang/lib/AST/Expr.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index d13a11c4a33..d4ec2714d59 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -2942,11 +2942,19 @@ bool Expr::HasSideEffects(const ASTContext &Ctx,
case CXXOperatorCallExprClass:
case CXXMemberCallExprClass:
case CUDAKernelCallExprClass:
+ case UserDefinedLiteralClass: {
+ // We don't know a call definitely has side effects, except for calls
+ // to pure/const functions that definitely don't.
+ // If the call itself is considered side-effect free, check the operands.
+ const Decl *FD = cast<CallExpr>(this)->getCalleeDecl();
+ bool IsPure = FD && (FD->hasAttr<ConstAttr>() || FD->hasAttr<PureAttr>());
+ if (IsPure || !IncludePossibleEffects)
+ break;
+ return true;
+ }
+
case BlockExprClass:
case CXXBindTemporaryExprClass:
- case UserDefinedLiteralClass:
- // We don't know a call definitely has side effects, but we can check the
- // call's operands.
if (!IncludePossibleEffects)
break;
return true;
OpenPOWER on IntegriCloud