-Wunreachable-code: treat 'const bool' locals as control values.

llvm-svn: 204001
This commit is contained in:
Ted Kremenek 2014-03-15 06:47:45 +00:00
parent ad8753c00e
commit 9dfe400dc2
2 changed files with 25 additions and 1 deletions

View File

@ -236,7 +236,12 @@ static bool isConfigurationValue(const Stmt *S,
// We could generalize this to local variables, but it isn't
// clear if those truly represent configuration values that
// gate unreachable code.
return !VD->hasLocalStorage();
if (!VD->hasLocalStorage())
return true;
// As a heuristic, locals that have been marked 'const' explicitly
// can be treated as configuration values as well.
return VD->getType().isLocalConstQualified();
}
return false;
}

View File

@ -199,3 +199,22 @@ int test_arithmetic() {
return 2; // expected-warning {{never be executed}}
}
int test_treat_const_bool_local_as_config_value() {
const bool controlValue = false;
if (!controlValue)
return 1;
test_treat_const_bool_local_as_config_value(); // no-warning
return 0;
}
int test_treat_non_const_bool_local_as_non_config_value() {
bool controlValue = false;
if (!controlValue)
return 1;
// There is no warning here because 'controlValue' isn't really
// a control value at all. The CFG will not treat this
// branch as unreachable.
test_treat_non_const_bool_local_as_non_config_value(); // no-warning
return 0;
}