Removed hard coded avr8 platform and moved it into a platform file (avr8.xml).
This commit is contained in:
parent
9e10c2fc78
commit
61e47208eb
|
@ -703,8 +703,6 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
|||
_settings->platform(Settings::Unix32);
|
||||
else if (platform == "unix64")
|
||||
_settings->platform(Settings::Unix64);
|
||||
else if (platform == "avr8")
|
||||
_settings->platform(Settings::AVR8);
|
||||
else if (platform == "native")
|
||||
_settings->platform(Settings::Native);
|
||||
else if (platform == "unspecified")
|
||||
|
|
|
@ -146,28 +146,7 @@ bool cppcheck::Platform::platform(cppcheck::Platform::PlatformType type)
|
|||
long_bit = char_bit * sizeof_long;
|
||||
long_long_bit = char_bit * sizeof_long_long;
|
||||
return true;
|
||||
case AVR8:
|
||||
platformType = type;
|
||||
sizeof_bool = 1;
|
||||
sizeof_short = 2;
|
||||
sizeof_int = 2;
|
||||
sizeof_long = 4;
|
||||
sizeof_long_long = 8;
|
||||
sizeof_float = 4;
|
||||
sizeof_double = 4;
|
||||
sizeof_long_double = 4;
|
||||
sizeof_wchar_t = 2;
|
||||
sizeof_size_t = 2;
|
||||
sizeof_pointer = 2;
|
||||
defaultSign = '\0';
|
||||
char_bit = 8;
|
||||
short_bit = char_bit * sizeof_short;
|
||||
int_bit = char_bit * sizeof_int;
|
||||
long_bit = char_bit * sizeof_long;
|
||||
long_long_bit = char_bit * sizeof_long_long;
|
||||
return true;
|
||||
}
|
||||
|
||||
// unsupported platform
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -87,7 +87,6 @@ namespace cppcheck {
|
|||
Win64,
|
||||
Unix32,
|
||||
Unix64,
|
||||
AVR8,
|
||||
PlatformFile
|
||||
};
|
||||
|
||||
|
@ -126,8 +125,6 @@ namespace cppcheck {
|
|||
return "unix32";
|
||||
case Unix64:
|
||||
return "unix64";
|
||||
case AVR8:
|
||||
return "avr8";
|
||||
case PlatformFile:
|
||||
return "platformFile";
|
||||
default:
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0"?>
|
||||
<platform>
|
||||
<char_bit>8</char_bit>
|
||||
<default-sign>unsigned</default-sign>
|
||||
<sizeof>
|
||||
<bool>1</bool>
|
||||
<short>2</short>
|
||||
<int>2</int>
|
||||
<long>4</long>
|
||||
<long-long>8</long-long>
|
||||
<float>4</float>
|
||||
<double>4</double>
|
||||
<long-double>4</long-double>
|
||||
<pointer>2</pointer>
|
||||
<size_t>2</size_t>
|
||||
<wchar_t>2</wchar_t>
|
||||
</sizeof>
|
||||
</platform>
|
|
@ -34,7 +34,6 @@ private:
|
|||
|
||||
void run() {
|
||||
TEST_CASE(checkTooBigShift_Unix32);
|
||||
TEST_CASE(checkTooBigShift_AVR8);
|
||||
TEST_CASE(checkIntegerOverflow);
|
||||
TEST_CASE(signConversion);
|
||||
TEST_CASE(longCastAssign);
|
||||
|
@ -62,58 +61,6 @@ private:
|
|||
checkType.runChecks(&tokenizer, settings, this);
|
||||
}
|
||||
|
||||
void checkTooBigShift_AVR8() {
|
||||
Settings settings;
|
||||
settings.platform(Settings::AVR8);
|
||||
|
||||
// int, short and size_t on AVR is 2 bytes long
|
||||
{
|
||||
check("int foo(int x) { return x << 17;}",&settings);
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) Shifting 16-bit value by 17 bits is undefined behaviour\n", errout.str());
|
||||
check("int foo(int x) { return x << 16;}",&settings);
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) Shifting 16-bit value by 16 bits is undefined behaviour\n", errout.str());
|
||||
check("int foo(int x) { return x << 15;}",&settings);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
check("short foo(int x) { return x << 17;}",&settings);
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) Shifting 16-bit value by 17 bits is undefined behaviour\n", errout.str());
|
||||
check("short foo(int x) { return x << 16;}",&settings);
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) Shifting 16-bit value by 16 bits is undefined behaviour\n", errout.str());
|
||||
check("short foo(int x) { return x << 15;}",&settings);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
check("size_t foo(int x) { return x << 17;}",&settings);
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) Shifting 16-bit value by 17 bits is undefined behaviour\n", errout.str());
|
||||
check("size_t foo(int x) { return x << 16;}",&settings);
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) Shifting 16-bit value by 16 bits is undefined behaviour\n", errout.str());
|
||||
check("size_t foo(int x) { return x << 15;}",&settings);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
// long has four 4 bytes long
|
||||
{
|
||||
// downcast to int
|
||||
check("long foo(long x) { return (int)x << 33;}",&settings);
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) Shifting 16-bit value by 33 bits is undefined behaviour\n", errout.str());
|
||||
check("long foo(long x) { return x << 33;}",&settings);
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) Shifting 32-bit value by 33 bits is undefined behaviour\n", errout.str());
|
||||
check("long foo(long x) { return x << 32;}",&settings);
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) Shifting 32-bit value by 32 bits is undefined behaviour\n", errout.str());
|
||||
check("long foo(long x) { return x << 31;}",&settings);
|
||||
}
|
||||
// long long is 8 bytes long
|
||||
{
|
||||
// downcast to int
|
||||
check("long long foo(long long x) { return (int)x << 65;}",&settings);
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) Shifting 16-bit value by 65 bits is undefined behaviour\n", errout.str());
|
||||
// downcast to long
|
||||
check("long long foo(long long x) { return (long)x << 65;}",&settings);
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) Shifting 32-bit value by 65 bits is undefined behaviour\n", errout.str());
|
||||
check("long long foo(long long x) { return x << 65;}",&settings);
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) Shifting 64-bit value by 65 bits is undefined behaviour\n", errout.str());
|
||||
check("long long foo(long long x) { return x << 64;}",&settings);
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) Shifting 64-bit value by 64 bits is undefined behaviour\n", errout.str());
|
||||
check("long long foo(long long x) { return x << 63;}",&settings);
|
||||
}
|
||||
}
|
||||
|
||||
void checkTooBigShift_Unix32() {
|
||||
Settings settings;
|
||||
settings.platform(Settings::Unix32);
|
||||
|
|
Loading…
Reference in New Issue