From b7f208ffa770f45576706cc9478c35216e01c9a8 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 10 Apr 2024 16:58:32 +0200 Subject: [PATCH] Fix #12602 false positive: syntaxError for variable @ address (#6263) --- lib/tokenize.cpp | 12 ++++++------ test/testtokenize.cpp | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 56498b0d786..4d38a749845 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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); @@ -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() == "(") { @@ -9599,9 +9599,9 @@ void Tokenizer::simplifyAt() std::set 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; @@ -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); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 81c850b3613..4f4ac10d249 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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() {