OpenCilk / opencilk-project

Monorepo for the OpenCilk compiler. Forked from llvm/llvm-project and based on Tapir/LLVM.
Other
89 stars 29 forks source link

cilk for with loop index variable being a templated type crashes #220

Closed wheatman closed 7 months ago

wheatman commented 9 months ago

Describe the bug

compiler crash on clang version 16.0.6 (https://github.com/OpenCilk/opencilk-project aa4f4c0c6a59a9e42c3ef8cc8ef715f5ed8b7553)that did not exist on clang version 14.0.6 (https://github.com/OpenCilk/opencilk-project f54e98722992462e042f0686c74f710277c92cdb)

The following code causes a crash


#include <cilk/cilk.h>

template <class index_t> void foo() {
  cilk_for(index_t row = 0; row < 1024; row++) { void; }
}

int main() { foo<int>(); }

when compiled with

opencilk16/build/bin/clang++  -std=c++20   -fopencilk  -o test test.cpp

Expected behavior

For the program to compile successfully

OpenCilk version

clang version 16.0.6 (https://github.com/OpenCilk/opencilk-project aa4f4c0c6a59a9e42c3ef8cc8ef715f5ed8b7553) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /home/wheatman/opencilk16/build/bin

The crash dump is

test.cpp:5:50: warning: declaration does not declare anything [-Wmissing-declarations]
  cilk_for(index_t row = 0; row < 1024; row++) { void; }
                                                 ^~~~
Unknown builtin type!
UNREACHABLE executed at /home/wheatman/opencilk16/clang/lib/AST/ASTContext.cpp:2042!
PLEASE submit a bug report to https://github.com/OpenCilk/opencilk-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: /home/wheatman/opencilk16/build/bin/clang-16 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -clear-ast-before-backend -main-file-name test.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=/home/wheatman/MM -resource-dir /home/wheatman/opencilk16/build/lib/clang/16 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/x86_64-linux-gnu/c++/11 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/backward -internal-isystem /home/wheatman/opencilk16/build/lib/clang/16/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=c++20 -fdeprecated-macro -fdebug-compilation-dir=/home/wheatman/MM -ferror-limit 19 -fopencilk --opencilk-abi-bitcode=/home/wheatman/opencilk16/build/lib/clang/16/lib/x86_64-unknown-linux-gnu/libopencilk-abi.bc -fgnuc-version=4.2.1 -fno-implicit-modules -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/test-8f675f.o -x c++ test.cpp
1.      <eof> parser at end of file
2.      Per-file LLVM IR generation
3.      test.cpp:4:31: Generating code for declaration 'foo'
 #0 0x0000557de7817c47 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/wheatman/opencilk16/build/bin/clang-16+0x25cac47)
 #1 0x0000557de7815afe llvm::sys::RunSignalHandlers() (/home/wheatman/opencilk16/build/bin/clang-16+0x25c8afe)
 #2 0x0000557de781843a SignalHandler(int) Signals.cpp:0:0
 #3 0x00007f65cbbee520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007f65cbc429fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x00007f65cbc429fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #6 0x00007f65cbc429fc pthread_kill ./nptl/pthread_kill.c:89:10
 #7 0x00007f65cbbee476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x00007f65cbbd47f3 abort ./stdlib/abort.c:81:7
 #9 0x0000557de77a44c1 (/home/wheatman/opencilk16/build/bin/clang-16+0x25574c1)
#10 0x0000557dea3fa18a (/home/wheatman/opencilk16/build/bin/clang-16+0x51ad18a)
#11 0x0000557dea3faf14 clang::ASTContext::getTypeInfo(clang::Type const*) const (/home/wheatman/opencilk16/build/bin/clang-16+0x51adf14)
#12 0x0000557dea3fa53b clang::ASTContext::getPreferredTypeAlign(clang::Type const*) const (/home/wheatman/opencilk16/build/bin/clang-16+0x51ad53b)
#13 0x0000557dea3f87ef clang::ASTContext::getDeclAlign(clang::Decl const*, bool) const (/home/wheatman/opencilk16/build/bin/clang-16+0x51ab7ef)
#14 0x0000557de7f6ea82 clang::CodeGen::CodeGenFunction::EmitAutoVarAlloca(clang::VarDecl const&) (/home/wheatman/opencilk16/build/bin/clang-16+0x2d21a82)
#15 0x0000557de7f6af56 clang::CodeGen::CodeGenFunction::EmitVarDecl(clang::VarDecl const&) (/home/wheatman/opencilk16/build/bin/clang-16+0x2d1df56)
#16 0x0000557de7f6aa8d clang::CodeGen::CodeGenFunction::EmitDecl(clang::Decl const&) (/home/wheatman/opencilk16/build/bin/clang-16+0x2d1da8d)
#17 0x0000557de7ca24ac clang::CodeGen::CodeGenFunction::EmitDeclStmt(clang::DeclStmt const&) (/home/wheatman/opencilk16/build/bin/clang-16+0x2a554ac)
#18 0x0000557de7c9647d clang::CodeGen::CodeGenFunction::EmitSimpleStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/home/wheatman/opencilk16/build/bin/clang-16+0x2a4947d)
#19 0x0000557de7c957f1 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/home/wheatman/opencilk16/build/bin/clang-16+0x2a487f1)
#20 0x0000557de7f1c791 clang::CodeGen::CodeGenFunction::EmitCilkForStmt(clang::CilkForStmt const&, llvm::ArrayRef<clang::Attr const*>) (/home/wheatman/opencilk16/build/bin/clang-16+0x2ccf791)
#21 0x0000557de7ca3690 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/home/wheatman/opencilk16/build/bin/clang-16+0x2a56690)
#22 0x0000557de7d0943b clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/home/wheatman/opencilk16/build/bin/clang-16+0x2abc43b)
#23 0x0000557de7d30a18 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/home/wheatman/opencilk16/build/bin/clang-16+0x2ae3a18)
#24 0x0000557de7d28c9d clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/home/wheatman/opencilk16/build/bin/clang-16+0x2adbc9d)
#25 0x0000557de7d187f0 clang::CodeGen::CodeGenModule::EmitDeferred() (/home/wheatman/opencilk16/build/bin/clang-16+0x2acb7f0)
#26 0x0000557de7d1624e clang::CodeGen::CodeGenModule::Release() (/home/wheatman/opencilk16/build/bin/clang-16+0x2ac924e)
#27 0x0000557de89c4914 (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) ModuleBuilder.cpp:0:0
#28 0x0000557de89c127e clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/home/wheatman/opencilk16/build/bin/clang-16+0x377427e)
#29 0x0000557de97b96c0 clang::ParseAST(clang::Sema&, bool, bool) (/home/wheatman/opencilk16/build/bin/clang-16+0x456c6c0)
#30 0x0000557de835ed10 clang::FrontendAction::Execute() (/home/wheatman/opencilk16/build/bin/clang-16+0x3111d10)
#31 0x0000557de82cfdff clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/wheatman/opencilk16/build/bin/clang-16+0x3082dff)
#32 0x0000557de84331c3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/wheatman/opencilk16/build/bin/clang-16+0x31e61c3)
#33 0x0000557de61ed367 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/wheatman/opencilk16/build/bin/clang-16+0xfa0367)
#34 0x0000557de61e9a6b ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#35 0x0000557de61e9426 clang_main(int, char**) (/home/wheatman/opencilk16/build/bin/clang-16+0xf9c426)
#36 0x00007f65cbbd5d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#37 0x00007f65cbbd5e40 call_init ./csu/../csu/libc-start.c:128:20
#38 0x00007f65cbbd5e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#39 0x0000557de61e5bf5 _start (/home/wheatman/opencilk16/build/bin/clang-16+0xf98bf5)
clang-16: error: unable to execute command: Aborted
clang-16: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 16.0.6 (https://github.com/OpenCilk/opencilk-project aa4f4c0c6a59a9e42c3ef8cc8ef715f5ed8b7553)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/wheatman/opencilk16/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/test-4d2e8c.cpp
clang-16: note: diagnostic msg: /tmp/test-4d2e8c.sh
clang-16: note: diagnostic msg: 

********************
neboat commented 7 months ago

A fix for this crash is included in the latest release.