Fixed #6868 (Tokenizer: wrong simplification of the unlikely keyword)
This commit is contained in:
parent
8f309aed12
commit
72706cd0b8
|
@ -296,4 +296,6 @@
|
||||||
</arg>
|
</arg>
|
||||||
<leak-ignore/>
|
<leak-ignore/>
|
||||||
</function>
|
</function>
|
||||||
|
<define name="likely(X)" value="(X)"/>
|
||||||
|
<define name="unlikely(X)" value="(X)"/>
|
||||||
</def>
|
</def>
|
||||||
|
|
|
@ -3456,7 +3456,7 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
|
||||||
// remove Borland stuff..
|
// remove Borland stuff..
|
||||||
simplifyBorland();
|
simplifyBorland();
|
||||||
|
|
||||||
// Remove __builtin_expect, likely and unlikely
|
// Remove __builtin_expect
|
||||||
simplifyBuiltinExpect();
|
simplifyBuiltinExpect();
|
||||||
|
|
||||||
if (hasEnumsWithTypedef()) {
|
if (hasEnumsWithTypedef()) {
|
||||||
|
@ -9537,31 +9537,25 @@ void Tokenizer::simplifyBitfields()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Remove __builtin_expect(...), likely(...), and unlikely(...)
|
// Remove __builtin_expect(...)
|
||||||
void Tokenizer::simplifyBuiltinExpect()
|
void Tokenizer::simplifyBuiltinExpect()
|
||||||
{
|
{
|
||||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
if (Token::simpleMatch(tok->next(), "__builtin_expect (")) {
|
if (!Token::simpleMatch(tok->next(), "__builtin_expect ("))
|
||||||
// Count parentheses for tok2
|
continue;
|
||||||
const Token* end = tok->linkAt(2);
|
// Count parentheses for tok2
|
||||||
for (Token *tok2 = tok->tokAt(3); tok2 != end; tok2 = tok2->next()) {
|
const Token* end = tok->linkAt(2);
|
||||||
if (tok2->str() == "(") {
|
for (Token *tok2 = tok->tokAt(3); tok2 != end; tok2 = tok2->next()) {
|
||||||
tok2 = tok2->link();
|
if (tok2->str() == "(") {
|
||||||
} else if (tok2->str() == ",") {
|
tok2 = tok2->link();
|
||||||
if (Token::Match(tok2, ", %num% )")) {
|
} else if (tok2->str() == ",") {
|
||||||
tok->deleteNext();
|
if (Token::Match(tok2, ", %num% )")) {
|
||||||
tok2->deleteNext();
|
tok->deleteNext();
|
||||||
tok2->deleteThis();
|
tok2->deleteNext();
|
||||||
}
|
tok2->deleteThis();
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} else if (Token::Match(tok->next(), "likely|unlikely (")) {
|
|
||||||
// remove closing ')'
|
|
||||||
tok->linkAt(2)->deleteThis();
|
|
||||||
|
|
||||||
// remove "likely|unlikely ("
|
|
||||||
tok->deleteNext(2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -650,7 +650,7 @@ private:
|
||||||
void simplifyBitfields();
|
void simplifyBitfields();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove __builtin_expect(...), likely(...), and unlikely(...)
|
* Remove __builtin_expect(...)
|
||||||
*/
|
*/
|
||||||
void simplifyBuiltinExpect();
|
void simplifyBuiltinExpect();
|
||||||
|
|
||||||
|
|
|
@ -856,12 +856,9 @@ private:
|
||||||
|
|
||||||
void ifa_ifa() {
|
void ifa_ifa() {
|
||||||
ASSERT_EQUALS("int a ; if ( a ) { { ab } cd }", tok("int a ; if (a) { if (a) { ab } cd }", true));
|
ASSERT_EQUALS("int a ; if ( a ) { { ab } cd }", tok("int a ; if (a) { if (a) { ab } cd }", true));
|
||||||
ASSERT_EQUALS("int a ; if ( a ) { { ab } cd }", tok("int a ; if (unlikely(a)) { if (a) { ab } cd }", true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
unsigned int sizeofFromTokenizer(const char type[]) {
|
unsigned int sizeofFromTokenizer(const char type[]) {
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
|
@ -3857,8 +3854,6 @@ private:
|
||||||
ASSERT_EQUALS("class C { int f ( ) ; } ;", tok("class C { int f() override ; };", true));
|
ASSERT_EQUALS("class C { int f ( ) ; } ;", tok("class C { int f() override ; };", true));
|
||||||
ASSERT_EQUALS("class C { int f ( ) ; } ;", tok("class C { int f() final ; };", true));
|
ASSERT_EQUALS("class C { int f ( ) ; } ;", tok("class C { int f() final ; };", true));
|
||||||
ASSERT_EQUALS("void f ( ) { int final [ 10 ] ; }", tok("void f() { int final[10]; }", true));
|
ASSERT_EQUALS("void f ( ) { int final [ 10 ] ; }", tok("void f() { int final[10]; }", true));
|
||||||
ASSERT_EQUALS("if ( a ) { }", tok("if ( likely ( a ) ) { }", true));
|
|
||||||
ASSERT_EQUALS("if ( a ) { }", tok("if ( unlikely ( a ) ) { }", true));
|
|
||||||
ASSERT_EQUALS("int * p ;", tok("int * __restrict p;", "test.c"));
|
ASSERT_EQUALS("int * p ;", tok("int * __restrict p;", "test.c"));
|
||||||
ASSERT_EQUALS("int * * p ;", tok("int * __restrict__ * p;", "test.c"));
|
ASSERT_EQUALS("int * * p ;", tok("int * __restrict__ * p;", "test.c"));
|
||||||
ASSERT_EQUALS("void foo ( float * a , float * b ) ;", tok("void foo(float * __restrict__ a, float * __restrict__ b);", "test.c"));
|
ASSERT_EQUALS("void foo ( float * a , float * b ) ;", tok("void foo(float * __restrict__ a, float * __restrict__ b);", "test.c"));
|
||||||
|
|
|
@ -295,7 +295,7 @@ private:
|
||||||
TEST_CASE(syntax_error_templates_3); // Ticket #5605, #5759, #5762, #5774
|
TEST_CASE(syntax_error_templates_3); // Ticket #5605, #5759, #5762, #5774
|
||||||
TEST_CASE(template_member_ptr); // Ticket #5786 - crash upon valid code
|
TEST_CASE(template_member_ptr); // Ticket #5786 - crash upon valid code
|
||||||
|
|
||||||
TEST_CASE(removeKeywords);
|
TEST_CASE(simplifyBuiltinExpect);
|
||||||
|
|
||||||
// unsigned i; => unsigned int i;
|
// unsigned i; => unsigned int i;
|
||||||
TEST_CASE(unsigned1);
|
TEST_CASE(unsigned1);
|
||||||
|
@ -4355,7 +4355,7 @@ private:
|
||||||
"};");
|
"};");
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeKeywords() {
|
void simplifyBuiltinExpect() {
|
||||||
const char code[] = "if (__builtin_expect(!!(x), 1));";
|
const char code[] = "if (__builtin_expect(!!(x), 1));";
|
||||||
ASSERT_EQUALS("if ( ! ! x ) { ; }", tokenizeAndStringify(code, true));
|
ASSERT_EQUALS("if ( ! ! x ) { ; }", tokenizeAndStringify(code, true));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue