<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - [globalopt] optimization leaves store to a constant global"
href="https://bugs.llvm.org/show_bug.cgi?id=43616">43616</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[globalopt] optimization leaves store to a constant global
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Interprocedural Optimizations
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>juneyoung.lee@sf.snu.ac.kr
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=22643" name="attach_22643" title="input">attachment 22643</a> <a href="attachment.cgi?id=22643&action=edit" title="input">[details]</a></span>
input
```
$ opt -version
LLVM (<a href="http://llvm.org/">http://llvm.org/</a>):
LLVM version 10.0.0svn
Optimized build with assertions.
Default target: x86_64-apple-darwin19.0.0
Host CPU: skylake
$ cat input.ll
declare {}* @llvm.invariant.start.p0i8(i64 %size, i8* nocapture %ptr)
define void @test1(i8* %ptr) {
call {}* @llvm.invariant.start.p0i8(i64 4, i8* %ptr)
ret void
}
@object1 = global i32 0
define void @ctor1() {
store i32 -1, i32* @object1
%A = bitcast i32* @object1 to i8*
call void @test1(i8* %A)
ret void
}
@llvm.global_ctors = appending constant
[1 x { i32, void ()*, i8* }]
[ { i32, void ()*, i8* } { i32 65535, void ()* @ctor1, i8* null } ]
$ opt -globalopt -S -o - input.ll
@object1 = constant i32 -1
@llvm.global_ctors = appending constant [0 x { i32, void ()*, i8* }]
zeroinitializer
; Function Attrs: argmemonly nounwind willreturn
declare {}* @llvm.invariant.start.p0i8(i64 immarg, i8* nocapture) #0
define void @test1(i8* %ptr) local_unnamed_addr {
%1 = call {}* @llvm.invariant.start.p0i8(i64 4, i8* %ptr)
ret void
}
define void @ctor1() local_unnamed_addr {
store i32 -1, i32* @object1
%A = bitcast i32* @object1 to i8*
call void @test1(i8* %A)
ret void
}
attributes #0 = { argmemonly nounwind willreturn }
```
Running -globalopt leaves a store to @object1, which is a constant global,
which may cause crash because LangRef states that it can be placed in the
read-only section of an executable.
LangRef says:
A variable may be defined as a global constant, which indicates that the
contents of the variable will never be modified (enabling better optimization,
allowing the global data to be placed in the read-only section of an
executable, etc).</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>