[clang] [llvm] [Clang] Add `__builtin_stack_address` (PR #148281)

Aaron Ballman via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 4 09:35:49 PDT 2025


================
@@ -36,3 +36,8 @@ void* h(unsigned x) {
 // expected-error at +1 {{argument value 1048575 is outside the valid range [0, 65535]}}
 return __builtin_frame_address(0xFFFFF);
 }
+
+void *i() {
+// expected-error at +1 {{too many arguments to function call, expected 0, have 1}}
+return __builtin_stack_address(0);
----------------
AaronBallman wrote:

```suggestion
  // expected-error at +1 {{too many arguments to function call, expected 0, have 1}}
  return __builtin_stack_address(0);
```
Other test cases I would like to see are:
```
 // As a global variable where there is no stack address to get.
// This should be diagnosed as an error?
void *ptr = __builtin_stack_address();

inline void *what() {
  return __builtin_stack_address();
}

void func() {
  void *ptr = what(); // Is this getting the stack address of? The inline function or is it getting the stack address of the caller? Or depends on optimization level?
}
```
Should we also have tests for what happens with naked functions or other kind of odd situations where the stack may be different from the normal case?

https://github.com/llvm/llvm-project/pull/148281


More information about the llvm-commits mailing list