[PATCH] D137707: Move "auto-init" instructions to the dominator of their users
Hans Wennborg via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 12 03:56:19 PDT 2023
hans added a comment.
In D137707#4259567 <https://reviews.llvm.org/D137707#4259567>, @ayzhao wrote:
> I now have a reproducible (but non-reduced) testcase: https://crbug.com/1431366#c5
>
> This looks like a miscompile; the return parameter is not being initialized if we don't take the branch.
Here's a small repro based on that:
$ cat /tmp/a.cc
struct S {
unsigned long long x;
};
S g();
S f(int a) {
S ret;
if (a == 42)
ret = g();
return ret;
}
$ build/bin/clang.bad -target i686-linux-gnu -c -ftrivial-auto-var-init=pattern -O2 /tmp/a.cc -S -emit-llvm -o -
[...]
define dso_local void @_Z1fi(ptr noalias nocapture writeonly sret(%struct.S) align 4 %agg.result, i32 noundef %a) local_unnamed_addr #0 {
entry:
%ref.tmp = alloca %struct.S, align 8
%cmp = icmp eq i32 %a, 42
br i1 %cmp, label %if.then, label %if.end
if.then: ; preds = %entry
store i64 -1, ptr %agg.result, align 4, !annotation !6 <------ This used to be in the %entry block.
call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %ref.tmp) #3
call void @_Z1gv(ptr nonnull sret(%struct.S) align 4 %ref.tmp)
%0 = load i64, ptr %ref.tmp, align 8, !tbaa !7
store i64 %0, ptr %agg.result, align 4, !tbaa !7
call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %ref.tmp) #3
br label %if.end
if.end: ; preds = %if.then, %entry
ret void
}
This patch moved the `store i64 -1, ptr %agg.result` instruction from the `%entry` block to `%if.then`, meaning the return value doesn't always get initialized.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D137707/new/
https://reviews.llvm.org/D137707
More information about the llvm-commits
mailing list