Skip to content

[Clang] FE assertion failure in CGCoroutine: "expected alloca to be emitted" #148953

@yuxuanchen1997

Description

@yuxuanchen1997

Minimum Repro:

#include <coroutine>

struct Task {
    struct promise_type {
        Task get_return_object();
        
        std::suspend_always initial_suspend() { return {}; }
        std::suspend_always final_suspend() noexcept { return {}; }
        
        void return_void() {}
        void unhandled_exception() {}
    };
    
    Task() {}
    Task(const Task&) {};
};

// Example usage
const Task example() {
    co_return;
}

Compiler Explorer: https://godbolt.org/z/9W6vEvvz4

Assertion failure here:

assert(GroAlloca && "expected alloca to be emitted");

This is due to that in example()'s return type is const qualified and therefore didn't pass this check for DirectEmit, and that it's NRVO optimized. Emission of NRVO optimized variables don't have their Pointer be an AllocaInst.

The fix is either don't compare Qualified Types in DirectEmit or just don't attach the metadata when the return value is NRVO optimized.

Metadata

Metadata

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions