[cfe-commits] r157414 - in /cfe/trunk: lib/AST/Expr.cpp test/SemaCXX/unused.cpp
Eli Friedman
eli.friedman at gmail.com
Thu May 24 14:05:41 PDT 2012
Author: efriedma
Date: Thu May 24 16:05:41 2012
New Revision: 157414
URL: http://llvm.org/viewvc/llvm-project?rev=157414&view=rev
Log:
A minor tweak to the new volatile lvalue warning: don't warn on "(void)x", where "x" refers to a local variable. This should silence a useless warning in compiler-rt and other places.
Modified:
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/test/SemaCXX/unused.cpp
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=157414&r1=157413&r2=157414&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Thu May 24 16:05:41 2012
@@ -1883,43 +1883,40 @@
return true;
}
case CStyleCastExprClass: {
- // Ignore an explicit cast to void, as long as the operand isn't a
+ // Ignore an explicit cast to void unless the operand is a non-trivial
// volatile lvalue.
- const CStyleCastExpr *CE = cast<CStyleCastExpr>(this);
- if (CE->getCastKind() == CK_ToVoid) {
- if (CE->getSubExpr()->isGLValue() &&
- CE->getSubExpr()->getType().isVolatileQualified())
- return CE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc,
- R1, R2, Ctx);
- return false;
- }
- WarnE = this;
- Loc = CE->getLParenLoc();
- R1 = CE->getSubExpr()->getSourceRange();
- return true;
- }
- case CXXFunctionalCastExprClass: {
- // Ignore an explicit cast to void, as long as the operand isn't a
- // volatile lvalue.
- const CXXFunctionalCastExpr *CE = cast<CXXFunctionalCastExpr>(this);
+ const CastExpr *CE = cast<CastExpr>(this);
if (CE->getCastKind() == CK_ToVoid) {
if (CE->getSubExpr()->isGLValue() &&
- CE->getSubExpr()->getType().isVolatileQualified())
- return CE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc,
- R1, R2, Ctx);
+ CE->getSubExpr()->getType().isVolatileQualified()) {
+ const DeclRefExpr *DRE =
+ dyn_cast<DeclRefExpr>(CE->getSubExpr()->IgnoreParens());
+ if (!(DRE && isa<VarDecl>(DRE->getDecl()) &&
+ cast<VarDecl>(DRE->getDecl())->hasLocalStorage())) {
+ return CE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc,
+ R1, R2, Ctx);
+ }
+ }
return false;
}
-
+
// If this is a cast to a constructor conversion, check the operand.
// Otherwise, the result of the cast is unused.
if (CE->getCastKind() == CK_ConstructorConversion)
return CE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
+
WarnE = this;
- Loc = CE->getTypeBeginLoc();
- R1 = CE->getSubExpr()->getSourceRange();
+ if (const CXXFunctionalCastExpr *CXXCE =
+ dyn_cast<CXXFunctionalCastExpr>(this)) {
+ Loc = CXXCE->getTypeBeginLoc();
+ R1 = CXXCE->getSubExpr()->getSourceRange();
+ } else {
+ const CStyleCastExpr *CStyleCE = cast<CStyleCastExpr>(this);
+ Loc = CStyleCE->getLParenLoc();
+ R1 = CStyleCE->getSubExpr()->getSourceRange();
+ }
return true;
}
-
case ImplicitCastExprClass: {
const CastExpr *ICE = cast<ImplicitCastExpr>(this);
Modified: cfe/trunk/test/SemaCXX/unused.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/unused.cpp?rev=157414&r1=157413&r2=157414&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/unused.cpp (original)
+++ cfe/trunk/test/SemaCXX/unused.cpp Thu May 24 16:05:41 2012
@@ -30,5 +30,7 @@
void f(volatile char* x) {
*x; // expected-warning {{expression result unused; assign into a variable to force a volatile load}}
(void)*x; // expected-warning {{expression result unused; assign into a variable to force a volatile load}}
+ volatile char y = 10;
+ (void)y; // don't warn here, because it's a common pattern.
}
}
More information about the cfe-commits
mailing list