diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp --- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp @@ -517,7 +517,8 @@ /// Predicate for Internalize pass. static bool mustPreserveGV(const GlobalValue &GV) { if (const Function *F = dyn_cast(&GV)) - return F->isDeclaration() || AMDGPU::isEntryFunctionCC(F->getCallingConv()); + return F->isDeclaration() || F->getName().startswith("__asan_") || + AMDGPU::isEntryFunctionCC(F->getCallingConv()); GV.removeDeadConstantUsers(); return !GV.use_empty(); diff --git a/llvm/test/CodeGen/AMDGPU/internalize.ll b/llvm/test/CodeGen/AMDGPU/internalize.ll --- a/llvm/test/CodeGen/AMDGPU/internalize.ll +++ b/llvm/test/CodeGen/AMDGPU/internalize.ll @@ -1,7 +1,7 @@ ; RUN: opt -O0 -S -mtriple=amdgcn-unknown-amdhsa -amdgpu-internalize-symbols < %s | FileCheck -check-prefix=ALL -check-prefix=OPTNONE %s ; RUN: opt -passes='default' -S -mtriple=amdgcn-unknown-amdhsa -amdgpu-internalize-symbols < %s | FileCheck -check-prefix=ALL -check-prefix=OPTNONE %s -; RUN: opt -O1 -S -mtriple=amdgcn-unknown-amdhsa -amdgpu-internalize-symbols < %s | FileCheck -check-prefix=ALL -check-prefix=OPT %s -; RUN: opt -passes='default' -S -mtriple=amdgcn-unknown-amdhsa -amdgpu-internalize-symbols < %s | FileCheck -check-prefix=ALL -check-prefix=OPT %s +; RUN: opt -O1 -S -mtriple=amdgcn-unknown-amdhsa -amdgpu-internalize-symbols < %s | FileCheck -check-prefix=ALL -check-prefix=OPT -check-prefix=ASAN_NO_INTERNALIZE %s +; RUN: opt -passes='default' -S -mtriple=amdgcn-unknown-amdhsa -amdgpu-internalize-symbols < %s | FileCheck -check-prefix=ALL -check-prefix=OPT -check-prefix=ASAN_NO_INTERNALIZE %s ; OPT-NOT: gvar_unused ; OPTNONE: gvar_unused @@ -10,6 +10,20 @@ ; ALL: gvar_used @gvar_used = addrspace(1) global i32 undef, align 4 +; OPTNONE: define void @__asan_no_explicit_linkage( +; ASAN_NO_INTERNALIZE: define void @__asan_no_explicit_linkage( +define void @__asan_no_explicit_linkage() { +entry: + ret void +} + +; OPTNONE: define weak void @__asan_weak_linkage( +; ASAN_NO_INTERNALIZE: define weak void @__asan_weak_linkage( +define weak void @__asan_weak_linkage() { +entry: + ret void +} + ; OPT: define internal fastcc void @func_used_noinline( ; OPT-NONE: define fastcc void @func_used_noinline( define fastcc void @func_used_noinline(i32 addrspace(1)* %out, i32 %tid) #1 {