https://bugs.llvm.org/show_bug.cgi?id=49913

            Bug ID: 49913
           Summary: [coroutines] errno address is reused after context
                    switch
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++2a
          Assignee: unassignedclangb...@nondot.org
          Reporter: antosh...@gmail.com
                CC: blitzrak...@gmail.com, erik.pilking...@gmail.com,
                    llvm-bugs@lists.llvm.org, richard-l...@metafoo.co.uk

Created attachment 24742
  --> https://bugs.llvm.org/attachment.cgi?id=24742&action=edit
Full example

Consider the example:

CoroTask CoroToDealWith() {
    if (errno) first_call();
    co_await writerQueue;
    if (errno) second_call();
}

With `-O2 -std=c++20 -stdlib=libc++` flags clang generates code that stores the
`errno` address on first call:

  call __errno_location
  mov qword ptr [rbx + 24], rax
  cmp dword ptr [rax], 0
  je .LBB1_2
  call first_call()

and reuses that address after wakeup:

CoroToDealWith() [clone .resume]: # @CoroToDealWith() [clone .resume]
  push rbx
  mov rbx, rdi
  mov rax, qword ptr [rdi + 24]
  cmp dword ptr [rax], 0
  je .LBB2_2
  call second_call()


The optimization is wrong: coroutine could be resumed on other thread and the
errno address changes.

Godbolt playground: https://godbolt.org/z/Wh9xd9oME

Looks like the common subexpression elimination pass must not be applied
between the context switches for the functions with __attribute__((const))

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to