Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PowerPC] Emit warning when SP is clobbered by asm
This patch emits a warning when the stack pointer register (`R1`) is found in the clobber list of an inline asm statement. Clobbering the stack pointer is not supported. Reviewed By: #powerpc, nemanjai Differential Revision: https://reviews.llvm.org/D112073
- Loading branch information
Quinn Pham
authored and
Quinn Pham
committed
Jan 24, 2022
1 parent
997e128
commit 6a02829
Showing
5 changed files
with
96 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/// This test checks that the warning includes the location in the C source | ||
/// file that contains the inline asm. Although this warning is emitted in llvm | ||
/// it cannot be tested from IR as it does not have that location information at | ||
/// that stage. | ||
|
||
// REQUIRES: powerpc-registered-target | ||
|
||
// RUN: %clang --target=powerpc-unknown-unknown -mcpu=pwr7 \ | ||
// RUN: -c %s -o /dev/null 2>&1 | FileCheck %s | ||
// RUN: %clang --target=powerpc64-unknown-unknown -mcpu=pwr7 \ | ||
// RUN: -c %s -o /dev/null 2>&1 | FileCheck %s | ||
|
||
void test_r1_clobber() { | ||
__asm__("nop":::"r1"); | ||
} | ||
|
||
// CHECK: ppc-inline-asm-clobber-warning.c:14:11: warning: inline asm clobber list contains reserved registers: R1 [-Winline-asm] | ||
// CHECK-NEXT: __asm__("nop":::"r1"); | ||
// CHECK-NEXT: ^ | ||
// CHECK-NEXT: ppc-inline-asm-clobber-warning.c:14:11: note: Reserved registers on the clobber list may not be preserved across the asm statement, and clobbering them may lead to undefined behaviour. | ||
|
||
void test_1_clobber() { | ||
__asm__("nop":::"1"); | ||
} | ||
|
||
// CHECK: ppc-inline-asm-clobber-warning.c:23:11: warning: inline asm clobber list contains reserved registers: R1 [-Winline-asm] | ||
// CHECK-NEXT: __asm__("nop":::"1"); | ||
// CHECK-NEXT: ^ | ||
// CHECK-NEXT: ppc-inline-asm-clobber-warning.c:23:11: note: Reserved registers on the clobber list may not be preserved across the asm statement, and clobbering them may lead to undefined behaviour. | ||
|
||
void test_sp_clobber() { | ||
__asm__("nop":::"sp"); | ||
} | ||
|
||
// CHECK: ppc-inline-asm-clobber-warning.c:32:11: warning: inline asm clobber list contains reserved registers: R1 [-Winline-asm] | ||
// CHECK-NEXT: __asm__("nop":::"sp"); | ||
// CHECK-NEXT: ^ | ||
// CHECK-NEXT: ppc-inline-asm-clobber-warning.c:32:11: note: Reserved registers on the clobber list may not be preserved across the asm statement, and clobbering them may lead to undefined behaviour. |
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,22 @@ | ||
; RUN: llc < %s -verify-machineinstrs -mtriple=powerpc-unknown-unkown \ | ||
; RUN: -mcpu=pwr7 2>&1 | FileCheck %s | ||
; RUN: llc < %s -verify-machineinstrs -mtriple=powerpc64-unknown-unkown \ | ||
; RUN: -mcpu=pwr7 2>&1 | FileCheck %s | ||
|
||
define void @test_r1_clobber() { | ||
entry: | ||
call void asm sideeffect "nop", "~{r1}"() | ||
ret void | ||
} | ||
|
||
; CHECK: warning: inline asm clobber list contains reserved registers: R1 | ||
; CHECK-NEXT: note: Reserved registers on the clobber list may not be preserved across the asm statement, and clobbering them may lead to undefined behaviour. | ||
|
||
define void @test_x1_clobber() { | ||
entry: | ||
call void asm sideeffect "nop", "~{x1}"() | ||
ret void | ||
} | ||
|
||
; CHECK: warning: inline asm clobber list contains reserved registers: X1 | ||
; CHECK-NEXT: note: Reserved registers on the clobber list may not be preserved across the asm statement, and clobbering them may lead to undefined behaviour. |