Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #12602 false positive: syntaxError for variable @ address #6263

Merged
merged 4 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5509,6 +5509,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 @@ -5720,9 +5723,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 @@ -9609,9 +9609,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 @@ -9632,7 +9632,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 @@ -936,6 +936,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
Loading