| Issue |
233912
|
| Summary |
[Attributor] Privatizing a byval argument drops the padding bytes of the byval copy
|
| Labels |
miscompilation,
llvm::Attributor,
generated by fuzzer
|
| Assignees |
|
| Reporter |
ChoKyuWon
|
### reproducer
godbolt: https://godbolt.org/z/e94a5G8xT
alive: https://alive2.llvm.org/ce/z/9U6yjJ
```llvm
%S = type { i32, i8 }
define internal i64 @callee(ptr byval(%S) %p) {
%v = load i64, ptr %p, align 4
ret i64 %v
}
define i64 @f() {
%p = alloca %S, align 4
store i64 -1, ptr %p, align 4
%r = call i64 @callee(ptr byval(%S) %p)
ret i64 %r
}
```
```console
$ opt -passes=attributor -S repro.ll
define internal i64 @callee(i32 %0, i8 %1) #0 {
%p.priv = alloca %S, align 8
store i32 %0, ptr %p.priv, align 4
%p.priv.b4 = getelementptr i8, ptr %p.priv, i64 4
store i8 %1, ptr %p.priv.b4, align 1
%v = load i64, ptr %p.priv, align 4, !invariant.load !0
ret i64 %v
}
$ opt -passes=attributor,inline,sroa,instcombine -S repro.ll | grep -A1 'define i64 @f'
define i64 @f() #0 {
ret i64 1099511627775
$ opt -passes=inline,sroa,instcombine -S repro.ll | grep -A1 'define i64 @f'
define i64 @f() {
ret i64 -1
# alive link: @src = "" after -passes=inline, @tgt = @f after -passes=attributor,inline
$ alive-tv --disable-undef-input --disable-poison-input src-tgt.ll
ERROR: Target is more poisonous than source
Source value: #xffffffffffffffff (18446744073709551615, -1)
Target value: poison
```
### suggested fix
LangRef defines the byval copy as a memcpy of the type's allocation size, so padding bytes are part of it. `AAPrivatizablePtrArgument::updateImpl` skips its `isDenselyPacked` padding check (tightened for tail padding in #231558) for byval arguments, and `createInitialization` stores only the fields.
Apply the padding check to byval arguments too, or copy the full allocation size.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs