Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libcxx's modules build will crash #58716

Closed
ChuanqiXu9 opened this issue Nov 1, 2022 · 10 comments
Closed

libcxx's modules build will crash #58716

ChuanqiXu9 opened this issue Nov 1, 2022 · 10 comments
Assignees
Labels
clang:modules C++20 modules and Clang Header Modules crash Prefer [crash-on-valid] or [crash-on-invalid]

Comments

@ChuanqiXu9
Copy link
Member

ChuanqiXu9 commented Nov 1, 2022

From https://reviews.llvm.org/D134036.

Reproduce:

cmake -G Ninja ../llvm -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=On -DLLVM_ENABLE_PROJECTS="clang;" -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" -DLIBCXX_TEST_PARAMS="enable_modules=True"

Crash log:

llvm-lit: /iusers/ekeane1/workspaces/delayed-concepts/libcxx/utils/libcxx/test/newconfig.py:19: note: (llvm-libc++-shared.cfg.in) Using %{cxx} substitution: '/iusers/ekeane1/workspaces/delayed-concepts/build/./bin/clang++'
llvm-lit: /iusers/ekeane1/workspaces/delayed-concepts/libcxx/utils/libcxx/test/newconfig.py:19: note: (llvm-libc++-shared.cfg.in) Using %{flags} substitution: ' --target=x86_64-unknown-linux-gnu'
llvm-lit: /iusers/ekeane1/workspaces/delayed-concepts/libcxx/utils/libcxx/test/newconfig.py:19: note: (llvm-libc++-shared.cfg.in) Using %{compile_flags} substitution: '-nostdinc++ -I %{include} -I %{target-include} -I %{libcxx}/test/support -std=c++2b -fmodules -fcxx-modules -Werror -Wall -Wctad-maybe-unsupported -Wextra -Wshadow -Wundef -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-c++11-extensions -Wno-noexcept-type -Wno-atomic-alignment -W
no-user-defined-literals -Wno-tautological-compare -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBCPP_ENABLE_EXPERIMENTAL -D_LIBCPP_DISABLE_AVAILABILITY -fcoroutines-ts -Werror=thread-safety -Wuser-defined-warnings'
llvm-lit: /iusers/ekeane1/workspaces/delayed-concepts/libcxx/utils/libcxx/test/newconfig.py:19: note: (llvm-libc++-shared.cfg.in) Using %{link_flags} substitution: '-lc++experimental -nostdlib++ -L %{lib} -Wl,-rpath,%{lib} -lc++ -pthread'
llvm-lit: /iusers/ekeane1/workspaces/delayed-concepts/libcxx/utils/libcxx/test/newconfig.py:19: note: (llvm-libc++-shared.cfg.in) Using %{exec} substitution: '%{executor} --execdir %T -- '
llvm-lit: /iusers/ekeane1/workspaces/delayed-concepts/libcxx/utils/libcxx/test/newconfig.py:19: note: (llvm-libc++-shared.cfg.in) All available features: modules-build, verify-support, clang-16.0, locale.fr_CA.ISO8859-1, clang, stdlib=libc++, long_tests, clang-16.0.0, fcoroutines-ts, locale.zh_CN.UTF-8, locale.ja_JP.UTF-8, linux, objective-c++, has-fblocks, target=x86_64-unknown-linux-gnu, buildhost=linux, locale.fr_FR.UTF-8, c++experimental, locale.cs_CZ.ISO8859-2, libcpp
-abi-version=1, fdelayed-template-parsing, diagnose-if-support, locale.en_US.UTF-8, stdlib=llvm-libc++, has-fconstexpr-steps, -fsized-deallocation, clang-16, c++2b, thread-safety, -faligned-allocation, locale.ru_RU.UTF-8, has-unix-headers
FAIL: llvm-libc++-shared.cfg.in :: std/utilities/format/format.functions/escaped_output.ascii.pass.cpp (1 of 7790)
******************** TEST 'llvm-libc++-shared.cfg.in :: std/utilities/format/format.functions/escaped_output.ascii.pass.cpp' FAILED ********************
Script:
--
: 'COMPILED WITH';  /iusers/ekeane1/workspaces/delayed-concepts/build/./bin/clang++ /localdisk2/ekeane1/workspaces/delayed-concepts/libcxx/test/std/utilities/format/format.functions/escaped_output.ascii.pass.cpp  --target=x86_64-unknown-linux-gnu -nostdinc++ -I /iusers/ekeane1/workspaces/delayed-concepts/build/include/c++/v1 -I /iusers/ekeane1/workspaces/delayed-concepts/build/include/x86_64-unknown-linux-gnu/c++/v1 -I /iusers/ekeane1/workspaces/delayed-concepts/libcxx/tes
t/support -std=c++2b -fmodules -fcxx-modules -Werror -Wall -Wctad-maybe-unsupported -Wextra -Wshadow -Wundef -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-c++11-extensions -Wno-noexcept-type -Wno-atomic-alignment -Wno-user-defined-literals -Wno-tautological-compare -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBCPP_ENABLE_EXPERIMENTAL -D_LIBCPP_DISAB
LE_AVAILABILITY -fcoroutines-ts -Werror=thread-safety -Wuser-defined-warnings -D_LIBCPP_HAS_NO_UNICODE -lc++experimental -nostdlib++ -L /iusers/ekeane1/workspaces/delayed-concepts/build/./lib/x86_64-unknown-linux-gnu -Wl,-rpath,/iusers/ekeane1/workspaces/delayed-concepts/build/./lib/x86_64-unknown-linux-gnu -lc++ -pthread -o /localdisk2/ekeane1/workspaces/delayed-concepts/build/runtimes/runtimes-bins/test/std/utilities/format/format.functions/Output/escaped_output.ascii.pa
ss.cpp.dir/t.tmp.exe
: 'EXECUTED AS';  "/usr/bin/python3.6" /iusers/ekeane1/workspaces/delayed-concepts/libcxx/test/../utils/run.py --execdir /localdisk2/ekeane1/workspaces/delayed-concepts/build/runtimes/runtimes-bins/test/std/utilities/format/format.functions/Output/escaped_output.ascii.pass.cpp.dir --  /localdisk2/ekeane1/workspaces/delayed-concepts/build/runtimes/runtimes-bins/test/std/utilities/format/format.functions/Output/escaped_output.ascii.pass.cpp.dir/t.tmp.exe
--
Exit Code: 1

Command Output (stdout):
--
$ ":" "COMPILED WITH"
$ "/iusers/ekeane1/workspaces/delayed-concepts/build/./bin/clang++" "/localdisk2/ekeane1/workspaces/delayed-concepts/libcxx/test/std/utilities/format/format.functions/escaped_output.ascii.pass.cpp" "--target=x86_64-unknown-linux-gnu" "-nostdinc++" "-I" "/iusers/ekeane1/workspaces/delayed-concepts/build/include/c++/v1" "-I" "/iusers/ekeane1/workspaces/delayed-concepts/build/include/x86_64-unknown-linux-gnu/c++/v1" "-I" "/iusers/ekeane1/workspaces/delayed-concepts/libcxx/test/support" "-std=c++2b" "-fmodules" "-fcxx-modules" "-Werror" "-Wall" "-Wctad-maybe-unsupported" "-Wextra" "-Wshadow" "-Wundef" "-Wno-unused-command-line-argument" "-Wno-attributes" "-Wno-pessimizing-move" "-Wno-c++11-extensions" "-Wno-noexcept-type" "-Wno-atomic-alignment" "-Wno-user-defined-literals" "-Wno-tautological-compare" "-Wsign-compare" "-Wunused-variable" "-Wunused-parameter" "-Wunreachable-code" "-Wno-unused-local-typedef" "-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER" "-D_LIBCPP_ENABLE_EXPERIMENTAL" "-D_LIBCPP_DISABLE_AVAILABILITY" "-fcoroutines-ts" "-Werror=thread-safety" "-Wuser-defined-warnings" "-D_LIBCPP_HAS_NO_UNICODE" "-lc++experimental" "-nostdlib++" "-L" "/iusers/ekeane1/workspaces/delayed-concepts/build/./lib/x86_64-unknown-linux-gnu" "-Wl,-rpath,/iusers/ekeane1/workspaces/delayed-concepts/build/./lib/x86_64-unknown-linux-gnu" "-lc++" "-pthread" "-o" "/localdisk2/ekeane1/workspaces/delayed-concepts/build/runtimes/runtimes-bins/test/std/utilities/format/format.functions/Output/escaped_output.ascii.pass.cpp.dir/t.tmp.exe"
# command stderr:
clang-16: tools/clang/include/clang/AST/AbstractBasicReader.inc:736: clang::APValue clang::serialization::BasicReaderBase<T>::readAPValue() [with Impl = clang::ASTRecordReader]: Assertion `lvaluePath->getType() == elemTy && "Unexpected type reference!"' 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: /localdisk2/ekeane1/workspaces/delayed-concepts/build/bin/clang-16 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all --mrelax-relocations -disable-free -clear-ast-before-backend -main-file-name escaped_output.ascii.pass.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -fcoverage-compilation-dir=/localdisk2/ekeane1/workspaces/delayed-concepts/build/runtimes/runtimes-bins/test/std/utilities/format/format.functions -nostdinc++ -resource-dir /localdisk2/ekeane1/workspaces/delayed-concepts/build/lib/clang/16.0.0 -I /iusers/ekeane1/workspaces/delayed-concepts/build/include/c++/v1 -I /iusers/ekeane1/workspaces/delayed-concepts/build/include/x86_64-unknown-linux-gnu/c++/v1 -I /iusers/ekeane1/workspaces/delayed-concepts/libcxx/test/support -D _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D _LIBCPP_ENABLE_EXPERIMENTAL -D _LIBCPP_DISABLE_AVAILABILITY -D _LIBCPP_HAS_NO_UNICODE -internal-isystem /localdisk2/ekeane1/workspaces/delayed-concepts/build/lib/clang/16.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/8/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Werror -Wall -Wctad-maybe-unsupported -Wextra -Wshadow -Wundef -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-c++11-extensions -Wno-noexcept-type -Wno-atomic-alignment -Wno-user-defined-literals -Wno-tautological-compare -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -Werror=thread-safety -Wuser-defined-warnings -std=c++2b -fdeprecated-macro -fdebug-compilation-dir=/localdisk2/ekeane1/workspaces/delayed-concepts/build/runtimes/runtimes-bins/test/std/utilities/format/format.functions -ferror-limit 19 -pthread -fcoroutines-ts -fgnuc-version=4.2.1 -fmodules -fimplicit-module-maps -fmodules-cache-path=/nfs/site/home/ekeane1/.cache/clang/ModuleCache -fmodules-validate-system-headers -fcxx-exceptions -fexceptions -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/lit-tmp-ddqg5hwq/escaped_output-3e7200.o -x c++ /localdisk2/ekeane1/workspaces/delayed-concepts/libcxx/test/std/utilities/format/format.functions/escaped_output.ascii.pass.cpp
1.      <eof> parser at end of file
2.      Per-file LLVM IR generation
3.      /iusers/ekeane1/workspaces/delayed-concepts/build/include/c++/v1/__format/formatter_output.h:443:1: Generating code for declaration 'std::__formatter::__is_escaped_sequence_written'
 #0 0x0000000007ff1cff PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #1 0x0000000007fef44c SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f4a9fb0bdd0 __restore_rt sigaction.c:0:0
 #3 0x00007f4a9e34e70f raise (/lib64/libc.so.6+0x3770f)
 #4 0x00007f4a9e338b25 abort (/lib64/libc.so.6+0x21b25)
 #5 0x00007f4a9e3389f9 _nl_load_domain.cold.0 loadmsgcat.c:0:0
 #6 0x00007f4a9e346cc6 .annobin___GI___assert_fail.end assert.c:0:0
 #7 0x0000000008ddfda8 clang::serialization::BasicReaderBase<clang::ASTRecordReader>::readAPValue() ASTReaderDecl.cpp:0:0
 #8 0x0000000008df0c99 clang::ASTStmtReader::VisitConstantExpr(clang::ConstantExpr*) (/localdisk2/ekeane1/workspaces/delayed-concepts/build/bin/clang-16+0x8df0c99)
 #9 0x0000000008df1eda clang::ASTReader::ReadStmtFromStream(clang::serialization::ModuleFile&) (/localdisk2/ekeane1/workspaces/delayed-concepts/build/bin/clang-16+0x8df1eda)
#10 0x0000000008d5a3e4 clang::ASTReader::GetExternalDeclStmt(unsigned long) (/localdisk2/ekeane1/workspaces/delayed-concepts/build/bin/clang-16+0x8d5a3e4)
#11 0x000000000ac32830 clang::FunctionDecl::getBody(clang::FunctionDecl const*&) const (/localdisk2/ekeane1/workspaces/delayed-concepts/build/bin/clang-16+0xac32830)
#12 0x00000000084c6f71 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/localdisk2/ekeane1/workspaces/delayed-concepts/build/bin/clang-16+0x84c6f71)
#13 0x0000000008418cf6 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/localdisk2/ekeane1/workspaces/delayed-concepts/build/bin/clang-16+0x8418cf6)
#14 0x0000000008414db5 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/localdisk2/ekeane1/workspaces/delayed-concepts/build/bin/clang-16+0x8414db5)
#15 0x000000000841d339 clang::CodeGen::CodeGenModule::EmitDeferred() (/localdisk2/ekeane1/workspaces/delayed-concepts/build/bin/clang-16+0x841d339)
#16 0x000000000841d288 clang::CodeGen::CodeGenModule::EmitDeferred() (/localdisk2/ekeane1/workspaces/delayed-concepts/build/bin/clang-16+0x841d288)
#17 0x000000000841d288 clang::CodeGen::CodeGenModule::EmitDeferred() (/localdisk2/ekeane1/workspaces/delayed-concepts/build/bin/clang-16+0x841d288)
#18 0x000000000841d288 clang::CodeGen::CodeGenModule::EmitDeferred() (/localdisk2/ekeane1/workspaces/delayed-concepts/build/bin/clang-16+0x841d288)
#19 0x000000000841d288 clang::CodeGen::CodeGenModule::EmitDeferred() (/localdisk2/ekeane1/workspaces/delayed-concepts/build/bin/clang-16+0x841d288)
#20 0x000000000841d288 clang::CodeGen::CodeGenModule::EmitDeferred() (/localdisk2/ekeane1/workspaces/delayed-concepts/build/bin/clang-16+0x841d288)
#21 0x000000000841d288 clang::CodeGen::CodeGenModule::EmitDeferred() (/localdisk2/ekeane1/workspaces/delayed-concepts/build/bin/clang-16+0x841d288)
#22 0x000000000841d288 clang::CodeGen::CodeGenModule::EmitDeferred() (/localdisk2/ekeane1/workspaces/delayed-concepts/build/bin/clang-16+0x841d288)
#23 0x000000000841d288 clang::CodeGen::CodeGenModule::EmitDeferred() (/localdisk2/ekeane1/workspaces/delayed-concepts/build/bin/clang-16+0x841d288)
#24 0x000000000841d288 clang::CodeGen::CodeGenModule::EmitDeferred() (/localdisk2/ekeane1/workspaces/delayed-concepts/build/bin/clang-16+0x841d288)
#25 0x000000000841d288 clang::CodeGen::CodeGenModule::EmitDeferred() (/localdisk2/ekeane1/workspaces/delayed-concepts/build/bin/clang-16+0x841d288)
#26 0x000000000841d288 clang::CodeGen::CodeGenModule::EmitDeferred() (/localdisk2/ekeane1/workspaces/delayed-concepts/build/bin/clang-16+0x841d288)
#27 0x000000000841d288 clang::CodeGen::CodeGenModule::EmitDeferred() (/localdisk2/ekeane1/workspaces/delayed-concepts/build/bin/clang-16+0x841d288)
#28 0x000000000841d288 clang::CodeGen::CodeGenModule::EmitDeferred() (/localdisk2/ekeane1/workspaces/delayed-concepts/build/bin/clang-16+0x841d288)
#29 0x000000000841d288 clang::CodeGen::CodeGenModule::EmitDeferred() (/localdisk2/ekeane1/workspaces/delayed-concepts/build/bin/clang-16+0x841d288)
#30 0x000000000841d288 clang::CodeGen::CodeGenModule::EmitDeferred() (/localdisk2/ekeane1/workspaces/delayed-concepts/build/bin/clang-16+0x841d288)
#31 0x000000000841d288 clang::CodeGen::CodeGenModule::EmitDeferred() (/localdisk2/ekeane1/workspaces/delayed-concepts/build/bin/clang-16+0x841d288)
#32 0x00000000084200bd clang::CodeGen::CodeGenModule::Release() (/localdisk2/ekeane1/workspaces/delayed-concepts/build/bin/clang-16+0x84200bd)
#33 0x0000000008d0fb1a (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) ModuleBuilder.cpp:0:0
#34 0x0000000008d0f29d clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) CodeGenAction.cpp:0:0
#35 0x0000000009f41bbd clang::ParseAST(clang::Sema&, bool, bool) (/localdisk2/ekeane1/workspaces/delayed-concepts/build/bin/clang-16+0x9f41bbd)
#36 0x0000000008d0e398 clang::CodeGenAction::ExecuteAction() (/localdisk2/ekeane1/workspaces/delayed-concepts/build/bin/clang-16+0x8d0e398)
#37 0x0000000008c2cf09 clang::FrontendAction::Execute() (/localdisk2/ekeane1/workspaces/delayed-concepts/build/bin/clang-16+0x8c2cf09)
#38 0x0000000008bc1fe1 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/localdisk2/ekeane1/workspaces/delayed-concepts/build/bin/clang-16+0x8bc1fe1)
#39 0x0000000008d05b3b clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/localdisk2/ekeane1/workspaces/delayed-concepts/build/bin/clang-16+0x8d05b3b)
#40 0x00000000056a2474 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/localdisk2/ekeane1/workspaces/delayed-concepts/build/bin/clang-16+0x56a2474)
#41 0x000000000569b057 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#42 0x000000000569f98b clang_main(int, char**) (/localdisk2/ekeane1/workspaces/delayed-concepts/build/bin/clang-16+0x569f98b)
#43 0x00007f4a9e33a6a3 __libc_start_main (/lib64/libc.so.6+0x236a3)
#44 0x000000000569a92e _start (/localdisk2/ekeane1/workspaces/delayed-concepts/build/bin/clang-16+0x569a92e)
clang-16: error: unable to execute command: Aborted (core dumped)
clang-16: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 16.0.0 (https://github.com/llvm/llvm-project.git a48007355a03851f0f9bfcafd7a7865ca7467416)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /iusers/ekeane1/workspaces/delayed-concepts/build/./bin
clang-16: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-16: note: diagnostic msg: /tmp/lit-tmp-ddqg5hwq/escaped_output-b4d1d3.cpp
clang-16: note: diagnostic msg: /tmp/lit-tmp-ddqg5hwq/escaped_output-b4d1d3.cache
clang-16: note: diagnostic msg: /tmp/lit-tmp-ddqg5hwq/escaped_output-b4d1d3.sh
clang-16: note: diagnostic msg:

********************
@EugeneZelenko EugeneZelenko added clang:modules C++20 modules and Clang Header Modules clang:codegen crash Prefer [crash-on-valid] or [crash-on-invalid] and removed new issue labels Nov 1, 2022
@llvmbot
Copy link
Collaborator

llvmbot commented Nov 1, 2022

@llvm/issue-subscribers-clang-codegen

@llvmbot
Copy link
Collaborator

llvmbot commented Nov 1, 2022

@llvm/issue-subscribers-clang-modules

@aaronmondal
Copy link
Member

Ha! I encountered this when trying to include spdlog in the GMF of a module interface unit. I finally managed to create a reproducer 🥳

// mymodule.cppm
module;
#include "fail.h"
export module mymodule;


// fail.h
#include <string>
#include <format>

auto this_fails() -> void {
  std::string buffer;
  std::format_to(std::back_inserter(buffer), "{}", "hello");
}

Precompilation works. The failure occurs during It fails during the pcm -> object compilation.

 "bazel-out/k8-fastbuild-ST-1b2103630309/bin/external/llvm-project-overlay~16.0.0-bcr.0~llvm_project_overlay~llvm-project/clang/clang" -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all --mrelax-relocations -disable-free -clear-ast-before-backend -main-file-name mymodule.pcm -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposi
tion -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -v -fcoverage-compilation-dir=/home/aaron/.cache/bazel/_bazel_aaron/95259220a0c772521400371bdce9789f/sandbox/linux-sandbox/8978/exe
croot/_main -nostdinc++ -resource-dir bazel-out/k8-fastbuild/bin/external/llvm-project-overlay~16.0.0-bcr.0~llvm_project_overlay~llvm-project/clang/staging -Wdate-time -std=c++20 -fdebug-compilation-dir=. -ferror-limit 19 -fgnuc-version=4.2.1 -fcolor-diagnostics -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o bazel-out/k8-fastbuild/bin/mymodule.interface.o -x pc
m bazel-out/k8-fastbuild/bin/mymodule.pcm
clang -cc1 version 16.0.0 based upon LLVM 16.0.0git default target x86_64-unknown-linux-gnu
clang: bazel-out/k8-fastbuild-ST-1b2103630309/bin/external/llvm-project-overlay~16.0.0-bcr.0~llvm_project_overlay~llvm-project/clang/include/clang/AST/AbstractBasicReader.inc:736: clang::APValue clang::serialization::BasicReaderBase<clang::ASTRecordReader>::readAPValue() [Impl = clang::ASTRecordReader]: Assertion `lvaluePath->getType() == elemTy &
& "Unexpected type reference!"' 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: bazel-out/k8-fastbuild-ST-1b2103630309/bin/external/llvm-project-overlay~16.0.0-bcr.0~llvm_project_overlay~llvm-project/clang/clang -fcolor-diagnostics -Wdate-time -no-canonical-prefixes -fdebug-compilation-dir=. -fno-coverage-mapping -c -fPIC -Xarch_host -MJbazel-out/k8-fastbuild/bin/mymodule.interface.cdf -nostdlib++ -
nostdinc++ -nostdlib --gcc-toolchain=NONE -resource-dir=bazel-out/k8-fastbuild/bin/external/llvm-project-overlay~16.0.0-bcr.0~llvm_project_overlay~llvm-project/clang/staging -Iinclude -DSPDLOG_USE_STD_FORMAT -D_LIBCPP_ENABLE_EXPERIMENTAL -D_LIBCPP_NO_ABI_TAG -std=c++20 -v bazel-out/k8-fastbuild/bin/mymodule.pcm -o bazel-out/k8-fastbuild/bin/mymodu
le.interface.o
1.      <eof> parser at end of file
2.      /home/aaron/.cache/bazel/_bazel_aaron/95259220a0c772521400371bdce9789f/execroot/_main/fail.h:4:6: LLVM IR generation of declaration 'this_fails'
3.      /home/aaron/.cache/bazel/_bazel_aaron/95259220a0c772521400371bdce9789f/execroot/_main/fail.h:4:6: Generating code for declaration 'this_fails'

@ChuanqiXu9
Copy link
Member Author

@aaronmondal Thanks for reporting. And I get a minimal reproducer from your reproducer:

// clang++ -std=c++20 --precompile m.cppm  -o m.pcm
// clang++ -std=c++20 m.pcm -c
// m.cppm
module;
namespace std { 

template<class _CharT>
class basic_string_view {
public:
    constexpr basic_string_view(const _CharT* __s)
        : __data_(__s) {}

private:
    const   _CharT* __data_;
};

template <class _CharT>
struct basic_format_string {
  template <class _Tp>
  consteval basic_format_string(const _Tp& __str) : __str_{__str} {
  }

private:
  basic_string_view<_CharT> __str_;
};
}

auto this_fails() -> void {
    std::basic_format_string<char> __fmt("{}");
}
export module mymodule;

The crash goes aways if we don't mark the constructor of basic_format_string as consteval. So I can get a rough direction here. For your experiments, may be you can try to continue by removing the constexpr specifier (maybe you need to edit the code in libcxx;s __config file).

@ChuanqiXu9 ChuanqiXu9 self-assigned this Dec 6, 2022
@aaronmondal
Copy link
Member

aaronmondal commented Dec 6, 2022

@ChuanqiXu9 Ah yes this seems to be an issue with consteval. One other occurence of this error is at __chrono/statically_widen.h (@mordante left a comment that something was not working quite right. Likely related.).

The following hacky workaround patch makes at least the spdlog build pass.

diff --git a/libcxx/include/__chrono/statically_widen.h b/libcxx/include/__chrono/statically_widen.h
index dd12c3f5020e..6d29452e765d 100644
--- a/libcxx/include/__chrono/statically_widen.h
+++ b/libcxx/include/__chrono/statically_widen.h
@@ -26,7 +26,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 #  ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 template <__fmt_char_type _CharT>
-consteval const _CharT* __statically_widen(const char* __str, const wchar_t* __wstr) {
+constexpr const _CharT* __statically_widen(const char* __str, const wchar_t* __wstr) {
   if constexpr (same_as<_CharT, char>)
     return __str;
   else
@@ -39,7 +39,7 @@ consteval const _CharT* __statically_widen(const char* __str, const wchar_t* __w
 // fails for the CI build "No wide characters". This seems like a bug.
 // TODO FMT investigate why this is needed.
 template <__fmt_char_type _CharT>
-consteval const _CharT* __statically_widen(const char* __str) {
+constexpr const _CharT* __statically_widen(const char* __str) {
   return __str;
 }
 #    define _LIBCPP_STATICALLY_WIDEN(_CharT, __str) ::std::__statically_widen<_CharT>(__str)
diff --git a/libcxx/include/__format/format_functions.h b/libcxx/include/__format/format_functions.h
index 2e7925bfbd01..f8a0352b328a 100644
--- a/libcxx/include/__format/format_functions.h
+++ b/libcxx/include/__format/format_functions.h
@@ -335,7 +335,7 @@ template <class _CharT, class... _Args>
 struct _LIBCPP_TEMPLATE_VIS basic_format_string {
   template <class _Tp>
     requires convertible_to<const _Tp&, basic_string_view<_CharT>>
-  consteval basic_format_string(const _Tp& __str) : __str_{__str} {
+  constexpr basic_format_string(const _Tp& __str) : __str_{__str} {
     __format::__vformat_to(basic_format_parse_context<_CharT>{__str_, sizeof...(_Args)},
                            _Context{__types_.data(), __handles_.data(), sizeof...(_Args)});
   }

@ChuanqiXu9
Copy link
Member Author

@aaronmondal

@mordante left a comment that something was not working quite right. Likely related

Is there a bug reporting?

@mordante
Copy link
Member

Not entirely sure whether that's related. I need to investigate whether it's really a bug not.
I recall when I worked on getting the consteval constructor for basic_format_string working I had several issues.

I just changed the __compile_time_basic_format_context to use consteval instead of constexpr, which now works. I tested with a clang nightly build of last weekend. This works both normally and using clang modules. I haven't tested with C++20 modules but I expect that to fail since libc++ has no support for that.

@ChuanqiXu9
Copy link
Member Author

@mordante Got it.

I haven't tested with C++20 modules but I expect that to fail since libc++ has no support for that.

BTW, do you know if there are any plan about supporting std modules in libcxx? I mean something like https://reviews.llvm.org/D135507. (I'm not selling it. I know its current quality is not good enough). It shows it is not impossible to talk about C++20 Modules in libcxx now. And I want to know if there is anyone who is interested.

@mordante
Copy link
Member

I'm definitely interested in modules in libc++. However I'm not sure what the status of C++20 modules in clang is. I think it would be best to discuss this in the libcxx Discord channel and maybe have a short telecon with the interested parties.

@ChuanqiXu9
Copy link
Member Author

I'm definitely interested in modules in libc++. However I'm not sure what the status of C++20 modules in clang is. I think it would be best to discuss this in the libcxx Discord channel and maybe have a short telecon with the interested parties.

Good idea. I mentioned it in https://discord.com/channels/636084430946959380/636732894974312448/1052403022271094824. I wanted to ping you but I can't find your name there.

hahnjo pushed a commit to hahnjo/root that referenced this issue Apr 28, 2023
…Helper's type properly

Close llvm/llvm-project#58716.

Tested with libcxx's modules build.

When we read the type of
LValuePathSerializationHelper, we didn't read the correct type. We read
the element type as its name suggests. But the problem here is that it
looks like that both the usage and serialization use its type as the
top level type. So here is the mismatch.

Actually, the type of LValuePathSerializationHelper is never used after
Deserialization without the assertion. So it doesn't matter for the
release users. And this patch shouldn't change the behavior too.

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D139406
Axel-Naumann pushed a commit to root-project/root that referenced this issue Apr 29, 2023
…Helper's type properly

Close llvm/llvm-project#58716.

Tested with libcxx's modules build.

When we read the type of
LValuePathSerializationHelper, we didn't read the correct type. We read
the element type as its name suggests. But the problem here is that it
looks like that both the usage and serialization use its type as the
top level type. So here is the mismatch.

Actually, the type of LValuePathSerializationHelper is never used after
Deserialization without the assertion. So it doesn't matter for the
release users. And this patch shouldn't change the behavior too.

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D139406
Axel-Naumann pushed a commit to Axel-Naumann/root that referenced this issue Apr 29, 2023
…Helper's type properly

Close llvm/llvm-project#58716.

Tested with libcxx's modules build.

When we read the type of
LValuePathSerializationHelper, we didn't read the correct type. We read
the element type as its name suggests. But the problem here is that it
looks like that both the usage and serialization use its type as the
top level type. So here is the mismatch.

Actually, the type of LValuePathSerializationHelper is never used after
Deserialization without the assertion. So it doesn't matter for the
release users. And this patch shouldn't change the behavior too.

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D139406
Axel-Naumann pushed a commit to root-project/root that referenced this issue Apr 29, 2023
…Helper's type properly

Close llvm/llvm-project#58716.

Tested with libcxx's modules build.

When we read the type of
LValuePathSerializationHelper, we didn't read the correct type. We read
the element type as its name suggests. But the problem here is that it
looks like that both the usage and serialization use its type as the
top level type. So here is the mismatch.

Actually, the type of LValuePathSerializationHelper is never used after
Deserialization without the assertion. So it doesn't matter for the
release users. And this patch shouldn't change the behavior too.

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D139406
Axel-Naumann pushed a commit to root-project/llvm-project that referenced this issue May 17, 2023
Close llvm#58716.

Tested with libcxx's modules build.

When we read the type of
LValuePathSerializationHelper, we didn't read the correct type. We read
the element type as its name suggests. But the problem here is that it
looks like that both the usage and serialization use its type as the
top level type. So here is the mismatch.

Actually, the type of LValuePathSerializationHelper is never used after
Deserialization without the assertion. So it doesn't matter for the
release users. And this patch shouldn't change the behavior too.

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D139406
enirolf pushed a commit to enirolf/root that referenced this issue May 26, 2023
…Helper's type properly

Close llvm/llvm-project#58716.

Tested with libcxx's modules build.

When we read the type of
LValuePathSerializationHelper, we didn't read the correct type. We read
the element type as its name suggests. But the problem here is that it
looks like that both the usage and serialization use its type as the
top level type. So here is the mismatch.

Actually, the type of LValuePathSerializationHelper is never used after
Deserialization without the assertion. So it doesn't matter for the
release users. And this patch shouldn't change the behavior too.

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D139406
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:modules C++20 modules and Clang Header Modules crash Prefer [crash-on-valid] or [crash-on-invalid]
Projects
None yet
Development

No branches or pull requests

5 participants