Too big shift: fix FP when cast is used

This commit is contained in:
Daniel Marjamäki 2014-09-12 06:45:45 +02:00
parent 0ab7abded1
commit 7119550dde
2 changed files with 13 additions and 13 deletions

View File

@ -44,19 +44,20 @@ public:
/** @brief Run checks against the normal token list */
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) {
(void)tokenizer;
(void)settings;
(void)errorLogger;
}
/** @brief Run checks against the simplified token list */
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) {
// These are not "simplified" because casts can't be ignored
CheckType checkType(tokenizer, settings, errorLogger);
checkType.checkTooBigBitwiseShift();
checkType.checkIntegerOverflow();
checkType.checkSignConversion();
}
/** @brief Run checks against the simplified token list */
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) {
(void)tokenizer;
(void)settings;
(void)errorLogger;
}
/** @brief %Check for bitwise shift with too big right operand */
void checkTooBigBitwiseShift();

View File

@ -59,12 +59,6 @@ private:
// Check..
CheckType checkType(&tokenizer, settings, this);
checkType.runChecks(&tokenizer, settings, this);
const std::string str1(tokenizer.tokens()->stringifyList(0,true));
tokenizer.simplifyTokenList2();
const std::string str2(tokenizer.tokens()->stringifyList(0,true));
if (str1 != str2)
warn(("Unsimplified code in test case\nstr1="+str1+"\nstr2="+str2).c_str());
checkType.runSimplifiedChecks(&tokenizer, settings, this);
}
void checkTooBigShift() {
@ -80,6 +74,11 @@ private:
" return x << 2;\n"
"}",&settings);
ASSERT_EQUALS("", errout.str());
check("int foo(int x) {\n"
" return (long long)x << 40;\n"
"}",&settings);
ASSERT_EQUALS("", errout.str());
}
void checkIntegerOverflow() {