-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[Clang] Add __builtin_stack_address
#148281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 21 commits
029d9fc
0b5e0ed
2b8084a
020909e
88db438
0669180
aea6944
20d0259
da68490
6cdcf58
c56be28
1ed8a5d
1339b31
64eb4ad
7c38381
d47cb56
1ba60ce
4f1fad5
6ced7f8
fdb520a
1f77682
57e9fe5
ae3b2b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| // RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s | ||
|
|
||
| // CHECK-LABEL: define {{[^@]+}} @a() | ||
| // CHECK: call {{[^@]+}} @llvm.stackaddress.p0() | ||
| void *a() { | ||
| return __builtin_stack_address(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm %s -o - | llvm-cxxfilt | FileCheck %s --check-prefixes=COMMON,NO-OPT | ||
| // RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm %s -O3 -o - | llvm-cxxfilt | FileCheck %s --check-prefixes=COMMON,OPT | ||
|
|
||
| struct S { | ||
| void *a(); | ||
| }; | ||
|
|
||
| // COMMON-LABEL: @S::a() | ||
| // COMMON: call ptr @llvm.stackaddress.p0() | ||
| void *S::a() { | ||
| return __builtin_stack_address(); | ||
| } | ||
|
|
||
| // COMMON-LABEL: define {{[^@]+}} @two() | ||
| void *two() { | ||
|
|
||
| // The compiler is allowed to inline a function calling `__builtin_stack_address`. | ||
| // | ||
| // OPT-NOT: define {{[^@]+}} @"two()::$_0::operator()() const" | ||
| // OPT: call {{[^@]+}} @llvm.stackaddress.p0() | ||
| // | ||
| // NO-OPT-DAG: define {{[^@]+}} @"two()::$_0::operator()() const" | ||
| // NO-OPT-DAG: call {{[^@]+}} @"two()::$_0::operator()() const" | ||
| auto l = []() { return __builtin_stack_address(); }; | ||
| return l(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| ; RUN: llc < %s -mtriple=aarch64 | FileCheck %s | ||
|
|
||
| declare ptr @llvm.stackaddress.p0() | ||
|
|
||
| define ptr @test() { | ||
| ; CHECK: mov x0, sp | ||
| ; CHECK: ret | ||
| %sp = call ptr @llvm.stackaddress.p0() | ||
| ret ptr %sp | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| ; RUN: llc < %s -mtriple=armv7 | FileCheck %s | ||
|
|
||
| declare ptr @llvm.stackaddress.p0() | ||
|
|
||
| define ptr @test() { | ||
| ; CHECK: mov r0, sp | ||
| ; CHECK: bx lr | ||
| %sp = call ptr @llvm.stackaddress.p0() | ||
| ret ptr %sp | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| ; RUN: not llc < %s -mtriple nvptx 2>&1 | FileCheck %s | ||
|
|
||
| declare ptr @llvm.stackaddress.p0() | ||
|
|
||
| define ptr @test() { | ||
| ; CHECK: STACKADDRESS is not supported on this target. | ||
|
||
| %sp = call ptr @llvm.stackaddress.p0() | ||
| ret ptr %sp | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| ; RUN: llc < %s -mtriple=sparc | FileCheck --check-prefix=sparc32 %s | ||
| ; RUN: llc < %s -mtriple=sparcv9 | FileCheck --check-prefix=sparc64 %s | ||
|
|
||
| declare ptr @llvm.stackaddress.p0() | ||
|
|
||
| define ptr @test() { | ||
| ; sparc32: save %sp, -96, %sp | ||
| ; sparc32: ret | ||
| ; sparc32: restore %sp, 68, %o0 | ||
| ; | ||
| ; sparc64: save %sp, -128, %sp | ||
| ; sparc64: ret | ||
| ; sparc64: restore %sp, 2175, %o0 | ||
| %sp = call ptr @llvm.stackaddress.p0() | ||
| ret ptr %sp | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| ; RUN: llc < %s -mtriple=x86_64-linux-gnu -o - | FileCheck --check-prefix=x86_64 %s | ||
| ; RUN: llc < %s -mtriple=i386-linux-gnu -o - | FileCheck --check-prefix=i386 %s | ||
|
|
||
| declare ptr @llvm.stackaddress.p0() | ||
|
|
||
| define ptr @test() { | ||
| ; x86_64: movq %rsp, %rax | ||
| ; x86_64: retq | ||
|
|
||
| ; i386: movl %esp, %eax | ||
| ; i386: retl | ||
| %sp = call ptr @llvm.stackaddress.p0() | ||
| ret ptr %sp | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.