Skip to content
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

[TSan] Invalid IR generated for atomicrmw with pointers #85226

Closed
nikic opened this issue Mar 14, 2024 · 2 comments · Fixed by #85228
Closed

[TSan] Invalid IR generated for atomicrmw with pointers #85226

nikic opened this issue Mar 14, 2024 · 2 comments · Fixed by #85228
Assignees

Comments

@nikic
Copy link
Contributor

nikic commented Mar 14, 2024

https://llvm.godbolt.org/z/o3nej9cKj

; RUN: opt -S -passes=tsan
define void @atomic8_xchg_monotonic_ptr(ptr %a, ptr %b) {
entry:
  atomicrmw xchg ptr %a, ptr %b monotonic
  ret void
}

This produces:

define void @atomic8_xchg_monotonic_ptr(ptr %a, ptr %b) {
entry:
  %0 = call ptr @llvm.returnaddress(i32 0)
  call void @__tsan_func_entry(ptr %0)
  %1 = zext ptr %b to i64
  %2 = call i64 @__tsan_atomic64_exchange(ptr %a, i64 %1, i32 0)
  call void @__tsan_func_exit()
  ret void
}
@nikic nikic added the compiler-rt:tsan Thread sanitizer label Mar 14, 2024
@nikic nikic self-assigned this Mar 14, 2024
@nikic nikic added this to the LLVM 18.X Release milestone Mar 14, 2024
@github-project-automation github-project-automation bot moved this to Needs Triage in LLVM Release Status Mar 14, 2024
nikic added a commit that referenced this issue Mar 15, 2024
atomicrmw xchg also accepts pointer and floating-point values. To handle
those, insert necessary casts to and from integer. This is what we do
for cmpxchg as well.

Fixes #85226.
@github-project-automation github-project-automation bot moved this from Needs Triage to Done in LLVM Release Status Mar 15, 2024
@nikic
Copy link
Contributor Author

nikic commented Mar 15, 2024

/cherry-pick ff2fb2a

llvmbot pushed a commit to llvmbot/llvm-project that referenced this issue Mar 15, 2024
atomicrmw xchg also accepts pointer and floating-point values. To handle
those, insert necessary casts to and from integer. This is what we do
for cmpxchg as well.

Fixes llvm#85226.

(cherry picked from commit ff2fb2a)
@llvmbot
Copy link
Member

llvmbot commented Mar 15, 2024

/pull-request #85371

tstellar pushed a commit to llvmbot/llvm-project that referenced this issue Mar 19, 2024
atomicrmw xchg also accepts pointer and floating-point values. To handle
those, insert necessary casts to and from integer. This is what we do
for cmpxchg as well.

Fixes llvm#85226.

(cherry picked from commit ff2fb2a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging a pull request may close this issue.

3 participants