Skip to content

Clang 20.1.0 Compiler Internal Error (Crash) during AST Parsing of C++23 #145745

Closed as duplicate of#129397
@0xSqualo

Description

@0xSqualo

Clang 20.1.0 crashes with an unhandled internal error, when compiling a specific C++23 source file, and requests that this issue be reported to the LLVM project.

This issue was discovered using Boost 1.83.0 and Clang 20.1.0, which highlights the issue is in the AST parsing logic.

It seems that this issue could potentially be due to AST parsing during the _do_erased_copy(...) call internal to status_code_domain.hpp, however this root cause is not certain.

PoC

See example with full crash on godbolt: https://godbolt.org/z/crG13rjo9

This issue can otherwise be reproduced with:

  • clang-20: version 20.1.0
  • Boost: version 1.83.0

And using a basic entrypoint that includes the boost header which triggers the AST issue:

// main.cpp
#include <boost/outcome/experimental/status-code/status-code/nested_status_code.hpp>

int main() {
    return 0;
}

For full reproducability locally, I used (on Ubuntu 25.04):

CMakeLists.txt:

cmake_minimum_required(VERSION 3.30)

project(clang-20-issue)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

find_package(Boost REQUIRED EXACT 1.83.0)

set(TARGET_NAME a.out)
add_executable(${TARGET_NAME} main.cpp)
target_link_libraries(${TARGET_NAME} PRIVATE ${Boost_LIBRARIES})
target_include_directories(${TARGET_NAME} PRIVATE ${Boost_INCLUDE_DIRS})
set_property(TARGET ${TARGET_NAME} PROPERTY CXX_STANDARD 23)
set_property(TARGET ${TARGET_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)

And this build.sh build script:

mkdir -p build
CC=clang-20 CXX=clang++-20 cmake . -B build
cmake --build build

Which reproduces the same AST crash as on godbolt.

For reference:

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-20.1.0/bin/clang++ -gdwarf-4 -g -o /app/output.s -fno-verbose-asm -c --gcc-toolchain=/opt/compiler-explorer/gcc-14.2.0 -fcolor-diagnostics -fno-crash-diagnostics -std=gnu++23 <source> -isystem/opt/compiler-explorer/libs/boost_1_83_0
1.	/opt/compiler-explorer/libs/boost_1_83_0/boost/outcome/experimental/status-code/status-code/status_code_domain.hpp:451:30: current parser token ')'
2.	/opt/compiler-explorer/libs/boost_1_83_0/boost/outcome/experimental/status-code/status-code/status_code_domain.hpp:38:1 <Spelling=/opt/compiler-explorer/libs/boost_1_83_0/boost/outcome/experimental/status-code/status-code/config.hpp:212:3>: parsing namespace 'system_error2'
3.	/opt/compiler-explorer/libs/boost_1_83_0/boost/outcome/experimental/status-code/status-code/status_code_domain.hpp:110:1: parsing struct/union/class body 'system_error2::status_code_domain'
4.	/opt/compiler-explorer/libs/boost_1_83_0/boost/outcome/experimental/status-code/status-code/status_code_domain.hpp:443:3: parsing function body 'system_error2::status_code_domain::_do_erased_copy'
5.	/opt/compiler-explorer/libs/boost_1_83_0/boost/outcome/experimental/status-code/status-code/status_code_domain.hpp:443:3: in compound statement ('{}')
 #0 0x0000000003a59568 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-20.1.0/bin/clang+++0x3a59568)
 #1 0x0000000003a576ac llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-20.1.0/bin/clang+++0x3a576ac)
 #2 0x00000000039a69e8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x0000793ca9242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x0000000007769b20 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/opt/compiler-explorer/clang-20.1.0/bin/clang+++0x7769b20)
 #5 0x00000000071b4651 clang::ASTContext::getTypeInfoImpl(clang::Type const*) const (/opt/compiler-explorer/clang-20.1.0/bin/clang+++0x71b4651)
 #6 0x000000000719e68b clang::ASTContext::getTypeInfo(clang::Type const*) const (/opt/compiler-explorer/clang-20.1.0/bin/clang+++0x719e68b)
 #7 0x000000000719e68b clang::ASTContext::getTypeInfo(clang::Type const*) const (/opt/compiler-explorer/clang-20.1.0/bin/clang+++0x719e68b)
 #8 0x000000000719e68b clang::ASTContext::getTypeInfo(clang::Type const*) const (/opt/compiler-explorer/clang-20.1.0/bin/clang+++0x719e68b)
 #9 0x00000000071b556b clang::ASTContext::getTypeInfoInChars(clang::Type const*) const (/opt/compiler-explorer/clang-20.1.0/bin/clang+++0x71b556b)
#10 0x00000000071b5ec9 clang::ASTContext::getTypeSizeInChars(clang::QualType) const (/opt/compiler-explorer/clang-20.1.0/bin/clang+++0x71b5ec9)
#11 0x0000000007444ad3 HandleSizeof((anonymous namespace)::EvalInfo&, clang::SourceLocation, clang::QualType, clang::CharUnits&, SizeOfType) ExprConstant.cpp:0:0
#12 0x000000000749f0cb tryEvaluateBuiltinObjectSize(clang::Expr const*, unsigned int, (anonymous namespace)::EvalInfo&, unsigned long&) ExprConstant.cpp:0:0
#13 0x000000000749fb17 clang::Expr::tryEvaluateObjectSize(unsigned long&, clang::ASTContext&, unsigned int) const (/opt/compiler-explorer/clang-20.1.0/bin/clang+++0x749fb17)
#14 0x0000000006506839 clang::Sema::checkFortifiedBuiltinMemoryFunction(clang::FunctionDecl*, clang::CallExpr*)::'lambda1'(unsigned int)::operator()(unsigned int) const SemaChecking.cpp:0:0
#15 0x000000000651d7b0 clang::Sema::checkFortifiedBuiltinMemoryFunction(clang::FunctionDecl*, clang::CallExpr*) (/opt/compiler-explorer/clang-20.1.0/bin/clang+++0x651d7b0)
#16 0x00000000068266e2 clang::Sema::BuildResolvedCallExpr(clang::Expr*, clang::NamedDecl*, clang::SourceLocation, llvm::ArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool, clang::CallExpr::ADLCallKind) (/opt/compiler-explorer/clang-20.1.0/bin/clang+++0x68266e2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    c++23clang:frontendLanguage frontend issues, e.g. anything involving "Sema"crashPrefer [crash-on-valid] or [crash-on-invalid]duplicateResolved as duplicate

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions