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

            Bug ID: 47767
           Summary: [coroutines] ASan reports stack-use-after-scope when
                    coroutine allocation is elided
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++2a
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected]

This happens when the coroutine frame allocation is elided and the promise
constructor is not inlined. See: https://godbolt.org/z/8EzP7a

// -std=c++20 -stdlib=libc++ -O3 -g -fcoroutines-ts -fsanitize=address
-fsanitize-address-use-after-scope


#include <experimental/coroutine>

#define inline_never __attribute__((noinline)) 
#define inline_always inline __attribute__((always_inline))

template <typename T>
class co;

using suspend_never = std::experimental::suspend_never;

template <typename T>
class promise;

template <>
struct promise <void> 
{
    int member = 0;
    inline_never promise() 
    {
    }

    ~promise() 
    {
    }

    co<void> get_return_object() noexcept;

    void return_void() noexcept 
    {
    };

    suspend_never initial_suspend() noexcept 
    {
        return {};
    }

    void unhandled_exception() noexcept 
    {
    }

    suspend_never final_suspend() noexcept 
    {
        return {};
    }
};

template <typename T = void>
struct co 
{
    using promise_type = promise<T>;
    ~co() 
    {
    }
};

inline_always co<void> promise<void>::get_return_object() noexcept {
    return co<void>();
}

inline_never co<> bar() {
    co_return;
}

int main() {
    bar();
    return 0;
}

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

Reply via email to