llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.15k stars 12.03k forks source link

clang 17 ICE: Assertion `T != LastT && "Type unwrapping failed to unwrap!"' failed. #73865

Open tycho opened 11 months ago

tycho commented 11 months ago

Originally found on Windows with clang-cl 17.0.6, but I suspect this is still related to my original issue. Here's a repro on Godbolt: https://gcc.godbolt.org/z/n1KGbnEGs

It only happens at -g2 or higher:

clang++: /root/llvm-project/clang/lib/CodeGen/CGDebugInfo.cpp:3470: clang::QualType UnwrapTypeForDebugInfo(clang::QualType, const clang::ASTContext&): Assertion `T != LastT && "Type unwrapping failed to unwrap!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.  Program arguments: /opt/compiler-explorer/clang-assertions-17.0.1/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-13.2.0 -fcolor-diagnostics -fno-crash-diagnostics -std=c++20 -g2 <source>
1.  <eof> parser at end of file
2.  <source>:194:11: LLVM IR generation of declaration 'g_class'
3.  <source>:194:11: Generating code for declaration 'g_class'
 #0 0x00000000036e7558 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x36e7558)
 #1 0x00000000036e53dc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x36e53dc)
 #2 0x0000000003632918 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007fcaf5e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007fcaf5e969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007fcaf5e42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007fcaf5e287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00007fcaf5e2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x00007fcaf5e39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x000000000395d890 UnwrapTypeForDebugInfo(clang::QualType, clang::ASTContext const&) CGDebugInfo.cpp:0:0
#10 0x00000000039aaa45 clang::CodeGen::CGDebugInfo::getOrCreateType(clang::QualType, llvm::DIFile*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39aaa45)
#11 0x00000000039b4dd4 clang::CodeGen::CGDebugInfo::CreateRecordStaticField(clang::VarDecl const*, llvm::DIType*, clang::RecordDecl const*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39b4dd4)
#12 0x00000000039b69e9 clang::CodeGen::CGDebugInfo::CollectRecordFields(clang::RecordDecl const*, llvm::DIFile*, llvm::SmallVectorImpl<llvm::Metadata*>&, llvm::DICompositeType*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39b69e9)
#13 0x00000000039aa0ac clang::CodeGen::CGDebugInfo::CreateTypeDefinition(clang::RecordType const*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39aa0ac)
#14 0x00000000039aa71b clang::CodeGen::CGDebugInfo::CreateType(clang::RecordType const*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39aa71b)
#15 0x00000000039aa821 clang::CodeGen::CGDebugInfo::CreateTypeNode(clang::QualType, llvm::DIFile*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39aa821)
#16 0x00000000039aaa97 clang::CodeGen::CGDebugInfo::getOrCreateType(clang::QualType, llvm::DIFile*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39aaa97)
#17 0x00000000039bda7b clang::CodeGen::CGDebugInfo::CreateType(clang::TypedefType const*, llvm::DIFile*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39bda7b)
#18 0x00000000039aa82f clang::CodeGen::CGDebugInfo::CreateTypeNode(clang::QualType, llvm::DIFile*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39aa82f)
#19 0x00000000039aaa97 clang::CodeGen::CGDebugInfo::getOrCreateType(clang::QualType, llvm::DIFile*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39aaa97)
#20 0x00000000039b55b9 clang::CodeGen::CGDebugInfo::createFieldType(llvm::StringRef, clang::QualType, clang::SourceLocation, clang::AccessSpecifier, unsigned long, unsigned int, llvm::DIFile*, llvm::DIScope*, clang::RecordDecl const*, llvm::MDTupleTypedArrayWrapper<llvm::DINode>) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39b55b9)
#21 0x00000000039b654c clang::CodeGen::CGDebugInfo::CollectRecordNormalField(clang::FieldDecl const*, unsigned long, llvm::DIFile*, llvm::SmallVectorImpl<llvm::Metadata*>&, llvm::DIType*, clang::RecordDecl const*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39b654c)
#22 0x00000000039b692c clang::CodeGen::CGDebugInfo::CollectRecordFields(clang::RecordDecl const*, llvm::DIFile*, llvm::SmallVectorImpl<llvm::Metadata*>&, llvm::DICompositeType*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39b692c)
#23 0x00000000039aa0ac clang::CodeGen::CGDebugInfo::CreateTypeDefinition(clang::RecordType const*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39aa0ac)
#24 0x00000000039aa71b clang::CodeGen::CGDebugInfo::CreateType(clang::RecordType const*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39aa71b)
#25 0x00000000039aa821 clang::CodeGen::CGDebugInfo::CreateTypeNode(clang::QualType, llvm::DIFile*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39aa821)
#26 0x00000000039aaa97 clang::CodeGen::CGDebugInfo::getOrCreateType(clang::QualType, llvm::DIFile*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39aaa97)
#27 0x00000000039bc765 clang::CodeGen::CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable*, clang::VarDecl const*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39bc765)
#28 0x0000000003ab0b58 clang::CodeGen::CodeGenModule::EmitGlobalVarDefinition(clang::VarDecl const*, bool) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3ab0b58)
#29 0x0000000003ad2831 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3ad2831)
#30 0x0000000003ad2e8b clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3ad2e8b)
#31 0x0000000003adc05b clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#32 0x000000000493c1e6 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#33 0x000000000492e988 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x492e988)
#34 0x0000000005deb754 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x5deb754)
#35 0x0000000004939258 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x4939258)
#36 0x00000000041a1c09 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x41a1c09)
#37 0x00000000041278ce clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x41278ce)
#38 0x0000000004281de6 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x4281de6)
#39 0x0000000000bc67eb cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0xbc67eb)
#40 0x0000000000bbefaa ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#41 0x0000000003f83419 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#42 0x0000000003632dc4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3632dc4)
#43 0x0000000003f83a0f clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#44 0x0000000003f4b275 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3f4b275)
#45 0x0000000003f4bcdd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3f4bcdd)
#46 0x0000000003f5385d clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3f5385d)
#47 0x0000000000bc4a87 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0xbc4a87)
#48 0x0000000000abef61 main (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0xabef61)
#49 0x00007fcaf5e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#50 0x00007fcaf5e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#51 0x0000000000bbea8e _start (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0xbbea8e)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134

Here's the repro, though I don't have creduce/cvise up and running right now so it's a little too verbose:

#include <cstdint>
#include <vector>
#include <optional>
#include <map>

typedef unsigned int GLuint;
typedef int GLsizei;

#define UNREACHABLE __builtin_unreachable()
#define NOINLINE __attribute__((noinline))
#define unlikely(x) (x) [[unlikely]]
#define likely(x) (x) [[likely]]

extern void glBindVertexArray(GLuint array);
extern void glGenVertexArrays(GLsizei n, GLuint * arrays);

enum class GLNameType {
    Buffer,
    FrameBuffer,
    Query,
    RenderBuffer,
    Sampler,
    Texture,
    VertexArray,
    NumNameTypes
};

template class std::map<uint32_t, GLuint>;

// A strong wrapper for GLuint names, to avoid accidentally using the wrong
// name somewhere.
template <GLNameType T, class U>
class StrongResourceIDBase
{
public:
    typedef U value_type;

protected:
    value_type m_id;

public:
    constexpr StrongResourceIDBase()
    {
        m_id = 0;
    }

    explicit StrongResourceIDBase(value_type _id)
    {
        m_id = _id;
    }

    StrongResourceIDBase(StrongResourceIDBase<T, U> const &_other)
        : m_id(_other.m_id)
    {
    }

    StrongResourceIDBase &operator=(StrongResourceIDBase const &_other)
    {
        m_id = _other.m_id;
        return *this;
    }

    U value() const
    {
        return m_id;
    }

    bool valid() const
    {
        return m_id != 0;
    }

    void reset()
    {
        m_id = 0;
    }

    bool operator==(StrongResourceIDBase const &_other) const
    {
        return m_id = _other.m_id;
    }

    bool operator!=(StrongResourceIDBase const &_other) const
    {
        return !(*this == _other);
    }
};

template <GLNameType T>
class GLResourceName final : public StrongResourceIDBase<T, GLuint>
{
public:
    typedef GLResourceName<T> this_type;
    typedef StrongResourceIDBase<T, GLuint> base_type;
    typedef base_type::value_type value_type;

public:
    static void gl_create(GLsizei numNames, value_type *names)
    {
        if constexpr (T == GLNameType::VertexArray)
            glGenVertexArrays(numNames, names);
        else
            UNREACHABLE;
    }

    constexpr GLResourceName()
        : base_type()
    {
    }

    explicit GLResourceName(value_type _id)
        : base_type(_id)
    {
    }

    [[nodiscard]] static this_type create()
    {
        this_type newId;
        gl_create(1, &newId.m_id);
        return newId;
    }

    operator value_type() const
    {
        return this->m_id;
    }
};

template <GLNameType T>
class GLResourceRef final : public StrongResourceIDBase<T, uint32_t>
{
    friend class Resource;

public:
    typedef StrongResourceIDBase<T, uint32_t> base_type;
    typedef GLResourceRef<T> this_type;
    typedef GLResourceName<T> name_type;

    typedef base_type::value_type value_type;
    typedef name_type::base_type::value_type name_value_type;

private:
    static uint32_t s_lastIdx;
    static std::map<value_type, name_value_type> s_resourceNames;

protected:
    static NOINLINE void create(this_type &_idx, name_type &_name)
    {
        _idx = this_type(++s_lastIdx);
        _name = name_type::create();
        s_resourceNames.emplace(_idx.value(), _name.value());
    }

public:
    constexpr GLResourceRef()
        : base_type()
    {
    }

    explicit GLResourceRef(value_type _id)
        : base_type(_id)
    {
    }

    // Returns true if a new object had to be created
    // Returns false if an exissting object was returned
    [[nodiscard]] bool create(name_type &_name)
    {
        create(*this, _name);
        return true;
    }
};

typedef GLResourceName<GLNameType::VertexArray> GLVertexArrayName;
typedef GLResourceRef<GLNameType::VertexArray> GLVertexArrayID;

class TestRepro
{
public:
    GLVertexArrayID m_vao;

    GLVertexArrayName EmptyVAO()
    {
        GLVertexArrayName name;
        if (m_vao.create(name)) {
            glBindVertexArray(name);
            glBindVertexArray(0);
        }
        return name;
    }
};

TestRepro g_class;
llvmbot commented 11 months ago

@llvm/issue-subscribers-debuginfo

Author: Steven Noonan (tycho)

Originally found on Windows with clang-cl 17.0.6, but I suspect this is still related to my original issue. Here's a repro on Godbolt: https://gcc.godbolt.org/z/n1KGbnEGs It only happens at -g2 or higher: ``` clang++: /root/llvm-project/clang/lib/CodeGen/CGDebugInfo.cpp:3470: clang::QualType UnwrapTypeForDebugInfo(clang::QualType, const clang::ASTContext&): Assertion `T != LastT && "Type unwrapping failed to unwrap!"' failed. PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script. Stack dump: 0. Program arguments: /opt/compiler-explorer/clang-assertions-17.0.1/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-13.2.0 -fcolor-diagnostics -fno-crash-diagnostics -std=c++20 -g2 <source> 1. <eof> parser at end of file 2. <source>:194:11: LLVM IR generation of declaration 'g_class' 3. <source>:194:11: Generating code for declaration 'g_class' #0 0x00000000036e7558 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x36e7558) #1 0x00000000036e53dc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x36e53dc) #2 0x0000000003632918 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0 #3 0x00007fcaf5e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520) #4 0x00007fcaf5e969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc) #5 0x00007fcaf5e42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476) #6 0x00007fcaf5e287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3) #7 0x00007fcaf5e2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b) #8 0x00007fcaf5e39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96) #9 0x000000000395d890 UnwrapTypeForDebugInfo(clang::QualType, clang::ASTContext const&) CGDebugInfo.cpp:0:0 #10 0x00000000039aaa45 clang::CodeGen::CGDebugInfo::getOrCreateType(clang::QualType, llvm::DIFile*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39aaa45) #11 0x00000000039b4dd4 clang::CodeGen::CGDebugInfo::CreateRecordStaticField(clang::VarDecl const*, llvm::DIType*, clang::RecordDecl const*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39b4dd4) #12 0x00000000039b69e9 clang::CodeGen::CGDebugInfo::CollectRecordFields(clang::RecordDecl const*, llvm::DIFile*, llvm::SmallVectorImpl<llvm::Metadata*>&, llvm::DICompositeType*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39b69e9) #13 0x00000000039aa0ac clang::CodeGen::CGDebugInfo::CreateTypeDefinition(clang::RecordType const*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39aa0ac) #14 0x00000000039aa71b clang::CodeGen::CGDebugInfo::CreateType(clang::RecordType const*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39aa71b) #15 0x00000000039aa821 clang::CodeGen::CGDebugInfo::CreateTypeNode(clang::QualType, llvm::DIFile*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39aa821) #16 0x00000000039aaa97 clang::CodeGen::CGDebugInfo::getOrCreateType(clang::QualType, llvm::DIFile*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39aaa97) #17 0x00000000039bda7b clang::CodeGen::CGDebugInfo::CreateType(clang::TypedefType const*, llvm::DIFile*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39bda7b) #18 0x00000000039aa82f clang::CodeGen::CGDebugInfo::CreateTypeNode(clang::QualType, llvm::DIFile*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39aa82f) #19 0x00000000039aaa97 clang::CodeGen::CGDebugInfo::getOrCreateType(clang::QualType, llvm::DIFile*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39aaa97) #20 0x00000000039b55b9 clang::CodeGen::CGDebugInfo::createFieldType(llvm::StringRef, clang::QualType, clang::SourceLocation, clang::AccessSpecifier, unsigned long, unsigned int, llvm::DIFile*, llvm::DIScope*, clang::RecordDecl const*, llvm::MDTupleTypedArrayWrapper<llvm::DINode>) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39b55b9) #21 0x00000000039b654c clang::CodeGen::CGDebugInfo::CollectRecordNormalField(clang::FieldDecl const*, unsigned long, llvm::DIFile*, llvm::SmallVectorImpl<llvm::Metadata*>&, llvm::DIType*, clang::RecordDecl const*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39b654c) #22 0x00000000039b692c clang::CodeGen::CGDebugInfo::CollectRecordFields(clang::RecordDecl const*, llvm::DIFile*, llvm::SmallVectorImpl<llvm::Metadata*>&, llvm::DICompositeType*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39b692c) #23 0x00000000039aa0ac clang::CodeGen::CGDebugInfo::CreateTypeDefinition(clang::RecordType const*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39aa0ac) #24 0x00000000039aa71b clang::CodeGen::CGDebugInfo::CreateType(clang::RecordType const*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39aa71b) #25 0x00000000039aa821 clang::CodeGen::CGDebugInfo::CreateTypeNode(clang::QualType, llvm::DIFile*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39aa821) #26 0x00000000039aaa97 clang::CodeGen::CGDebugInfo::getOrCreateType(clang::QualType, llvm::DIFile*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39aaa97) #27 0x00000000039bc765 clang::CodeGen::CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable*, clang::VarDecl const*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39bc765) #28 0x0000000003ab0b58 clang::CodeGen::CodeGenModule::EmitGlobalVarDefinition(clang::VarDecl const*, bool) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3ab0b58) #29 0x0000000003ad2831 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3ad2831) #30 0x0000000003ad2e8b clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3ad2e8b) #31 0x0000000003adc05b clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0 #32 0x000000000493c1e6 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0 #33 0x000000000492e988 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x492e988) #34 0x0000000005deb754 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x5deb754) #35 0x0000000004939258 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x4939258) #36 0x00000000041a1c09 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x41a1c09) #37 0x00000000041278ce clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x41278ce) #38 0x0000000004281de6 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x4281de6) #39 0x0000000000bc67eb cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0xbc67eb) #40 0x0000000000bbefaa ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0 #41 0x0000000003f83419 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0 #42 0x0000000003632dc4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3632dc4) #43 0x0000000003f83a0f clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0 #44 0x0000000003f4b275 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3f4b275) #45 0x0000000003f4bcdd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3f4bcdd) #46 0x0000000003f5385d clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3f5385d) #47 0x0000000000bc4a87 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0xbc4a87) #48 0x0000000000abef61 main (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0xabef61) #49 0x00007fcaf5e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90) #50 0x00007fcaf5e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40) #51 0x0000000000bbea8e _start (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0xbbea8e) clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation) Compiler returned: 134 ``` Here's the repro, though I don't have creduce/cvise up and running right now so it's a little too verbose: ``` #include <cstdint> #include <vector> #include <optional> #include <map> typedef unsigned int GLuint; typedef int GLsizei; #define UNREACHABLE __builtin_unreachable() #define NOINLINE __attribute__((noinline)) #define unlikely(x) (x) [[unlikely]] #define likely(x) (x) [[likely]] extern void glBindVertexArray(GLuint array); extern void glGenVertexArrays(GLsizei n, GLuint * arrays); enum class GLNameType { Buffer, FrameBuffer, Query, RenderBuffer, Sampler, Texture, VertexArray, NumNameTypes }; template class std::map<uint32_t, GLuint>; // A strong wrapper for GLuint names, to avoid accidentally using the wrong // name somewhere. template <GLNameType T, class U> class StrongResourceIDBase { public: typedef U value_type; protected: value_type m_id; public: constexpr StrongResourceIDBase() { m_id = 0; } explicit StrongResourceIDBase(value_type _id) { m_id = _id; } StrongResourceIDBase(StrongResourceIDBase<T, U> const &_other) : m_id(_other.m_id) { } StrongResourceIDBase &operator=(StrongResourceIDBase const &_other) { m_id = _other.m_id; return *this; } U value() const { return m_id; } bool valid() const { return m_id != 0; } void reset() { m_id = 0; } bool operator==(StrongResourceIDBase const &_other) const { return m_id = _other.m_id; } bool operator!=(StrongResourceIDBase const &_other) const { return !(*this == _other); } }; template <GLNameType T> class GLResourceName final : public StrongResourceIDBase<T, GLuint> { public: typedef GLResourceName<T> this_type; typedef StrongResourceIDBase<T, GLuint> base_type; typedef base_type::value_type value_type; public: static void gl_create(GLsizei numNames, value_type *names) { if constexpr (T == GLNameType::VertexArray) glGenVertexArrays(numNames, names); else UNREACHABLE; } constexpr GLResourceName() : base_type() { } explicit GLResourceName(value_type _id) : base_type(_id) { } [[nodiscard]] static this_type create() { this_type newId; gl_create(1, &newId.m_id); return newId; } operator value_type() const { return this->m_id; } }; template <GLNameType T> class GLResourceRef final : public StrongResourceIDBase<T, uint32_t> { friend class Resource; public: typedef StrongResourceIDBase<T, uint32_t> base_type; typedef GLResourceRef<T> this_type; typedef GLResourceName<T> name_type; typedef base_type::value_type value_type; typedef name_type::base_type::value_type name_value_type; private: static uint32_t s_lastIdx; static std::map<value_type, name_value_type> s_resourceNames; protected: static NOINLINE void create(this_type &_idx, name_type &_name) { _idx = this_type(++s_lastIdx); _name = name_type::create(); s_resourceNames.emplace(_idx.value(), _name.value()); } public: constexpr GLResourceRef() : base_type() { } explicit GLResourceRef(value_type _id) : base_type(_id) { } // Returns true if a new object had to be created // Returns false if an exissting object was returned [[nodiscard]] bool create(name_type &_name) { create(*this, _name); return true; } }; typedef GLResourceName<GLNameType::VertexArray> GLVertexArrayName; typedef GLResourceRef<GLNameType::VertexArray> GLVertexArrayID; class TestRepro { public: GLVertexArrayID m_vao; GLVertexArrayName EmptyVAO() { GLVertexArrayName name; if (m_vao.create(name)) { glBindVertexArray(name); glBindVertexArray(0); } return name; } }; TestRepro g_class; ```
llvmbot commented 11 months ago

@llvm/issue-subscribers-clang-codegen

Author: Steven Noonan (tycho)

Originally found on Windows with clang-cl 17.0.6, but I suspect this is still related to my original issue. Here's a repro on Godbolt: https://gcc.godbolt.org/z/n1KGbnEGs It only happens at -g2 or higher: ``` clang++: /root/llvm-project/clang/lib/CodeGen/CGDebugInfo.cpp:3470: clang::QualType UnwrapTypeForDebugInfo(clang::QualType, const clang::ASTContext&): Assertion `T != LastT && "Type unwrapping failed to unwrap!"' failed. PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script. Stack dump: 0. Program arguments: /opt/compiler-explorer/clang-assertions-17.0.1/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-13.2.0 -fcolor-diagnostics -fno-crash-diagnostics -std=c++20 -g2 <source> 1. <eof> parser at end of file 2. <source>:194:11: LLVM IR generation of declaration 'g_class' 3. <source>:194:11: Generating code for declaration 'g_class' #0 0x00000000036e7558 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x36e7558) #1 0x00000000036e53dc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x36e53dc) #2 0x0000000003632918 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0 #3 0x00007fcaf5e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520) #4 0x00007fcaf5e969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc) #5 0x00007fcaf5e42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476) #6 0x00007fcaf5e287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3) #7 0x00007fcaf5e2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b) #8 0x00007fcaf5e39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96) #9 0x000000000395d890 UnwrapTypeForDebugInfo(clang::QualType, clang::ASTContext const&) CGDebugInfo.cpp:0:0 #10 0x00000000039aaa45 clang::CodeGen::CGDebugInfo::getOrCreateType(clang::QualType, llvm::DIFile*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39aaa45) #11 0x00000000039b4dd4 clang::CodeGen::CGDebugInfo::CreateRecordStaticField(clang::VarDecl const*, llvm::DIType*, clang::RecordDecl const*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39b4dd4) #12 0x00000000039b69e9 clang::CodeGen::CGDebugInfo::CollectRecordFields(clang::RecordDecl const*, llvm::DIFile*, llvm::SmallVectorImpl<llvm::Metadata*>&, llvm::DICompositeType*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39b69e9) #13 0x00000000039aa0ac clang::CodeGen::CGDebugInfo::CreateTypeDefinition(clang::RecordType const*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39aa0ac) #14 0x00000000039aa71b clang::CodeGen::CGDebugInfo::CreateType(clang::RecordType const*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39aa71b) #15 0x00000000039aa821 clang::CodeGen::CGDebugInfo::CreateTypeNode(clang::QualType, llvm::DIFile*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39aa821) #16 0x00000000039aaa97 clang::CodeGen::CGDebugInfo::getOrCreateType(clang::QualType, llvm::DIFile*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39aaa97) #17 0x00000000039bda7b clang::CodeGen::CGDebugInfo::CreateType(clang::TypedefType const*, llvm::DIFile*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39bda7b) #18 0x00000000039aa82f clang::CodeGen::CGDebugInfo::CreateTypeNode(clang::QualType, llvm::DIFile*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39aa82f) #19 0x00000000039aaa97 clang::CodeGen::CGDebugInfo::getOrCreateType(clang::QualType, llvm::DIFile*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39aaa97) #20 0x00000000039b55b9 clang::CodeGen::CGDebugInfo::createFieldType(llvm::StringRef, clang::QualType, clang::SourceLocation, clang::AccessSpecifier, unsigned long, unsigned int, llvm::DIFile*, llvm::DIScope*, clang::RecordDecl const*, llvm::MDTupleTypedArrayWrapper<llvm::DINode>) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39b55b9) #21 0x00000000039b654c clang::CodeGen::CGDebugInfo::CollectRecordNormalField(clang::FieldDecl const*, unsigned long, llvm::DIFile*, llvm::SmallVectorImpl<llvm::Metadata*>&, llvm::DIType*, clang::RecordDecl const*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39b654c) #22 0x00000000039b692c clang::CodeGen::CGDebugInfo::CollectRecordFields(clang::RecordDecl const*, llvm::DIFile*, llvm::SmallVectorImpl<llvm::Metadata*>&, llvm::DICompositeType*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39b692c) #23 0x00000000039aa0ac clang::CodeGen::CGDebugInfo::CreateTypeDefinition(clang::RecordType const*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39aa0ac) #24 0x00000000039aa71b clang::CodeGen::CGDebugInfo::CreateType(clang::RecordType const*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39aa71b) #25 0x00000000039aa821 clang::CodeGen::CGDebugInfo::CreateTypeNode(clang::QualType, llvm::DIFile*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39aa821) #26 0x00000000039aaa97 clang::CodeGen::CGDebugInfo::getOrCreateType(clang::QualType, llvm::DIFile*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39aaa97) #27 0x00000000039bc765 clang::CodeGen::CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable*, clang::VarDecl const*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x39bc765) #28 0x0000000003ab0b58 clang::CodeGen::CodeGenModule::EmitGlobalVarDefinition(clang::VarDecl const*, bool) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3ab0b58) #29 0x0000000003ad2831 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3ad2831) #30 0x0000000003ad2e8b clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3ad2e8b) #31 0x0000000003adc05b clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0 #32 0x000000000493c1e6 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0 #33 0x000000000492e988 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x492e988) #34 0x0000000005deb754 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x5deb754) #35 0x0000000004939258 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x4939258) #36 0x00000000041a1c09 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x41a1c09) #37 0x00000000041278ce clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x41278ce) #38 0x0000000004281de6 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x4281de6) #39 0x0000000000bc67eb cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0xbc67eb) #40 0x0000000000bbefaa ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0 #41 0x0000000003f83419 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0 #42 0x0000000003632dc4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3632dc4) #43 0x0000000003f83a0f clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0 #44 0x0000000003f4b275 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3f4b275) #45 0x0000000003f4bcdd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3f4bcdd) #46 0x0000000003f5385d clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3f5385d) #47 0x0000000000bc4a87 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0xbc4a87) #48 0x0000000000abef61 main (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0xabef61) #49 0x00007fcaf5e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90) #50 0x00007fcaf5e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40) #51 0x0000000000bbea8e _start (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0xbbea8e) clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation) Compiler returned: 134 ``` Here's the repro, though I don't have creduce/cvise up and running right now so it's a little too verbose: ``` #include <cstdint> #include <vector> #include <optional> #include <map> typedef unsigned int GLuint; typedef int GLsizei; #define UNREACHABLE __builtin_unreachable() #define NOINLINE __attribute__((noinline)) #define unlikely(x) (x) [[unlikely]] #define likely(x) (x) [[likely]] extern void glBindVertexArray(GLuint array); extern void glGenVertexArrays(GLsizei n, GLuint * arrays); enum class GLNameType { Buffer, FrameBuffer, Query, RenderBuffer, Sampler, Texture, VertexArray, NumNameTypes }; template class std::map<uint32_t, GLuint>; // A strong wrapper for GLuint names, to avoid accidentally using the wrong // name somewhere. template <GLNameType T, class U> class StrongResourceIDBase { public: typedef U value_type; protected: value_type m_id; public: constexpr StrongResourceIDBase() { m_id = 0; } explicit StrongResourceIDBase(value_type _id) { m_id = _id; } StrongResourceIDBase(StrongResourceIDBase<T, U> const &_other) : m_id(_other.m_id) { } StrongResourceIDBase &operator=(StrongResourceIDBase const &_other) { m_id = _other.m_id; return *this; } U value() const { return m_id; } bool valid() const { return m_id != 0; } void reset() { m_id = 0; } bool operator==(StrongResourceIDBase const &_other) const { return m_id = _other.m_id; } bool operator!=(StrongResourceIDBase const &_other) const { return !(*this == _other); } }; template <GLNameType T> class GLResourceName final : public StrongResourceIDBase<T, GLuint> { public: typedef GLResourceName<T> this_type; typedef StrongResourceIDBase<T, GLuint> base_type; typedef base_type::value_type value_type; public: static void gl_create(GLsizei numNames, value_type *names) { if constexpr (T == GLNameType::VertexArray) glGenVertexArrays(numNames, names); else UNREACHABLE; } constexpr GLResourceName() : base_type() { } explicit GLResourceName(value_type _id) : base_type(_id) { } [[nodiscard]] static this_type create() { this_type newId; gl_create(1, &newId.m_id); return newId; } operator value_type() const { return this->m_id; } }; template <GLNameType T> class GLResourceRef final : public StrongResourceIDBase<T, uint32_t> { friend class Resource; public: typedef StrongResourceIDBase<T, uint32_t> base_type; typedef GLResourceRef<T> this_type; typedef GLResourceName<T> name_type; typedef base_type::value_type value_type; typedef name_type::base_type::value_type name_value_type; private: static uint32_t s_lastIdx; static std::map<value_type, name_value_type> s_resourceNames; protected: static NOINLINE void create(this_type &_idx, name_type &_name) { _idx = this_type(++s_lastIdx); _name = name_type::create(); s_resourceNames.emplace(_idx.value(), _name.value()); } public: constexpr GLResourceRef() : base_type() { } explicit GLResourceRef(value_type _id) : base_type(_id) { } // Returns true if a new object had to be created // Returns false if an exissting object was returned [[nodiscard]] bool create(name_type &_name) { create(*this, _name); return true; } }; typedef GLResourceName<GLNameType::VertexArray> GLVertexArrayName; typedef GLResourceRef<GLNameType::VertexArray> GLVertexArrayID; class TestRepro { public: GLVertexArrayID m_vao; GLVertexArrayName EmptyVAO() { GLVertexArrayName name; if (m_vao.create(name)) { glBindVertexArray(name); glBindVertexArray(0); } return name; } }; TestRepro g_class; ```
shafik commented 11 months ago

Much reduced: https://gcc.godbolt.org/z/7PhK1vvhh

#include <map>

template <int T>
struct StrongResourceIDBase {
    typedef int value_type;
};

template <int T>
struct GLResourceName  {
    typedef StrongResourceIDBase<T> base_type;
};

template <int T>
class GLResourceRef  {
    typedef GLResourceName<T>::base_type::value_type name_value_type;

private:
    static std::map<unsigned int, name_value_type> s_resourceNames;
};

GLResourceRef<0> m_vao;

Looks like a regression starting in clang-16.

CC @dwblaikie

dwblaikie commented 11 months ago

Reduced down a bit further:

template <typename T>
struct t1 {
  typedef int m1;
};

template <typename T>
struct t2 {
  typedef t1<T> m2;
};

template <typename T>
struct t3 {
  static t2<T>::m2::m1 m3;
};

t3<int> g1;

The missing typename in static typename t2<T>::m2::m1 m3; seems to make a difference between success and crashing. So I'm guessing maybe some difference in the AST was made that caused this problem.

dwblaikie commented 11 months ago

Yeah, so in the missing typename case, the CGDebugInfo.cpp sees the static member as having a dependent type:

DependentNameType 0x555569273d20 'typename t2<int>::m2::m1' dependent

Whereas in the case that has the typename:

ElaboratedType 0x555569274200 'typename t2<int>::m2::m1' sugar
`-TypedefType 0x5555692741d0 't1<int>::m1' sugar
  |-Typedef 0x555569274160 'm1'
  `-BuiltinType 0x555569204fc0 'int'
dwblaikie commented 11 months ago

That doesn't seem consistent with Clang's "recover as-if the fixit was written in the source".

dwblaikie commented 11 months ago

So I think this should be a generic clang fix, not related to debug info.