Skip to content

Commit

Permalink
Fix #12602 false positive: syntaxError for variable @ address (#6263)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Apr 10, 2024
1 parent 789be1c commit b7f208f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5499,6 +5499,9 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])

simplifySpaceshipOperator();

// @..
simplifyAt();

// Bail out if code is garbage
if (mTimerResults) {
Timer t("Tokenizer::simplifyTokens1::simplifyTokenList1::findGarbageCode", mSettings.showtime, mTimerResults);
Expand Down Expand Up @@ -5710,9 +5713,6 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
// Put ^{} statements in asm()
simplifyAsm2();

// @..
simplifyAt();

// When the assembly code has been cleaned up, no @ is allowed
for (const Token *tok = list.front(); tok; tok = tok->next()) {
if (tok->str() == "(") {
Expand Down Expand Up @@ -9599,9 +9599,9 @@ void Tokenizer::simplifyAt()
std::set<std::string> var;

for (Token *tok = list.front(); tok; tok = tok->next()) {
if (Token::Match(tok, "%name%|] @ %num%|%name%|(")) {
if (Token::Match(tok, "%name%|] @ %num%|%name%|%str%|(")) {
const Token *end = tok->tokAt(2);
if (end->isNumber())
if (end->isLiteral())
end = end->next();
else if (end->str() == "(") {
int par = 0;
Expand All @@ -9622,7 +9622,7 @@ void Tokenizer::simplifyAt()
if (Token::Match(end, ": %num% ;"))
end = end->tokAt(2);

if (end && end->str() == ";") {
if (Token::Match(end, "[;=]")) {
if (tok->isName())
var.insert(tok->str());
tok->isAtAddress(true);
Expand Down
2 changes: 2 additions & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,8 @@ class TestTokenizer : public TestFixture {
ASSERT_EQUALS("int x [ 10 ] ;", tokenizeAndStringify("int x[10]@0x100;"));

ASSERT_EQUALS("interrupt@ f ( ) { }", tokenizeAndStringify("@interrupt f() {}"));

ASSERT_EQUALS("const short MyVariable = 0xF0F0 ;", tokenizeAndStringify("const short MyVariable @ \"MYOWNSECTION\" = 0xF0F0; ")); // #12602
}

void inlineasm() {
Expand Down

0 comments on commit b7f208f

Please sign in to comment.