From 0c39d40c8b1e3ef028b4082593896e24633a66d7 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Sat, 16 Aug 2014 01:54:32 +0000 Subject: IR: Don't add inbounds to GEPs of extern_weak variables Global variables that have `extern_weak` linkage may be null, so it's incorrect to add `inbounds` when constant folding. This also fixes a bug when parsing global aliases, whose forward reference placeholders are global variables with `extern_weak` linkage. If GEPs to these aliases are encountered before the alias itself, the GEPs would incorrectly gain the `inbounds` keyword as well. llvm-svn: 215803 --- llvm/test/Assembler/ConstantExprNoFold.ll | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'llvm/test') diff --git a/llvm/test/Assembler/ConstantExprNoFold.ll b/llvm/test/Assembler/ConstantExprNoFold.ll index d21441372bf..04ad3f5b130 100644 --- a/llvm/test/Assembler/ConstantExprNoFold.ll +++ b/llvm/test/Assembler/ConstantExprNoFold.ll @@ -25,3 +25,15 @@ target datalayout = "p:32:32" ; CHECK: @E = global i64 addrspace(1)* addrspacecast (i64* @A to i64 addrspace(1)*) @E = global i64 addrspace(1)* addrspacecast(i64* @A to i64 addrspace(1)*) + +; Don't add an inbounds on @weak.gep, since @weak may be null. +; CHECK: @weak.gep = global i32* getelementptr (i32* @weak, i32 1) +@weak.gep = global i32* getelementptr (i32* @weak, i32 1) +@weak = extern_weak global i32 + +; Don't add an inbounds on @glob.a3, since it's not inbounds. +; CHECK: @glob.a3 = alias getelementptr (i32* @glob.a2, i32 1) +@glob = global i32 0 +@glob.a3 = alias getelementptr (i32* @glob.a2, i32 1) +@glob.a2 = alias getelementptr (i32* @glob.a1, i32 1) +@glob.a1 = alias i32* @glob -- cgit v1.2.3