Skip to content

[C++20] [Modules] Crash with inconsistent deduced type in two importing modules #78830

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

Closed
gen740 opened this issue Jan 20, 2024 · 2 comments
Closed
Assignees
Labels
clang:modules C++20 modules and Clang Header Modules crash Prefer [crash-on-valid] or [crash-on-invalid]

Comments

@gen740
Copy link

gen740 commented Jan 20, 2024

I created a C++20 modules project incorporating STL libraries, ranges and OpenMP, but it suddenly crashes. I've set up a minimum reproduction project at gen740/InternalCompilerError. (I couldn't minimize the issue further!)

The error message can be found here:
https://github.com/gen740/InternalCompilerError/actions/runs/7592379101/job/20681666596#step:7:33

I also confirmed that this issue occurs in the HEAD branch. However, I can't reproduce it on Compiler Explorer at https://godbolt.org/z/h8M1sq5zc.

@github-actions github-actions bot added the clang Clang issues not falling into any other category label Jan 20, 2024
@gen740
Copy link
Author

gen740 commented Jan 22, 2024

I could minimize the setup without OpenMP and standard libraries.

Step to reproduce

  • Create following 4 c++ modules files.
// Type.ccm
export module MyVec:Type;

template <class T> struct Size {
  auto total() const { return 1; }
};


// Vec.ccm
export module MyVec:Vec;

import :Type;

int size_ = Size<int>().total();

// Vec2.ccm
export module MyVec:Vec2;

import :Type;

struct Vec2 {
  Size<int> size_;
};

// Calculator.ccm
export module MyVec:Calculator;

import :Vec;
import :Vec2;

auto Calculate() { return Size<int>().total(); };
  • Compile with following commands.
$CXX -std=c++23 -c Type.ccm               \
  -fmodule-output=MyVec-Type.pcm
$CXX -std=c++23 -c Vec2.ccm               \
  -fmodule-output=MyVec-Vec2.pcm          \
  -fmodule-file=MyVec:Type=MyVec-Type.pcm
$CXX -std=c++23 -c Vec.ccm                \
  -fmodule-output=MyVec-Vec.pcm           \
  -fmodule-file=MyVec:Type=MyVec-Type.pcm
$CXX -std=c++23 -c Calculator.ccm         \
  -fmodule-output=MyVec-Calculator.pcm    \
  -fmodule-file=MyVec:Vec=MyVec-Vec.pcm   \
  -fmodule-file=MyVec:Vec2=MyVec-Vec2.pcm \
  -fmodule-file=MyVec:Type=MyVec-Type.pcm

Environment

  • OS macOS 14.2.1
  • clang compiler
Homebrew clang version 17.0.6
Target: x86_64-apple-darwin23.2.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin

Output

GitHub Actions

PLEASE submit a bug report to https://github.com/Homebrew/homebrew-core/issues and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: /usr/local/Cellar/llvm/17.0.6_1/bin/clang-17 -cc1 -triple x86_64-apple-macosx14.0.0 -Wundef-prefix=TARGET_OS_ -Werror=undef-prefix -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name Calculator.ccm -mrelocation-model pic -pic-level 2 -mframe-pointer=all -ffp-contract=on -fno-rounding-math -funwind-tables=2 -fcompatibility-qualified-id-block-type-checking -fvisibility-inlines-hidden-static-local-var -target-cpu penryn -tune-cpu generic -debugger-tuning=lldb -target-linker-version 1022.1 -fcoverage-compilation-dir=/Users/gen/home/Labo/InternalCompilerError -resource-dir /usr/local/Cellar/llvm/17.0.6_1/lib/clang/17 -std=c++23 -fdebug-compilation-dir=/Users/gen/home/Labo/InternalCompilerError -ferror-limit 19 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fmodule-file=MyVec:Vec=MyVec-Vec.pcm -fmodule-file=MyVec:Vec2=MyVec-Vec2.pcm -fmodule-file=MyVec:Type=MyVec-Type.pcm -fmax-type-align=16 -fcolor-diagnostics -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o Calculator.o -x pcm MyVec-Calculator.pcm
1.      <eof> parser at end of file
2.      /Users/gen/home/Labo/InternalCompilerError/Calculator.ccm:6:6: LLVM IR generation of declaration 'Calculate'
3.      /Users/gen/home/Labo/InternalCompilerError/Calculator.ccm:6:6: Generating code for declaration 'Calculate'
 #0 0x0000000122b35948 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/local/Cellar/llvm/17.0.6_1/lib/libLLVM.dylib+0x1c7e948)
 #1 0x00000001257146ea SignalHandler(int) (/usr/local/Cellar/llvm/17.0.6_1/lib/libLLVM.dylib+0x485d6ea)
 #2 0x00007ff80f64737d (/usr/lib/system/libsystem_platform.dylib+0x7ff80046937d)
 #3 0x0000000100000004 (/usr/local/Cellar/llvm/17.0.6_1/bin/clang-17+0xf1d8b004)
 #4 0x00000001134f0ad8 (anonymous namespace)::X86_64ABIInfo::computeInfo(clang::CodeGen::CGFunctionInfo&) const (.llvm.1432843204888195738) (/usr/local/Cellar/llvm/17.0.6_1/lib/libclang-cpp.dylib+0x25aad8)
 #5 0x000000011371f5c8 clang::CodeGen::CodeGenTypes::arrangeCXXMethodDeclaration(clang::CXXMethodDecl const*) (/usr/local/Cellar/llvm/17.0.6_1/lib/libclang-cpp.dylib+0x4895c8)
 #6 0x00000001142560f4 clang::CodeGen::CodeGenFunction::EmitCXXMemberOrOperatorMemberCallExpr(clang::CallExpr const*, clang::CXXMethodDecl const*, clang::CodeGen::ReturnValueSlot, bool, clang::NestedNameSpecifier*, bool, clang::Expr const*) (/usr/local/Cellar/llvm/17.0.6_1/lib/libclang-cpp.dylib+0xfc00f4)
 #7 0x00000001137390c2 clang::CodeGen::CodeGenFunction::EmitCallExpr(clang::CallExpr const*, clang::CodeGen::ReturnValueSlot) (/usr/local/Cellar/llvm/17.0.6_1/lib/libclang-cpp.dylib+0x4a30c2)
 #8 0x0000000114c0a15a (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) (.llvm.13750155672644761025) (/usr/local/Cellar/llvm/17.0.6_1/lib/libclang-cpp.dylib+0x197415a)
 #9 0x0000000114c77565 clang::CodeGen::CodeGenFunction::EmitReturnStmt(clang::ReturnStmt const&) (/usr/local/Cellar/llvm/17.0.6_1/lib/libclang-cpp.dylib+0x19e1565)
#10 0x0000000114c74927 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/usr/local/Cellar/llvm/17.0.6_1/lib/libclang-cpp.dylib+0x19de927)
#11 0x0000000114cb5fda clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/usr/local/Cellar/llvm/17.0.6_1/lib/libclang-cpp.dylib+0x1a1ffda)
#12 0x0000000113acafff clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/usr/local/Cellar/llvm/17.0.6_1/lib/libclang-cpp.dylib+0x834fff)
#13 0x0000000113ad3b26 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/usr/local/Cellar/llvm/17.0.6_1/lib/libclang-cpp.dylib+0x83db26)
#14 0x000000011378450d clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/usr/local/Cellar/llvm/17.0.6_1/lib/libclang-cpp.dylib+0x4ee50d)
#15 0x000000011432231f clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/usr/local/Cellar/llvm/17.0.6_1/lib/libclang-cpp.dylib+0x108c31f)
#16 0x000000011431af88 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (/usr/local/Cellar/llvm/17.0.6_1/lib/libclang-cpp.dylib+0x1084f88)
#17 0x0000000113ae663d (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) (/usr/local/Cellar/llvm/17.0.6_1/lib/libclang-cpp.dylib+0x85063d)
#18 0x00000001142fdf20 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/usr/local/Cellar/llvm/17.0.6_1/lib/libclang-cpp.dylib+0x1067f20)
#19 0x0000000113bdc140 clang::ASTReader::PassInterestingDeclsToConsumer() (/usr/local/Cellar/llvm/17.0.6_1/lib/libclang-cpp.dylib+0x946140)
#20 0x00000001160583ff non-virtual thunk to clang::ASTReader::StartTranslationUnit(clang::ASTConsumer*) (/usr/local/Cellar/llvm/17.0.6_1/lib/libclang-cpp.dylib+0x2dc23ff)
#21 0x00000001148dba6a clang::ParseAST(clang::Sema&, bool, bool) (/usr/local/Cellar/llvm/17.0.6_1/lib/libclang-cpp.dylib+0x1645a6a)
#22 0x00000001145d506d clang::FrontendAction::Execute() (/usr/local/Cellar/llvm/17.0.6_1/lib/libclang-cpp.dylib+0x133f06d)
#23 0x0000000113c12b42 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/local/Cellar/llvm/17.0.6_1/lib/libclang-cpp.dylib+0x97cb42)
#24 0x000000011460dab8 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/local/Cellar/llvm/17.0.6_1/lib/libclang-cpp.dylib+0x1377ab8)
#25 0x000000010e279b9b cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/local/Cellar/llvm/17.0.6_1/bin/clang-17+0x100004b9b)
#26 0x000000010e27eed3 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) (/usr/local/Cellar/llvm/17.0.6_1/bin/clang-17+0x100009ed3)
#27 0x000000010e27d893 clang_main(int, char**, llvm::ToolContext const&) (/usr/local/Cellar/llvm/17.0.6_1/bin/clang-17+0x100008893)
#28 0x000000010e289843 main (/usr/local/Cellar/llvm/17.0.6_1/bin/clang-17+0x100014843)
#29 0x00007ff80f28e386
clang++: error: unable to execute command: Segmentation fault: 11
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Homebrew clang version 17.0.6
Target: x86_64-apple-darwin23.2.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin
clang++: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang++: note: diagnostic msg: /var/folders/3d/3cl9czgd5c1b8nvtqw_tf4mh0000gp/T/Calculator-b08f2f.cppm
clang++: note: diagnostic msg: /var/folders/3d/3cl9czgd5c1b8nvtqw_tf4mh0000gp/T/Calculator-b08f2f.sh
clang++: note: diagnostic msg: Crash backtrace is located in
clang++: note: diagnostic msg: /Users/gen/Library/Logs/DiagnosticReports/clang-17_<YYYY-MM-DD-HHMMSS>_<hostname>.crash
clang++: note: diagnostic msg: (choose the .crash file that corresponds to your crash)
clang++: note: diagnostic msg:

********************

P.S.
I was able to reproduce this issue on Compiler Explorer (https://godbolt.org/z/7rYaE4jvz).

@gen740 gen740 changed the title clang Crashes under certain conditions on MacOS. Clang Crashes on Simple Module Project in MacOS. Jan 22, 2024
@gen740 gen740 changed the title Clang Crashes on Simple Module Project in MacOS. Clang Crashes on Simple Module Project in MacOS Jan 22, 2024
@EugeneZelenko EugeneZelenko added clang:modules C++20 modules and Clang Header Modules crash Prefer [crash-on-valid] or [crash-on-invalid] and removed clang Clang issues not falling into any other category labels Jan 22, 2024
@llvmbot
Copy link
Member

llvmbot commented Jan 22, 2024

@llvm/issue-subscribers-clang-modules

Author: Gen (gen740)

I created a C++20 modules project incorporating STL libraries, ranges and OpenMP, but it suddenly crashes. I've set up a minimum reproduction project at [gen740/InternalCompilerError](https://github.com/gen740/InternalCompilerError). (I couldn't minimize the issue further!)

The error message can be found here:
https://github.com/gen740/InternalCompilerError/actions/runs/7592379101/job/20681666596#step:7:33

I also confirmed that this issue occurs in the HEAD branch. However, I can't reproduce it on Compiler Explorer at https://godbolt.org/z/h8M1sq5zc.

@ChuanqiXu9 ChuanqiXu9 self-assigned this Jan 23, 2024
@ChuanqiXu9 ChuanqiXu9 changed the title Clang Crashes on Simple Module Project in MacOS [C++20] [Modules] Crash with inconsistent deduced type in two importing modules Jan 23, 2024
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

4 participants