From f02b39ca4c14050d0fb9f5427c8be8b106a5de79 Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Wed, 2 Aug 2017 15:52:32 +0000 Subject: [PATCH] Merging r309594: ------------------------------------------------------------------------ r309594 | majnemer | 2017-07-31 10:47:07 -0700 (Mon, 31 Jul 2017) | 4 lines [IPSCCP] Guard a user of getInitializer with hasDefinitiveInitializer We are not allowed to reason about an initializer value without first consulting hasDefinitiveInitializer. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_50@309827 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/SCCP.cpp | 3 ++- test/Transforms/SCCP/definite-initializer.ll | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 test/Transforms/SCCP/definite-initializer.ll diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp index a738ebb4607..4822cf7cce0 100644 --- a/lib/Transforms/Scalar/SCCP.cpp +++ b/lib/Transforms/Scalar/SCCP.cpp @@ -1790,7 +1790,8 @@ static bool runIPSCCP(Module &M, const DataLayout &DL, // variables that do not have their 'addresses taken'. If they don't have // their addresses taken, we can propagate constants through them. for (GlobalVariable &G : M.globals()) - if (!G.isConstant() && G.hasLocalLinkage() && !AddressIsTaken(&G)) + if (!G.isConstant() && G.hasLocalLinkage() && + G.hasDefinitiveInitializer() && !AddressIsTaken(&G)) Solver.TrackValueOfGlobalVariable(&G); // Solve for constants. diff --git a/test/Transforms/SCCP/definite-initializer.ll b/test/Transforms/SCCP/definite-initializer.ll new file mode 100644 index 00000000000..a2c4521e07c --- /dev/null +++ b/test/Transforms/SCCP/definite-initializer.ll @@ -0,0 +1,11 @@ +; RUN: opt -S -ipsccp < %s | FileCheck %s +@d = internal externally_initialized global i32 0, section ".openbsd.randomdata", align 4 + +; CHECK-LABEL: @test1( +define i32 @test1() { +entry: + %load = load i32, i32* @d, align 4 + ret i32 %load +; CHECK: %[[load:.*]] = load i32, i32* @d, align 4 +; CHECK: ret i32 %[[load]] +} -- 2.40.0