[compiler-rt] Remove `__cdecl` from _ReturnAddress (PR #72919)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 20 14:12:29 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-compiler-rt-sanitizer
Author: nicole mazzuca (strega-nil)
<details>
<summary>Changes</summary>
As an intrinsic, `_ReturnAddress` does not need it; additionally,
if someone else declares `_ReturnAddress` without `__cdecl` (for
example, `<intrin.h>`)
Additionally, actually add a test for this change. I've tested it locally with both LLVM and MSVC.
---
Full diff: https://github.com/llvm/llvm-project/pull/72919.diff
2 Files Affected:
- (modified) compiler-rt/include/sanitizer/common_interface_defs.h (+1-1)
- (added) compiler-rt/test/asan/TestCases/Windows/msvc/gz.cpp (+15)
``````````diff
diff --git a/compiler-rt/include/sanitizer/common_interface_defs.h b/compiler-rt/include/sanitizer/common_interface_defs.h
index 56d9e008fa06e96..f9fce595b37bb89 100644
--- a/compiler-rt/include/sanitizer/common_interface_defs.h
+++ b/compiler-rt/include/sanitizer/common_interface_defs.h
@@ -293,7 +293,7 @@ void SANITIZER_CDECL __sanitizer_symbolize_global(void *data_ptr,
#define __sanitizer_return_address() \
__builtin_extract_return_addr(__builtin_return_address(0))
#else
-void *SANITIZER_CDECL _ReturnAddress(void);
+void *_ReturnAddress(void);
#pragma intrinsic(_ReturnAddress)
#define __sanitizer_return_address() _ReturnAddress()
#endif
diff --git a/compiler-rt/test/asan/TestCases/Windows/msvc/gz.cpp b/compiler-rt/test/asan/TestCases/Windows/msvc/gz.cpp
new file mode 100644
index 000000000000000..52a59d2fe335e7a
--- /dev/null
+++ b/compiler-rt/test/asan/TestCases/Windows/msvc/gz.cpp
@@ -0,0 +1,15 @@
+// Make sure that ASan works with non-cdecl default calling conventions.
+// Many x86 projects pass `/Gz` to their compiles, so that __stdcall is the default,
+// but LLVM is built with __cdecl.
+//
+// RUN: %clang_cl_asan -Gz %Od %s %Fe%t
+
+// includes a declaration of `_ReturnAddress`
+#include <intrin.h>
+
+#include <sanitizer/asan_interface.h>
+
+int main() {
+ alignas(8) char buffer[8];
+ __asan_poison_memory_region(buffer, sizeof buffer);
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/72919
More information about the llvm-commits
mailing list