From 898ff81b9ac51de2e4ca6586633d40ceb3aafb6e Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Wed, 1 Apr 2020 15:39:51 -0400 Subject: [PATCH] fix detection of srets containing tracked pointers in GC lowering --- src/llvm-late-gc-lowering.cpp | 13 +++++++------ test/compiler/codegen.jl | 11 +++++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/llvm-late-gc-lowering.cpp b/src/llvm-late-gc-lowering.cpp index e85e181a6cf58..65d8c0c84f851 100644 --- a/src/llvm-late-gc-lowering.cpp +++ b/src/llvm-late-gc-lowering.cpp @@ -1350,12 +1350,13 @@ State LateLowerGCFrame::LocalScan(Function &F) { MaybeNoteDef(S, BBS, CI, BBS.Safepoints); } if (CI->hasStructRetAttr()) { - AllocaInst *SRet = dyn_cast((CI->arg_begin()[0])->stripInBoundsOffsets()); - if (SRet) { - Type *ElT = SRet->getAllocatedType(); - if (!(SRet->isStaticAlloca() && isa(ElT) && ElT->getPointerAddressSpace() == AddressSpace::Tracked)) { - auto tracked = CountTrackedPointers(ElT); - if (tracked.count) { + Type *ElT = (CI->arg_begin()[0])->getType()->getPointerElementType(); + auto tracked = CountTrackedPointers(ElT); + if (tracked.count) { + AllocaInst *SRet = dyn_cast((CI->arg_begin()[0])->stripInBoundsOffsets()); + assert(SRet); + { + if (!(SRet->isStaticAlloca() && isa(ElT) && ElT->getPointerAddressSpace() == AddressSpace::Tracked)) { assert(!tracked.derived); if (tracked.all) { S.ArrayAllocas[SRet] = tracked.count * cast(SRet->getArraySize())->getZExtValue(); diff --git a/test/compiler/codegen.jl b/test/compiler/codegen.jl index 41e153e93544f..254548bf6126c 100644 --- a/test/compiler/codegen.jl +++ b/test/compiler/codegen.jl @@ -433,3 +433,14 @@ const c29864 = VecElement{Union{Int,Nothing}}(2) @noinline g29864() = VecElement{Union{Int,Nothing}}(3) @test f29864().value === 2 @test g29864().value === 3 + +# test sret pointing into a struct containing a tracked pointer +# reduced from TerminalLoggers/ProgressLogging +const _PROGRESS_LOGGING_UUID_NS_test = Base.UUID("1e962757-ea70-431a-b9f6-aadf988dcb7f") +_asuuid_test(id) = Base.uuid5(_PROGRESS_LOGGING_UUID_NS_test, repr(id)) +@noinline _handle_progress_test(progress) = progress +function _handle_message_test() + progress = (_asuuid_test(:id), "name") + return _handle_progress_test(progress) +end +@test _handle_message_test() isa Tuple{Base.UUID, String}