/// "sometimes unreachable" code. Such code is usually not interesting
/// to report as unreachable, and may mask truly unreachable code within
/// those blocks.
-static bool isConfigurationValue(const Stmt *S) {
+static bool isConfigurationValue(const Stmt *S,
+ bool IncludeIntegers = true) {
if (!S)
return false;
const DeclRefExpr *DR = cast<DeclRefExpr>(S);
const ValueDecl *D = DR->getDecl();
if (const EnumConstantDecl *ED = dyn_cast<EnumConstantDecl>(D))
- return ED ? isConfigurationValue(ED->getInitExpr()) : false;
+ return isConfigurationValue(ED->getInitExpr());
if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
// As a heuristic, treat globals as configuration values. Note
// that we only will get here if Sema evaluated this
return false;
}
case Stmt::IntegerLiteralClass:
- return isExpandedFromConfigurationMacro(S);
+ return IncludeIntegers ? isExpandedFromConfigurationMacro(S)
+ : false;
case Stmt::UnaryExprOrTypeTraitExprClass:
return true;
case Stmt::BinaryOperatorClass: {
const BinaryOperator *B = cast<BinaryOperator>(S);
- return (B->isLogicalOp() || B->isComparisonOp()) &&
- (isConfigurationValue(B->getLHS()) ||
- isConfigurationValue(B->getRHS()));
+ // Only include raw integers (not enums) as configuration
+ // values if they are used in a logical or comparison operator
+ // (not arithmetic).
+ IncludeIntegers &= (B->isLogicalOp() || B->isComparisonOp());
+ return isConfigurationValue(B->getLHS(), IncludeIntegers) ||
+ isConfigurationValue(B->getRHS(), IncludeIntegers);
}
case Stmt::UnaryOperatorClass: {
const UnaryOperator *UO = cast<UnaryOperator>(S);
void test_with_unreachable_tmp_dtors(int x) {
raze(x ? A() : A()); // no-warning
}
+
+// Test sizeof - sizeof in enum declaration.
+enum { BrownCow = sizeof(long) - sizeof(char) };
+enum { CowBrown = 8 - 1 };
+
+
+int test_enum_sizeof_arithmetic() {
+ if (BrownCow)
+ return 1;
+ return 2;
+}
+
+int test_enum_arithmetic() {
+ if (CowBrown)
+ return 1;
+ return 2; // expected-warning {{never be executed}}
+}
+
+int test_arithmetic() {
+ if (8 -1)
+ return 1;
+ return 2; // expected-warning {{never be executed}}
+}
+