<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 - Miscompile with inalloca/exception/inlining"
href="https://bugs.llvm.org/show_bug.cgi?id=46386">46386</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Miscompile with inalloca/exception/inlining
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>aeubanks@google.com
</td>
</tr>
<tr>
<th>CC</th>
<td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Brought up in <a href="https://reviews.llvm.org/D80951">https://reviews.llvm.org/D80951</a>.
```
#include <cstdio>
struct A {
__attribute((optnone)) A(int) noexcept { z[1] = 10; }
__attribute((optnone)) A() {
z[1] = 5;
throw 1;
}
__attribute((optnone)) ~A() { printf("%d %p\n", z[1], this); }
int z[10000];
};
__attribute((optnone)) void foo(int z, A a) noexcept {}
__attribute((always_inline)) static int inner() {
try {
foo(1, A());
} catch (...) {
}
return 3;
}
void bar() {
for (int i = 0; i < 10; ++i) {
foo(inner(), A(1));
}
}
int main() { bar(); }
```
seems to be miscompiled on Win32. It should print "10 XXXXXXXX" where XXXXXXXX
is constant (no stack leak).
But instead of "10" it prints a random (but consistent within a run) value.
LLVM IR:
```
; Function Attrs: noinline optnone
define dso_local void @"?bar@@YAXXZ"() #1 personality i8* bitcast (i32 (...)*
@__CxxFrameHandler3 to i8*) {
entry:
%i = alloca i32, align 4
store i32 0, i32* %i, align 4
br label %for.cond
for.cond: ; preds = %for.inc, %entry
%0 = load i32, i32* %i, align 4
%cmp = icmp slt i32 %0, 10
br i1 %cmp, label %for.body, label %for.end
for.body: ; preds = %for.cond
%inalloca.save = call i8* @llvm.stacksave()
%argmem = alloca inalloca <{ i32, %struct.A }>, align 4
%1 = getelementptr inbounds <{ i32, %struct.A }>, <{ i32, %struct.A }>*
%argmem, i32 0, i32 1
%call = call x86_thiscallcc %struct.A* @"??0A@@QAE@H@Z"(%struct.A* %1, i32 1)
#2
%inalloca.save.i = call i8* @llvm.stacksave()
%argmem.i = alloca inalloca <{ i32, %struct.A }>, align 4
%2 = getelementptr inbounds <{ i32, %struct.A }>, <{ i32, %struct.A }>*
%argmem.i, i32 0, i32 1
%call.i = invoke x86_thiscallcc %struct.A* @"??0A@@QAE@XZ"(%struct.A* %2)
to label %invoke.cont.i unwind label %catch.dispatch.i
catch.dispatch.i: ; preds = %for.body
%3 = catchswitch within none [label %catch.i] unwind label %ehcleanup
catch.i: ; preds = %catch.dispatch.i
%4 = catchpad within %3 [i8* null, i32 64, i8* null]
catchret from %4 to label %catchret.dest.i
catchret.dest.i: ; preds = %catch.i
br label %"?inner@@YAHXZ.exit"
invoke.cont.i: ; preds = %for.body
%5 = getelementptr inbounds <{ i32, %struct.A }>, <{ i32, %struct.A }>*
%argmem.i, i32 0, i32 0
store i32 1, i32* %5, align 4
call void @"?foo@@YAXHUA@@@Z"(<{ i32, %struct.A }>* inalloca %argmem.i) #2
call void @llvm.stackrestore(i8* %inalloca.save.i)
br label %"?inner@@YAHXZ.exit"
"?inner@@YAHXZ.exit": ; preds = %catchret.dest.i,
%invoke.cont.i
br label %invoke.cont
invoke.cont: ; preds =
%"?inner@@YAHXZ.exit"
%6 = getelementptr inbounds <{ i32, %struct.A }>, <{ i32, %struct.A }>*
%argmem, i32 0, i32 0
store i32 3, i32* %6, align 4
call void @"?foo@@YAXHUA@@@Z"(<{ i32, %struct.A }>* inalloca %argmem) #2
call void @llvm.stackrestore(i8* %inalloca.save)
br label %for.inc
for.inc: ; preds = %invoke.cont
%7 = load i32, i32* %i, align 4
%inc = add nsw i32 %7, 1
store i32 %inc, i32* %i, align 4
br label %for.cond
ehcleanup: ; preds = %catch.dispatch.i
%8 = cleanuppad within none []
call x86_thiscallcc void @"??1A@@QAE@XZ"(%struct.A* %1) #2 [ "funclet"(token
%8) ]
cleanupret from %8 unwind to caller
for.end: ; preds = %for.cond
ret void
}
```
Moving the `@llvm.stackrestore` in `invoke.cont.i` to instead be in
`catchret.dest.i` seems to fix this issue.</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>