[llvm-bugs] [Bug 47767] New: [coroutines] ASan reports stack-use-after-scope when coroutine allocation is elided

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Oct 8 07:53:40 PDT 2020


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: unassignedclangbugs at nondot.org
          Reporter: erik at olofsson.info
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20201008/fdd7759c/attachment.html>


More information about the llvm-bugs mailing list