summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/Expr.cpp
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2015-01-03 17:00:12 +0000
committerAaron Ballman <aaron@aaronballman.com>2015-01-03 17:00:12 +0000
commit409af508589990413231e9ac567db1289de1b18c (patch)
tree6920721e1eaa3ddf3dac9762ad923d0989461406 /clang/lib/AST/Expr.cpp
parentd73bfba7ebc915214c93e93652eac8685c005262 (diff)
downloadbcm5719-llvm-409af508589990413231e9ac567db1289de1b18c.tar.gz
bcm5719-llvm-409af508589990413231e9ac567db1289de1b18c.zip
Volatile reads are side-effecting operations, but in the general case of access through a volatile-qualified type, we're not certain of the underlying object's side-effects on access.
Treat volatile accesses as "maybe" instead of "definite" side effects for the purposes of warning on evaluations in an unevaluated context. No longer diagnose on idiomatic code like: int * volatile v; (void)sizeof(*v); llvm-svn: 225116
Diffstat (limited to 'clang/lib/AST/Expr.cpp')
-rw-r--r--clang/lib/AST/Expr.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 818b60ca50b..21e668f68ff 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -3021,6 +3021,13 @@ bool Expr::HasSideEffects(const ASTContext &Ctx,
case CXXReinterpretCastExprClass:
case CXXConstCastExprClass:
case CXXFunctionalCastExprClass: {
+ // While volatile reads are side-effecting in both C and C++, we treat them
+ // as having possible (not definite) side-effects. This allows idiomatic
+ // code to behave without warning, such as sizeof(*v) for a volatile-
+ // qualified pointer.
+ if (!IncludePossibleEffects)
+ break;
+
const CastExpr *CE = cast<CastExpr>(this);
if (CE->getCastKind() == CK_LValueToRValue &&
CE->getSubExpr()->getType().isVolatileQualified())
OpenPOWER on IntegriCloud