Skip to content

Commit b7f208f

Browse files
Fix #12602 false positive: syntaxError for variable @ address (#6263)
1 parent 789be1c commit b7f208f

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

lib/tokenize.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5499,6 +5499,9 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
54995499

55005500
simplifySpaceshipOperator();
55015501

5502+
// @..
5503+
simplifyAt();
5504+
55025505
// Bail out if code is garbage
55035506
if (mTimerResults) {
55045507
Timer t("Tokenizer::simplifyTokens1::simplifyTokenList1::findGarbageCode", mSettings.showtime, mTimerResults);
@@ -5710,9 +5713,6 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
57105713
// Put ^{} statements in asm()
57115714
simplifyAsm2();
57125715

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

96019601
for (Token *tok = list.front(); tok; tok = tok->next()) {
9602-
if (Token::Match(tok, "%name%|] @ %num%|%name%|(")) {
9602+
if (Token::Match(tok, "%name%|] @ %num%|%name%|%str%|(")) {
96039603
const Token *end = tok->tokAt(2);
9604-
if (end->isNumber())
9604+
if (end->isLiteral())
96059605
end = end->next();
96069606
else if (end->str() == "(") {
96079607
int par = 0;
@@ -9622,7 +9622,7 @@ void Tokenizer::simplifyAt()
96229622
if (Token::Match(end, ": %num% ;"))
96239623
end = end->tokAt(2);
96249624

9625-
if (end && end->str() == ";") {
9625+
if (Token::Match(end, "[;=]")) {
96269626
if (tok->isName())
96279627
var.insert(tok->str());
96289628
tok->isAtAddress(true);

test/testtokenize.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,8 @@ class TestTokenizer : public TestFixture {
938938
ASSERT_EQUALS("int x [ 10 ] ;", tokenizeAndStringify("int x[10]@0x100;"));
939939

940940
ASSERT_EQUALS("interrupt@ f ( ) { }", tokenizeAndStringify("@interrupt f() {}"));
941+
942+
ASSERT_EQUALS("const short MyVariable = 0xF0F0 ;", tokenizeAndStringify("const short MyVariable @ \"MYOWNSECTION\" = 0xF0F0; ")); // #12602
941943
}
942944

943945
void inlineasm() {

0 commit comments

Comments
 (0)