Skip to content

Write to readonly byval argument is not considered UB #930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
erikdesjardins opened this issue Aug 9, 2023 · 0 comments
Closed

Write to readonly byval argument is not considered UB #930

erikdesjardins opened this issue Aug 9, 2023 · 0 comments
Labels
memory Memory Model

Comments

@erikdesjardins
Copy link

Demo: https://alive2.llvm.org/ce/z/L6zCAg

define void @src(ptr readonly byval(i8) %p) {
  store i8 0, ptr %p
  ret void
}

define void @tgt(ptr readonly byval(i8) %p) {
  unreachable
}

Transformation doesn't verify!

ERROR: Source is more defined than target

This behavior makes some sense, since byval means the argument is copied, so callers can't see any writes.

But, LangRef implies that this is illegal:

The copy is considered to belong to the caller not the callee (for example, readonly functions should not write to byval parameters).

And optimizations do treat it as UB in practice. llvm/llvm-project#64289 is an end-to-end miscompile caused by tailcallelim introducing a write to a readonly byval argument.

@nunoplopes nunoplopes added the memory Memory Model label Aug 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
memory Memory Model
Projects
None yet
Development

No branches or pull requests

2 participants