aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/ModuleUtils.cpp
diff options
context:
space:
mode:
authorMatt Arsenault <Matthew.Arsenault@amd.com>2022-11-29 10:31:20 -0500
committerMatt Arsenault <Matthew.Arsenault@amd.com>2022-11-29 10:54:11 -0500
commit02ea3694a0a541f6328d120f02eb04977c1fc840 (patch)
treeba02099cbcc0d7b4ded36a4237f2e73d7bdcae70 /llvm/lib/Transforms/Utils/ModuleUtils.cpp
parent57dc4a8cab1257c5412471139ef4b6d6060997c9 (diff)
downloadllvm-02ea3694a0a541f6328d120f02eb04977c1fc840.zip
llvm-02ea3694a0a541f6328d120f02eb04977c1fc840.tar.gz
llvm-02ea3694a0a541f6328d120f02eb04977c1fc840.tar.bz2
Utils: Fix appending to global_ctors with program address spaces
Also fix constructing sanitizer constructors in address space 0 so it's testable (this was also failing the verifier on the type of global_ctors).
Diffstat (limited to 'llvm/lib/Transforms/Utils/ModuleUtils.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/ModuleUtils.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Utils/ModuleUtils.cpp b/llvm/lib/Transforms/Utils/ModuleUtils.cpp
index da588b3..b0f784b 100644
--- a/llvm/lib/Transforms/Utils/ModuleUtils.cpp
+++ b/llvm/lib/Transforms/Utils/ModuleUtils.cpp
@@ -30,7 +30,9 @@ static void appendToGlobalArray(StringRef ArrayName, Module &M, Function *F,
// to the list.
SmallVector<Constant *, 16> CurrentCtors;
StructType *EltTy = StructType::get(
- IRB.getInt32Ty(), PointerType::getUnqual(FnTy), IRB.getInt8PtrTy());
+ IRB.getInt32Ty(), PointerType::get(FnTy, F->getAddressSpace()),
+ IRB.getInt8PtrTy());
+
if (GlobalVariable *GVCtor = M.getNamedGlobal(ArrayName)) {
if (Constant *Init = GVCtor->getInitializer()) {
unsigned n = Init->getNumOperands();
@@ -123,7 +125,8 @@ llvm::declareSanitizerInitFunction(Module &M, StringRef InitName,
Function *llvm::createSanitizerCtor(Module &M, StringRef CtorName) {
Function *Ctor = Function::createWithDefaultAttr(
FunctionType::get(Type::getVoidTy(M.getContext()), false),
- GlobalValue::InternalLinkage, 0, CtorName, &M);
+ GlobalValue::InternalLinkage, M.getDataLayout().getProgramAddressSpace(),
+ CtorName, &M);
Ctor->addFnAttr(Attribute::NoUnwind);
BasicBlock *CtorBB = BasicBlock::Create(M.getContext(), "", Ctor);
ReturnInst::Create(M.getContext(), CtorBB);