Skip to content

Commit

Permalink
[clang][AVR] Restrict range of assembly constraint 'G' (llvm#76561)
Browse files Browse the repository at this point in the history
According to
https://www.nongnu.org/avr-libc/user-manual/inline_asm.html, 'G' only
represents floating point constant '0.0'. And avr-gcc also rejects other
non-zero FP values.
  • Loading branch information
benshi001 authored Jan 4, 2024
1 parent 0cdaadf commit 75365b2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion clang/lib/Basic/Targets/AVR.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ class LLVM_LIBRARY_VISIBILITY AVRTargetInfo : public TargetInfo {
case 'R': // Integer constant (Range: -6 to 5)
Info.setRequiresImmediate(-6, 5);
return true;
case 'G': // Floating point constant
case 'G': // Floating point constant 0.0
Info.setRequiresImmediate(0);
return true;
case 'Q': // A memory address based on Y or Z pointer with displacement.
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions clang/test/CodeGen/avr/avr-inline-asm-constraints.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ void R() {
}

void G() {
// CHECK: call addrspace(0) void asm sideeffect "subi r30, $0", "G"(i16 50)
asm("subi r30, %0" :: "G"(50));
// CHECK: call addrspace(0) void asm sideeffect "subi r30, $0", "G"(i16 0)
asm("subi r30, %0" :: "G"(0));
}

void Q() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ const unsigned char val = 0;
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'}}
}

0 comments on commit 75365b2

Please sign in to comment.