Skip to content

Conversation

@ampandey-1995
Copy link
Contributor

@ampandey-1995 ampandey-1995 commented Nov 11, 2025

This patch adds the following device ASan hooks and guarded macros in
__clang_hip_libdevice_declares.h

  • Function Declarations

    • __asan_poison_memory_region
    • __asan_unpoison_memory_region
    • __asan_address_is_poisoned
    • __asan_region_is_poisoned
  • Macros

    • ASAN_POISON_MEMORY_REGION
    • ASAN_UNPOISON_MEMORY_REGION

@llvmbot llvmbot added clang Clang issues not falling into any other category backend:X86 clang:headers Headers provided by Clang, e.g. for intrinsics labels Nov 11, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 11, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-backend-x86

Author: Amit Kumar Pandey (ampandey-1995)

Changes

__clang_hip_libdevice_declares.h Add device declarations for the following AddressSanitizer hooks:

  • Function Declarations

    • __asan_poison_memory_region
    • __asan_unpoison_memory_region
    • __asan_address_is_poisoned
    • __asan_region_is_poisoned
  • Macros

    • ASAN_POISON_MEMORY_REGION
    • ASAN_UNPOISON_MEMORY_REGION

Full diff: https://github.com/llvm/llvm-project/pull/167522.diff

1 Files Affected:

  • (modified) clang/lib/Headers/__clang_hip_libdevice_declares.h (+15)
diff --git a/clang/lib/Headers/__clang_hip_libdevice_declares.h b/clang/lib/Headers/__clang_hip_libdevice_declares.h
index fa8d918248dd0..cf4b9d486b903 100644
--- a/clang/lib/Headers/__clang_hip_libdevice_declares.h
+++ b/clang/lib/Headers/__clang_hip_libdevice_declares.h
@@ -338,6 +338,21 @@ __device__ __attribute__((const)) __2f16 __ocml_sqrt_2f16(__2f16);
 __device__ __attribute__((const)) __2f16 __ocml_trunc_2f16(__2f16);
 __device__ __attribute__((const)) __2f16 __ocml_pown_2f16(__2f16, __2i16);
 
+__device__ void __asan_poison_memory_region(const void *addr,  size_t size);
+__device__ void __asan_unpoison_memory_region(const void *addr,  size_t size);
+__device__ int  __asan_address_is_poisoned(const void *addr);
+__device__ void *__asan_region_is_poisoned(void *beg, size_t size);
+
+#if __has_feature(address_sanitizer)
+#define ASAN_POISON_MEMORY_REGION(addr, size)                                  \
+  __asan_poison_memory_region((addr), (size))
+#define ASAN_UNPOISON_MEMORY_REGION(addr, size)                                \
+  __asan_unpoison_memory_region((addr), (size))
+#else
+#define ASAN_POISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))
+#define ASAN_UNPOISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))
+#endif
+
 #ifdef __cplusplus
 } // extern "C"
 #endif

@github-actions
Copy link

github-actions bot commented Nov 11, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@ampandey-1995 ampandey-1995 changed the title [ASan][HIP] Declare device ASan hooks and guarded macros in [ASan][HIP] Add ASan declarations and macros. Nov 11, 2025
This patch adds the following device ASan hooks and guarded macros in
__clang_hip_libdevice_declares.h

  - Function Declarations
    - __asan_poison_memory_region
    - __asan_unpoison_memory_region
    - __asan_address_is_poisoned
    - __asan_region_is_poisoned

  - Macros
    - ASAN_POISON_MEMORY_REGION
    - ASAN_UNPOISON_MEMORY_REGION
Switch from 'size_t' to '__SIZE_TYPE__'
Copy link

@b-sumner b-sumner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks good. @yxsamliu do you have any concerns about it?

@b-sumner b-sumner merged commit c1c22cd into llvm:main Nov 17, 2025
10 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Nov 17, 2025

LLVM Buildbot has detected a new failure on builder llvm-clang-aarch64-darwin running on doug-worker-4 while building clang at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/31126

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'LLVM :: ExecutionEngine/OrcLazy/multiple-compile-threads-basic.ll' FAILED ********************
Exit Code: 2

Command Output (stdout):
--
# RUN: at line 1
/Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/lli -jit-kind=orc-lazy -compile-threads=2 -thread-entry hello /Users/buildbot/buildbot-root/llvm-project/llvm/test/ExecutionEngine/OrcLazy/multiple-compile-threads-basic.ll | /Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/FileCheck /Users/buildbot/buildbot-root/llvm-project/llvm/test/ExecutionEngine/OrcLazy/multiple-compile-threads-basic.ll
# executed command: /Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/lli -jit-kind=orc-lazy -compile-threads=2 -thread-entry hello /Users/buildbot/buildbot-root/llvm-project/llvm/test/ExecutionEngine/OrcLazy/multiple-compile-threads-basic.ll
# .---command stderr------------
# | PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
# | Stack dump:
# | 0.	Program arguments: /Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/lli -jit-kind=orc-lazy -compile-threads=2 -thread-entry hello /Users/buildbot/buildbot-root/llvm-project/llvm/test/ExecutionEngine/OrcLazy/multiple-compile-threads-basic.ll
# |  #0 0x00000001033658cc llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/lli+0x100f298cc)
# |  #1 0x000000010336367c llvm::sys::RunSignalHandlers() (/Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/lli+0x100f2767c)
# |  #2 0x00000001033663cc SignalHandler(int, __siginfo*, void*) (/Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/lli+0x100f2a3cc)
# |  #3 0x0000000195727584 (/usr/lib/system/libsystem_platform.dylib+0x18047b584)
# |  #4 0x0000010102eb9538
# |  #5 0x0000000102ec3294 llvm::orc::ExecutionSession::removeJITDylibs(std::__1::vector<llvm::IntrusiveRefCntPtr<llvm::orc::JITDylib>, std::__1::allocator<llvm::IntrusiveRefCntPtr<llvm::orc::JITDylib>>>) (/Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/lli+0x100a87294)
# |  #6 0x0000000102ec3044 llvm::orc::ExecutionSession::endSession() (/Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/lli+0x100a87044)
# |  #7 0x0000000102f4f8ec llvm::orc::LLJIT::~LLJIT() (/Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/lli+0x100b138ec)
# |  #8 0x0000000102f54278 llvm::orc::LLLazyJIT::~LLLazyJIT() (/Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/lli+0x100b18278)
# |  #9 0x00000001024439c4 runOrcJIT(char const*) (/Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/lli+0x1000079c4)
# | #10 0x000000010243eee0 main (/Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/lli+0x100002ee0)
# | #11 0x000000019536b154
# `-----------------------------
# error: command failed with exit status: -11
# executed command: /Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/FileCheck /Users/buildbot/buildbot-root/llvm-project/llvm/test/ExecutionEngine/OrcLazy/multiple-compile-threads-basic.ll
# .---command stderr------------
# | FileCheck error: '<stdin>' is empty.
# | FileCheck command line:  /Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/FileCheck /Users/buildbot/buildbot-root/llvm-project/llvm/test/ExecutionEngine/OrcLazy/multiple-compile-threads-basic.ll
# `-----------------------------
# error: command failed with exit status: 2

--

********************


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend:X86 clang:headers Headers provided by Clang, e.g. for intrinsics clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants