Skip to content

[clang] crash caused by a slightly modified libc++ std::source_location (in nostd) as a template argument #59948

@Qwinci

Description

@Qwinci
Stack dump:
0.	Program arguments: /usr/lib/llvm/15/bin/clang++ -I/home/visa/CLionProjects/crescent/src -I/home/visa/CLionProjects/crescent/thirdparty -g -fPIE -fcolor-diagnostics -Wall -fno-stack-protector -mno-80387 -mno-mmx -mno-sse -mno-sse2 -mno-red-zone -mgeneral-regs-only -mcmodel=kernel -masm=intel -fno-omit-frame-pointer -Wno-interrupt-service-routine -nostdlibinc -fno-exceptions -fno-rtti -std=gnu++2b -MD -MT CMakeFiles/crescent.dir/src/memory/allocator.cpp.o -MF CMakeFiles/crescent.dir/src/memory/allocator.cpp.o.d -o CMakeFiles/crescent.dir/src/memory/allocator.cpp.o -c /home/visa/CLionProjects/crescent/src/memory/allocator.cpp
1.	/home/visa/CLionProjects/crescent/src/memory/allocator.cpp:63:1: current parser token 'void'
2.	/home/visa/CLionProjects/crescent/src/memory/allocator.cpp:26:18: LLVM IR generation of declaration 'Allocator::alloc'
3.	/home/visa/CLionProjects/crescent/src/memory/allocator.cpp:26:18: Generating code for declaration 'Allocator::alloc'
4.	/home/visa/CLionProjects/crescent/src/utils/panic.hpp:32:33: Mangling declaration 'panic'
 #0 0x00007f4b6204c153 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/llvm/15/bin/../lib64/libLLVM-15.so+0x364c153)
 #1 0x00007f4b6204a292 llvm::sys::RunSignalHandlers() (/usr/lib/llvm/15/bin/../lib64/libLLVM-15.so+0x364a292)
 #2 0x00007f4b61f6c266 (/usr/lib/llvm/15/bin/../lib64/libLLVM-15.so+0x356c266)
 #3 0x00007f4b65468950 (/lib64/libc.so.6+0x37950)
 #4 0x00007f4b66f7293b (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x197293b)
 #5 0x00007f4b66f80c60 (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x1980c60)
 #6 0x00007f4b66f807d7 (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x19807d7)
 #7 0x00007f4b66f7dacb (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x197dacb)
 #8 0x00007f4b66f81706 (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x1981706)
 #9 0x00007f4b66f73fc7 (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x1973fc7)
#10 0x00007f4b66f72d7d (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x1972d7d)
#11 0x00007f4b66f700bc (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x19700bc)
#12 0x00007f4b67d3482a (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x273482a)
#13 0x00007f4b67d2e96d clang::CodeGen::CodeGenModule::getMangledName(clang::GlobalDecl) (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x272e96d)
#14 0x00007f4b67d43ccd clang::CodeGen::CodeGenModule::GetAddrOfFunction(clang::GlobalDecl, llvm::Type*, bool, bool, clang::CodeGen::ForDefinition_t) (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x2743ccd)
#15 0x00007f4b67b8b614 (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x258b614)
#16 0x00007f4b67b8a3b3 (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x258a3b3)
#17 0x00007f4b67b891d7 clang::CodeGen::CodeGenFunction::EmitCallee(clang::Expr const*) (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x25891d7)
#18 0x00007f4b67b88e5c clang::CodeGen::CodeGenFunction::EmitCallExpr(clang::CallExpr const*, clang::CodeGen::ReturnValueSlot) (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x2588e5c)
#19 0x00007f4b67bc666d (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x25c666d)
#20 0x00007f4b67bb9e9b clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x25b9e9b)
#21 0x00007f4b67b6ea7e clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x256ea7e)
#22 0x00007f4b67b6e940 clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x256e940)
#23 0x00007f4b67cbf1a8 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x26bf1a8)
#24 0x00007f4b67cc004f clang::CodeGen::CodeGenFunction::EmitIfStmt(clang::IfStmt const&) (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x26c004f)
#25 0x00007f4b67cbf2ec clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x26bf2ec)
#26 0x00007f4b67cca8ac clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x26ca8ac)
#27 0x00007f4b67d23c8e clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x2723c8e)
#28 0x00007f4b67d2467c clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x272467c)
#29 0x00007f4b67d424fd clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x27424fd)
#30 0x00007f4b67d3be9d clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x273be9d)
#31 0x00007f4b67d3b631 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x273b631)
#32 0x00007f4b67dcc4cf (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x27cc4cf)
#33 0x00007f4b67d18d6f (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x2718d6f)
#34 0x00007f4b66ba8de7 clang::ParseAST(clang::Sema&, bool, bool) (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x15a8de7)
#35 0x00007f4b68617d5d clang::FrontendAction::Execute() (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x3017d5d)
#36 0x00007f4b685939b6 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x2f939b6)
#37 0x00007f4b6868dbfe clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x308dbfe)
#38 0x0000558fcf46cbc5 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/lib/llvm/15/bin/clang+++0x16bc5)
#39 0x0000558fcf46aa36 (/usr/lib/llvm/15/bin/clang+++0x14a36)
#40 0x00007f4b6825ba52 (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x2c5ba52)
#41 0x00007f4b61f6bfaf llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/usr/lib/llvm/15/bin/../lib64/libLLVM-15.so+0x356bfaf)
#42 0x00007f4b6825b273 clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x2c5b273)
#43 0x00007f4b68223f6a clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x2c23f6a)
#44 0x00007f4b6822425e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x2c2425e)
#45 0x00007f4b6823e28c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/usr/lib/llvm/15/bin/../lib64/libclang-cpp.so.15+0x2c3e28c)
#46 0x0000558fcf46a114 clang_main(int, char**) (/usr/lib/llvm/15/bin/clang+++0x14114)
#47 0x00007f4b6545434a (/lib64/libc.so.6+0x2334a)
#48 0x00007f4b654543fc __libc_start_main (/lib64/libc.so.6+0x233fc)
#49 0x0000558fcf467541 _start (/usr/lib/llvm/15/bin/clang+++0x11541)
clang-15: error: clang frontend command failed with exit code 139 (use -v to see invocation)

Minimal reproducible example compiled with clang++ -std=c++20:

namespace std {
    class source_location {
    public:
        struct __impl;
        static constexpr source_location current(const __impl* __p = __builtin_source_location()) {
            source_location loc;
            loc.impl = __p;
            return loc;
        }
        [[nodiscard]] constexpr unsigned int line() const { return impl ? impl->_M_line : 0; }
        struct __impl {
            const char* _M_file_name;
            const char* _M_function_name;
            unsigned int _M_line;
            unsigned int _M_column;
        };
        const __impl* impl = nullptr;
    };
}

template<typename... Args, std::source_location loc = std::source_location::current()>
[[noreturn]] static inline void panic(Args... args) {
    while (true);
}

int main() {
    panic("Hello");
}

backtrace.txt
allocator-37f680.cpp.txt
allocator-37f680.sh.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmedVerified by a second partycrashPrefer [crash-on-valid] or [crash-on-invalid]llvm:codegen

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions