Skip to content

Commit 75365b2

Browse files
authored
[clang][AVR] Restrict range of assembly constraint 'G' (#76561)
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.
1 parent 0cdaadf commit 75365b2

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

clang/lib/Basic/Targets/AVR.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ class LLVM_LIBRARY_VISIBILITY AVRTargetInfo : public TargetInfo {
146146
case 'R': // Integer constant (Range: -6 to 5)
147147
Info.setRequiresImmediate(-6, 5);
148148
return true;
149-
case 'G': // Floating point constant
149+
case 'G': // Floating point constant 0.0
150+
Info.setRequiresImmediate(0);
151+
return true;
150152
case 'Q': // A memory address based on Y or Z pointer with displacement.
151153
return true;
152154
}

clang/test/CodeGen/avr/avr-inline-asm-constraints.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ void R() {
109109
}
110110

111111
void G() {
112-
// CHECK: call addrspace(0) void asm sideeffect "subi r30, $0", "G"(i16 50)
113-
asm("subi r30, %0" :: "G"(50));
112+
// CHECK: call addrspace(0) void asm sideeffect "subi r30, $0", "G"(i16 0)
113+
asm("subi r30, %0" :: "G"(0));
114114
}
115115

116116
void Q() {

clang/test/CodeGen/avr/avr-unsupported-inline-asm-constraints.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ const unsigned char val = 0;
55
int foo(void) {
66
__asm__ volatile("foo %0, 1" : : "fo" (val)); // expected-error {{invalid input constraint 'fo' in asm}}
77
__asm__ volatile("foo %0, 1" : : "Nd" (val)); // expected-error {{invalid input constraint 'Nd' in asm}}
8+
__asm__ volatile("subi r30, %0" : : "G" (1)); // expected-error {{value '1' out of range for constraint 'G'}}
89
}

0 commit comments

Comments
 (0)