Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CodeGen][ARM] Error when writing to specific reserved registers in i…
…nline asm Summary: No error or warning is emitted when specific reserved registers are written to in inline assembly. Therefore, writes to the program counter or to the frame pointer, for instance, were permitted, which could have led to undesirable behaviour. Example: int foo() { register int a __asm__("r7"); // r7 = frame-pointer in M-class ARM __asm__ __volatile__("mov %0, r1" : "=r"(a) : : ); return a; } In contrast, GCC issues an error in the same scenario. This patch detects writes to specific reserved registers in inline assembly for ARM and emits an error in such case. The detection works for output and input operands. Clobber operands are not handled here: they are already covered at a later point in AsmPrinter::emitInlineAsm(const MachineInstr *MI). The registers covered are: program counter, frame pointer and base pointer. This is ARM only. Therefore the implementation of other targets' counterparts remain open to do. Reviewers: efriedma Reviewed By: efriedma Subscribers: kristof.beyls, hiraditya, danielkiss, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D76848
- Loading branch information
Showing
5 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
; RUN: not llc -mtriple thumbv6m-arm-none-eabi -frame-pointer=all %s 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR | ||
|
||
; CHECK-ERROR: error: write to reserved register 'R7' | ||
define void @test_framepointer_output(i32 %input) { | ||
entry: | ||
%0 = call i32 asm sideeffect "mov $0, $1", "={r7},r"(i32 %input) | ||
ret void | ||
} | ||
|
||
; CHECK-ERROR: error: write to reserved register 'R7' | ||
define void @test_framepointer_input(i32 %input) { | ||
entry: | ||
%0 = call i32 asm sideeffect "mov $0, $1", "=r,{r7}"(i32 %input) | ||
ret void | ||
} | ||
|
||
; CHECK-ERROR: error: write to reserved register 'PC' | ||
define void @test_pc_output(i32 %input) { | ||
entry: | ||
%0 = call i32 asm sideeffect "mov $0, $1", "={pc},r"(i32 %input) | ||
ret void | ||
} | ||
|
||
; CHECK-ERROR: error: write to reserved register 'PC' | ||
define void @test_pc_input(i32 %input) { | ||
entry: | ||
%0 = call i32 asm sideeffect "mov $0, $1", "=r,{pc}"(i32 %input) | ||
ret void | ||
} | ||
|
||
; CHECK-ERROR: error: write to reserved register 'R6' | ||
define void @test_basepointer_output(i32 %size, i32 %input) alignstack(8) { | ||
entry: | ||
%vla = alloca i32, i32 %size, align 4 | ||
%0 = call i32 asm sideeffect "mov $0, $1", "={r6},r"(i32 %input) | ||
ret void | ||
} | ||
|
||
; CHECK-ERROR: error: write to reserved register 'R6' | ||
define void @test_basepointer_input(i32 %size, i32 %input) alignstack(8) { | ||
entry: | ||
%vla = alloca i32, i32 %size, align 4 | ||
%0 = call i32 asm sideeffect "mov $0, $1", "=r,{r6}"(i32 %input) | ||
ret void | ||
} |