From 6f2e37429af186069cb93a30b436cb567293f047 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Wed, 6 Apr 2016 02:25:12 +0000 Subject: [PATCH] ValueMapper: Fix delayed blockaddress handling after r265273 r265273 added Mapper::mapBlockAddress, which delays mapping a blockaddress value until the function has a body. The condition was backwards, and should be checking Function::empty instead of GlobalValue::isDeclaration. llvm-svn: 265508 --- llvm/lib/Transforms/Utils/ValueMapper.cpp | 6 +++--- llvm/test/Transforms/Inline/blockaddress.ll | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Transforms/Utils/ValueMapper.cpp b/llvm/lib/Transforms/Utils/ValueMapper.cpp index c6285de..0c2954f 100644 --- a/llvm/lib/Transforms/Utils/ValueMapper.cpp +++ b/llvm/lib/Transforms/Utils/ValueMapper.cpp @@ -383,11 +383,11 @@ Value *Mapper::mapBlockAddress(const BlockAddress &BA) { // dummy basic block for now, and replace it once we've materialized all // the initializers. BasicBlock *BB; - if (F->isDeclaration()) { - BB = cast_or_null(mapValue(BA.getBasicBlock())); - } else { + if (F->empty()) { DelayedBBs.push_back(DelayedBasicBlock(BA)); BB = DelayedBBs.back().TempBB.get(); + } else { + BB = cast_or_null(mapValue(BA.getBasicBlock())); } return VM[&BA] = BlockAddress::get(F, BB ? BB : BA.getBasicBlock()); diff --git a/llvm/test/Transforms/Inline/blockaddress.ll b/llvm/test/Transforms/Inline/blockaddress.ll index 8eb3072..22ad882 100644 --- a/llvm/test/Transforms/Inline/blockaddress.ll +++ b/llvm/test/Transforms/Inline/blockaddress.ll @@ -26,3 +26,25 @@ entry: call void @doit(i8** @ptr1, i32 %cond) ret void } + +; PR27233: We can inline @run into @init. Don't crash on it. +; +; CHECK-LABEL: define void @init +; CHECK: store i8* blockaddress(@run, %bb) +; CHECK-SAME: @run.bb +define void @init() { +entry: + call void @run() + ret void +} + +define void @run() { +entry: + store i8* blockaddress(@run, %bb), i8** getelementptr inbounds ([1 x i8*], [1 x i8*]* @run.bb, i64 0, i64 0), align 8 + ret void + +bb: + unreachable +} + +@run.bb = global [1 x i8*] zeroinitializer -- 2.7.4