From eb5dc3fdac5e9b8eda4d28b7684ff50b636bc0b5 Mon Sep 17 00:00:00 2001 From: apaz Date: Mon, 7 Nov 2022 23:18:57 -0600 Subject: [PATCH] Removed attributes from arguments to gc_preserve_begin (#47482) LLVM adds the nonnull attribute on its own, which makes the verifier fail. Fixes #47245 (cherry picked from commit bc39fd1c5bc248e0c796f61a39c48dc03e96d2d5) --- src/llvm-alloc-opt.cpp | 2 +- test/llvmpasses/alloc-opt-pass.jl | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/llvm-alloc-opt.cpp b/src/llvm-alloc-opt.cpp index f4a60cf739fc3..0b8b81edfbdf7 100644 --- a/src/llvm-alloc-opt.cpp +++ b/src/llvm-alloc-opt.cpp @@ -46,6 +46,7 @@ static void removeGCPreserve(CallInst *call, Instruction *val) { auto replace = Constant::getNullValue(val->getType()); call->replaceUsesOfWith(val, replace); + call->setAttributes(AttributeList()); for (auto &arg: call->arg_operands()) { if (!isa(arg.get())) { return; @@ -1426,7 +1427,6 @@ void Optimizer::splitOnStack(CallInst *orig_inst) } auto new_call = builder.CreateCall(pass.gc_preserve_begin_func, operands); new_call->takeName(call); - new_call->setAttributes(call->getAttributes()); call->replaceAllUsesWith(new_call); call->eraseFromParent(); return; diff --git a/test/llvmpasses/alloc-opt-pass.jl b/test/llvmpasses/alloc-opt-pass.jl index 9bde40036ff73..14225b068baa4 100644 --- a/test/llvmpasses/alloc-opt-pass.jl +++ b/test/llvmpasses/alloc-opt-pass.jl @@ -30,7 +30,7 @@ define void @preserve_branches(i8* %fptr, i1 %b, i1 %b2) { L1: %v = call noalias {} addrspace(10)* @julia.gc_alloc_obj(i8* %ptls_i8, $isz 8, {} addrspace(10)* @tag) - %tok = call token (...) @llvm.julia.gc_preserve_begin({} addrspace(10)* %v) + %tok = call token (...) @llvm.julia.gc_preserve_begin({} addrspace(10)* nonnull %v) call void @external_function() br i1 %b2, label %L2, label %L3 @@ -65,7 +65,7 @@ define void @preserve_branches2(i8* %fptr, i1 %b, i1 %b2) { L1: %v = call noalias {} addrspace(10)* @julia.gc_alloc_obj(i8* %ptls_i8, $isz 8, {} addrspace(10)* @tag) - %tok = call token (...) @llvm.julia.gc_preserve_begin({} addrspace(10)* %v, {} addrspace(10)* %v2) + %tok = call token (...) @llvm.julia.gc_preserve_begin({} addrspace(10)* %v, {} addrspace(10)* nonnull %v2) call void @external_function() br i1 %b2, label %L2, label %L3