Add test cases for ValueFlow issue with cast/switch (#3527)

This commit is contained in:
chrchr-github 2021-10-28 19:49:42 +02:00 committed by GitHub
parent 87d1ba4c08
commit 728531aba1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 30 additions and 0 deletions

View File

@ -2959,6 +2959,36 @@ private:
"}\n";
ASSERT_EQUALS(false, testValueOfX(code, 12U, 3));
code = "long long f(const long long& x, const long long& y) {\n"
" switch (s) {\n"
" case 0:\n"
" if (x >= 64)\n"
" return 0;\n"
" return (long long)y << (long long)x;\n"
" case 1:\n"
" if (x >= 64) {\n"
" }\n"
" }\n"
" return 0; \n"
"}\n";
ASSERT_EQUALS(true, testValueOfX(code, 6U, 63));
ASSERT_EQUALS(true, testValueOfXImpossible(code, 6U, 64));
code = "long long f(const long long& x, const long long& y) {\n"
" switch (s) {\n"
" case 0:\n"
" if (x >= 64)\n"
" return 0;\n"
" return long long(y) << long long(x);\n"
" case 1:\n"
" if (x >= 64) {\n"
" }\n"
" }\n"
" return 0; \n"
"}\n";
ASSERT_EQUALS(true, testValueOfX(code, 6U, 63));
TODO_ASSERT_EQUALS(true, false, testValueOfXImpossible(code, 6U, 64));
code = "int g(int x) { throw 0; }\n"
"void f(int x) {\n"
" if (x == 3)\n"