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

[avr] Tools won't understand their own assembly code. #58853

Closed
sprintersb opened this issue Nov 7, 2022 · 4 comments
Closed

[avr] Tools won't understand their own assembly code. #58853

sprintersb opened this issue Nov 7, 2022 · 4 comments
Assignees

Comments

@sprintersb
Copy link

sprintersb commented Nov 7, 2022

Compile the following C module with

> clang --target=avr -c -save-temps
int r25, x;
void foo (void)
{
    r25 = x;
}

This will throw 4 errors at you:

*.s:8:11: error: invalid operand for instruction
        lds     r24, x
                     ^
*.s:9:11: error: invalid operand for instruction
        lds     r25, x+1
                     ^
*.s:10:6: error: invalid operand for instruction
        sts     r25+1, r25
                ^
*.s:11:6: error: invalid operand for instruction
        sts     r25, r24
                ^

The generated assembly code is all fine:

foo:
	lds	r24, x
	lds	r25, x+1
	sts	r25+1, r25
	sts	r25, r24
	ret
  • The 2nd operand of lds is an absolute address, hence legitimate operands are: symbol, symbol+offset or integer. Hence its obvious that x names a symbol, not a register.

  • The 1st operand of sts is an absolute address, hence legitimate operands are: symbol, symbol+offset or integer. Hence its obvious that r25 in the 1st operand names a symbol, not a register.

The appropriate RELOCs are of type R_AVR_16 in all the cases.

@benshi001 benshi001 assigned benshi001 and unassigned benshi001 Dec 12, 2022
@benshi001 benshi001 self-assigned this Dec 30, 2022
@benshi001
Copy link
Member

fixed by https://reviews.llvm.org/D140777

@benshi001
Copy link
Member

fixed by 7a45b13

@sprintersb
Copy link
Author

sprintersb commented Jan 7, 2023

Let ma add that the same problem also occurs with [r]jmp and [r]call when they are targetting a symbol like r24 or x. Again, compile with -save-temps:

int r24 (void);
int x (void);

int main (void)
{
    return x() + r24();
}

x and r24 are symbols that are perfectly fine, and let me add that with AVR ISA, there is no ambiguitiy of which kind an operand is. In the case above, it's a symbol or symbol+offset or int (any absolute constant that's known at link time or earlier).

@benshi001
Copy link
Member

ymbols that are perfectly fine, and let me add that with AVR ISA, the

This case is also fixed in the main branch. I have tested your new case with --save-temps and there is no failure report.

CarlosAlbertoEnciso pushed a commit to SNSystems/llvm-debuginfo-analyzer that referenced this issue Jan 9, 2023
Some specific operands in specific instructions should be treated
as variables/symbols/labels, other than registers.

This patch fixes those ambiguous cases, such as "lds r25, r24",
which means loading the value inside symbol 'r24' into register 'r25'.

Fixes llvm/llvm-project#58853

Reviewed by: aykevl

Differential Revision: https://reviews.llvm.org/D140777
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants