-
Notifications
You must be signed in to change notification settings - Fork 37
Description
The following code causes a segfault in the compiler when compiled with -03. I would bet the issue has to deal with the exit in the cilk_for, but it seems to need some level of complexity to cause the issue, since when I tried deleting other random lines the crash went away.
#include <cilk/cilk.h>
#include <string>
int *get_edges_from_file(std::string filename, bool symetric) {
FILE *fp;
fp = fopen(filename.c_str(), "r");
size_t buf_size = 32;
char *line = (char *)malloc(buf_size);
int line_count = 0;
if (fp) {
while (getline(&line, &buf_size, fp) != -1) {
line_count++;
}
}
int *edges = (int *)malloc(32);
int num_nodes = 0;
cilk_for(int i = 0; i < line_count; i++) {
int elem_1;
sscanf(line, "%u", &elem_1);
num_nodes = std::max(num_nodes, elem_1);
if (num_nodes > 1000000000) {
printf("got num_nodes = %u, something is probably wrong\n", num_nodes);
printf("line: %s\n", line);
exit(-1);
}
if (symetric) {
edges[line_count+i] = elem_1;
}
}
return edges;
}
int main() {
}
The version of the compiler I am running on is
wheatman@ip-172-31-63-211:~$ /efs/tools/opencilk/llvm/bin/clang++ --version
clang version 9.0.1 (/EBS/mount/tfk/opencilk-project/clang c694fa66042cb0a50682641d8ce2560225f4c3c8)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /efs/tools/opencilk/llvm/bin
My full compile command is
/efs/tools/opencilk/llvm/bin/clang++ -fcilkplus -lcilkrts -O3 bug.cpp
The stack dump is
Stack dump: 0. Program arguments: /efs/tools/opencilk/llvm/bin/clang-9 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -disable-free -disable-llvm-verifier -discard-value-names -main-file-name bug.cpp -mrelocation-model static -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -resource-dir /efs/tools/opencilk/llvm/lib/clang/9.0.1 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/c++/7.4.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/x86_64-linux-gnu/c++/7.4.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/x86_64-linux-gnu/c++/7.4.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/c++/7.4.0/backward -internal-isystem /usr/local/include -internal-isystem /efs/tools/opencilk/llvm/lib/clang/9.0.1/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -fdeprecated-macro -fdebug-compilation-dir /efs/home/wheatman -ferror-limit 19 -fmessage-length 0 -fcilkplus -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -stripmine-loops -faddrsig -o /tmp/bug-de51eb.o -x c++ bug.cpp
<eof> parser at end of file 2. Per-module optimization passes 3. Running pass 'Function Pass Manager' on module 'bug.cpp'. 4. Running pass 'Value Propagation' on function '@_Z19get_edges_from_fileSsb' #0 0x000000000169f91a llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/efs/tools/opencilk/llvm/bin/clang-9+0x169f91a) #1 0x000000000169da1a llvm::sys::RunSignalHandlers() (/efs/tools/opencilk/llvm/bin/clang-9+0x169da1a) #2 0x000000000169db49 SignalHandler(int) (/efs/tools/opencilk/llvm/bin/clang-9+0x169db49) #3 0x00007fc3bdc77330 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x10330) #4 0x000000000110b714 llvm::BasicBlock::getModule() const (/efs/tools/opencilk/llvm/bin/clang-9+0x110b714) #5 0x0000000000c27735 llvm::LazyValueInfo::getConstantOnEdge(llvm::Value*, llvm::BasicBlock*, llvm::BasicBlock*, llvm::Instruction*) (/efs/tools/opencilk/llvm/bin/clang-9+0xc27735) #6 0x0000000001488384 runImpl(llvm::Function&, llvm::LazyValueInfo*, llvm::DominatorTree*, llvm::SimplifyQuery const&) (/efs/tools/opencilk/llvm/bin/clang-9+0x1488384) #7 0x000000000148a745 (anonymous namespace)::CorrelatedValuePropagation::runOnFunction(llvm::Function&) (/efs/tools/opencilk/llvm/bin/clang-9+0x148a745) #8 0x00000000011b566f llvm::FPPassManager::runOnFunction(llvm::Function&) (/efs/tools/opencilk/llvm/bin/clang-9+0x11b566f) #9 0x00000000011b5873 llvm::FPPassManager::runOnModule(llvm::Module&) (/efs/tools/opencilk/llvm/bin/clang-9+0x11b5873) #10 0x00000000011b6680 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/efs/tools/opencilk/llvm/bin/clang-9+0x11b6680) #11 0x00000000018a1a96 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::DataLayout const&, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >) (/efs/tools/opencilk/llvm/bin/clang-9+0x18a1a96) #12 0x00000000021d8d5b clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/efs/tools/opencilk/llvm/bin/clang-9+0x21d8d5b) #13 0x0000000002b62bc9 clang::ParseAST(clang::Sema&, bool, bool) (/efs/tools/opencilk/llvm/bin/clang-9+0x2b62bc9) #14 0x00000000021d7074 clang::CodeGenAction::ExecuteAction() (/efs/tools/opencilk/llvm/bin/clang-9+0x21d7074) #15 0x0000000001cee9a9 clang::FrontendAction::Execute() (/efs/tools/opencilk/llvm/bin/clang-9+0x1cee9a9) #16 0x0000000001cb5a90 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/efs/tools/opencilk/llvm/bin/clang-9+0x1cb5a90) #17 0x0000000001d8e684 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/efs/tools/opencilk/llvm/bin/clang-9+0x1d8e684) #18 0x000000000094441d cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/efs/tools/opencilk/llvm/bin/clang-9+0x94441d) #19 0x00000000008dc84f main (/efs/tools/opencilk/llvm/bin/clang-9+0x8dc84f) #20 0x00007fc3bcbfcf45 __libc_start_main /build/eglibc-oGUzwX/eglibc-2.19/csu/libc-start.c:321:0 #21 0x000000000094147a _start (/efs/tools/opencilk/llvm/bin/clang-9+0x94147a) clang-9: error: unable to execute command: Segmentation fault (core dumped) clang-9: error: clang frontend command failed due to signal (use -v to see invocation) clang version 9.0.1 (/EBS/mount/tfk/opencilk-project/clang c694fa66042cb0a50682641d8ce2560225f4c3c8) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /efs/tools/opencilk/llvm/bin clang-9: note: diagnostic msg: PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script. clang-9: note: diagnostic msg: ********************PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-9: note: diagnostic msg: /tmp/bug-f2a004.cpp
clang-9: note: diagnostic msg: /tmp/bug-f2a004.sh
clang-9: note: diagnostic msg:
The two requested files are
bug-f2a004.sh.txt
bug-f2a004.cpp.txt
The code looks nonsensical right now since I tried making minimal example by deleting or simplifying anything I could such that the compiler still crashed.