Skip to content

Commit b0524f3

Browse files
authored
[clang][AVR] Improve compatibility of inline assembly with avr-gcc (#136534)
Allow the value 64 to be round up to 0 for constraint 'I'.
1 parent 720a911 commit b0524f3

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

clang/lib/Basic/Targets/AVR.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ class LLVM_LIBRARY_VISIBILITY AVRTargetInfo : public TargetInfo {
124124
Info.setAllowsRegister();
125125
return true;
126126
case 'I': // 6-bit positive integer constant
127-
Info.setRequiresImmediate(0, 63);
127+
// Due to issue https://github.com/llvm/llvm-project/issues/51513, we
128+
// allow value 64 in the frontend and let it be denied in the backend.
129+
Info.setRequiresImmediate(0, 64);
128130
return true;
129131
case 'J': // 6-bit negative integer constant
130132
Info.setRequiresImmediate(-63, 0);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ void z() {
7171
void I() {
7272
// CHECK: call addrspace(0) void asm sideeffect "subi r30, $0", "I"(i16 50)
7373
asm("subi r30, %0" :: "I"(50));
74+
// CHECK: call addrspace(0) void asm sideeffect "subi r30, $0", "I"(i16 64)
75+
asm("subi r30, %0" :: "I"(64));
7476
}
7577

7678
void J() {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ 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}}
88
__asm__ volatile("subi r30, %0" : : "G" (1)); // expected-error {{value '1' out of range for constraint 'G'}}
9+
__asm__ volatile("out %0, r20" : : "I" (65)); // expected-error {{value '65' out of range for constraint 'I'}}
910
}

llvm/test/CodeGen/AVR/inline-asm/inline-asm-invalid.ll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,9 @@ define void @foo2() {
2121
call void asm sideeffect "ldd r24, X+2", ""()
2222
ret void
2323
}
24+
25+
define void @foo3() {
26+
; AVR6: error: value out of range for constraint 'I'
27+
call void asm sideeffect "out $0, r20", "I"(i16 64)
28+
ret void
29+
}

0 commit comments

Comments
 (0)