Tokenizer: Fixed goto problems
This commit is contained in:
parent
7f6a10599b
commit
47e1a571f7
|
@ -6697,14 +6697,12 @@ void Tokenizer::simplifyGoto()
|
|||
}
|
||||
|
||||
else if (tok->str() == "}") {
|
||||
if (!indentlevel) {
|
||||
if (indentlevel == 0) {
|
||||
if (indentspecial)
|
||||
--indentspecial;
|
||||
else
|
||||
break; // break out - it seems the code is wrong
|
||||
} else {
|
||||
--indentlevel;
|
||||
if (!indentlevel) {
|
||||
if (indentlevel == 0) {
|
||||
gotos.clear();
|
||||
beginfunction = 0;
|
||||
}
|
||||
|
@ -6839,12 +6837,16 @@ void Tokenizer::simplifyGoto()
|
|||
}
|
||||
|
||||
// goto the end of the function
|
||||
while (tok) {
|
||||
if (tok->str() == "{")
|
||||
tok = tok->link();
|
||||
else if (tok->str() == "}")
|
||||
break;
|
||||
tok = tok->next();
|
||||
if (tok->str() == "{")
|
||||
tok = tok->link();
|
||||
else {
|
||||
while (tok) {
|
||||
if (tok->str() == "{")
|
||||
tok = tok->link();
|
||||
else if (tok->str() == "}")
|
||||
break;
|
||||
tok = tok->next();
|
||||
}
|
||||
}
|
||||
if (!tok)
|
||||
break;
|
||||
|
|
|
@ -174,6 +174,7 @@ private:
|
|||
TEST_CASE(goto3); // #3138
|
||||
TEST_CASE(goto4); // #3459
|
||||
TEST_CASE(goto5); // #3705 - return ({asm("");});
|
||||
TEST_CASE(goto6);
|
||||
|
||||
//remove dead code after flow control statements
|
||||
TEST_CASE(flowControl);
|
||||
|
@ -3347,6 +3348,33 @@ private:
|
|||
"}", tok(code));
|
||||
}
|
||||
|
||||
void goto6() { // from code in linux that wasn't handled well
|
||||
const char code1[] = "static void a() {\n"
|
||||
"unlock:\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"static void b() {\n"
|
||||
" if (c)\n"
|
||||
" goto defer;\n"
|
||||
"defer:\n"
|
||||
"}\n";
|
||||
ASSERT_EQUALS("static void a ( ) { } "
|
||||
"static void b ( ) { if ( c ) { return ; } }", tok(code1));
|
||||
|
||||
const char code2[] = "void a()\n"
|
||||
"{\n"
|
||||
" if (x) {}\n"
|
||||
"unlock:\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"void b()\n"
|
||||
"{\n"
|
||||
" { goto defer; }\n"
|
||||
"defer:\n"
|
||||
"}";
|
||||
ASSERT_EQUALS("void a ( ) { if ( x ) { } } void b ( ) { return ; }", tok(code2));
|
||||
}
|
||||
|
||||
void flowControl() {
|
||||
std::list<std::string> beforedead;
|
||||
//beforedead.push_back("return");
|
||||
|
|
Loading…
Reference in New Issue