Author: aaronballman
Date: Sat Jan 3 11:00:12 2015
New Revision: 225116
URL: http://llvm.org/viewvc/llvm-project?rev=225116&view=rev
Log:
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);
Modified:
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/test/SemaCXX/warn-unused-value.cpp
Modified: cfe/trunk/lib/AST/Expr.cpp
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=225116&r1=225115&r2=225116&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Sat Jan 3 11:00:12 2015
@@ -3021,6 +3021,13 @@ bool Expr::HasSideEffects(const ASTConte
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())
Modified: cfe/trunk/test/SemaCXX/warn-unused-value.cpp
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-unused-value.cpp?rev=225116&r1=225115&r2=225116&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-unused-value.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-unused-value.cpp Sat Jan 3 11:00:12 2015
@@ -90,9 +90,10 @@ void f() {
Bad b;
(void)typeid(b.f()); // expected-warning {{expression with side effects will
be evaluated despite being used as an operand to 'typeid'}}
- // A dereference of a volatile pointer is a side effecting operation, despite
- // it being a reasonable operation.
+ // A dereference of a volatile pointer is a side effecting operation, however
+ // since it is idiomatic code, and the alternatives induce higher maintenance
+ // costs, it is allowed.
int * volatile x;
- (void)sizeof(*x); // expected-warning {{expression with side effects has no
effect in an unevaluated context}}
+ (void)sizeof(*x); // Ok
}
}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits