Fixed #1382 (False positive: uninitialized variable when using assembly to initialize variable)

This commit is contained in:
Daniel Marjamäki 2010-02-12 18:15:15 +01:00
parent 2a78637da7
commit 669fe1b23d
2 changed files with 38 additions and 3 deletions

View File

@ -1081,15 +1081,31 @@ std::string Preprocessor::getcode(const std::string &filedata, std::string cfg,
bool found_end = false;
while (getline(istr, line))
{
ret << "\n";
if (line.compare(0, 14, "#pragma endasm") == 0)
{
found_end = true;
break;
}
ret << "\n";
}
if (!found_end)
break;
if (line.find("=") != std::string::npos)
{
Tokenizer tokenizer;
line.erase(0, sizeof("#pragma endasm"));
std::istringstream istr(line.c_str());
tokenizer.tokenize(istr, "");
if (Token::Match(tokenizer.tokens(), "( %var% = %any% )"))
{
ret << "asm(" << tokenizer.tokens()->strAt(1) << ");";
}
}
ret << "\n";
continue;
}

View File

@ -157,7 +157,8 @@ private:
TEST_CASE(stringify5);
TEST_CASE(ifdefwithfile);
TEST_CASE(pragma);
TEST_CASE(pragma_asm);
TEST_CASE(pragma_asm_1);
TEST_CASE(pragma_asm_2);
TEST_CASE(endifsemicolon);
TEST_CASE(missing_doublequote);
TEST_CASE(handle_error);
@ -1518,7 +1519,7 @@ private:
ASSERT_EQUALS("\nvoid f()\n{\n}\n", actual[""]);
}
void pragma_asm()
void pragma_asm_1()
{
const char filedata[] = "#pragma asm\n"
" mov r1, 11\n"
@ -1540,6 +1541,24 @@ private:
ASSERT_EQUALS("\n\n\naaa\n\n\n\nbbb\n", actual[""]);
}
void pragma_asm_2()
{
const char filedata[] = "#pragma asm\n"
" mov @w1, 11\n"
"#pragma endasm ( temp=@w1 )\n"
"bbb";
// Preprocess => actual result..
std::istringstream istr(filedata);
std::map<std::string, std::string> actual;
Preprocessor preprocessor;
preprocessor.preprocess(istr, actual, "file.c");
// Compare results..
ASSERT_EQUALS(1, static_cast<unsigned int>(actual.size()));
ASSERT_EQUALS("\n\nasm(temp);\nbbb\n", actual[""]);
}
void endifsemicolon()
{
const char filedata[] = "void f()\n"