Skip to content

[clang][AVR] Improve compatibility of inline assembly with avr-gcc #136534

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

Merged
merged 3 commits into from
Apr 23, 2025
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
4 changes: 3 additions & 1 deletion clang/lib/Basic/Targets/AVR.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ class LLVM_LIBRARY_VISIBILITY AVRTargetInfo : public TargetInfo {
Info.setAllowsRegister();
return true;
case 'I': // 6-bit positive integer constant
Info.setRequiresImmediate(0, 63);
// Due to issue https://github.com/llvm/llvm-project/issues/51513, we
// allow value 64 in the frontend and let it be denied in the backend.
Info.setRequiresImmediate(0, 64);
return true;
case 'J': // 6-bit negative integer constant
Info.setRequiresImmediate(-63, 0);
Expand Down
2 changes: 2 additions & 0 deletions clang/test/CodeGen/avr/avr-inline-asm-constraints.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ void z() {
void I() {
// CHECK: call addrspace(0) void asm sideeffect "subi r30, $0", "I"(i16 50)
asm("subi r30, %0" :: "I"(50));
// CHECK: call addrspace(0) void asm sideeffect "subi r30, $0", "I"(i16 64)
asm("subi r30, %0" :: "I"(64));
}

void J() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ int foo(void) {
__asm__ volatile("foo %0, 1" : : "fo" (val)); // expected-error {{invalid input constraint 'fo' in asm}}
__asm__ volatile("foo %0, 1" : : "Nd" (val)); // expected-error {{invalid input constraint 'Nd' in asm}}
__asm__ volatile("subi r30, %0" : : "G" (1)); // expected-error {{value '1' out of range for constraint 'G'}}
__asm__ volatile("out %0, r20" : : "I" (65)); // expected-error {{value '65' out of range for constraint 'I'}}
}
6 changes: 6 additions & 0 deletions llvm/test/CodeGen/AVR/inline-asm/inline-asm-invalid.ll
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@ define void @foo2() {
call void asm sideeffect "ldd r24, X+2", ""()
ret void
}

define void @foo3() {
; AVR6: error: value out of range for constraint 'I'
call void asm sideeffect "out $0, r20", "I"(i16 64)
ret void
}
Loading