vgvassilev / clad

clad -- automatic differentiation for C/C++
GNU Lesser General Public License v3.0
291 stars 122 forks source link

Random crash during compilation #791

Open efeklisov opened 8 months ago

efeklisov commented 8 months ago

I'm trying to integrate CLAD in my project, but I get a seemingly random crash when I do so. CLAD is built from source

https://github.com/efeklisov/LiteRF-RadianceFields/blob/7934405fd2cbb58c12dc073a5aaba6439923bb01/example_tracer/example_tracer.cpp#L253

[ 25%] Building CXX object CMakeFiles/testapp.dir/example_tracer/example_tracer.cpp.o
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: /usr/bin/clang++-17 -DUSE_ENZYME -D_CRT_SECURE_NO_WARNINGS -I/home/egorf/LiteRF -I/home/egorf/LiteRF/external/LiteMath -I/home/egorf/LiteRF/./external/nlohmann -I/home/egorf/LiteRF/./external -I/home/egorf/LiteRF/. -Wno-attributes -O0 -fopenmp -I /home/egorf/clad/inst/include -fplugin=/home/egorf/clad/inst/lib/clad.so -fplugin=/home/egorf/LiteRF/enzyme/build/Enzyme/ClangEnzyme-17.so -MD -MT CMakeFiles/testapp.dir/example_tracer/example_tracer.cpp.o -MF CMakeFiles/testapp.dir/example_tracer/example_tracer.cpp.o.d -o CMakeFiles/testapp.dir/example_tracer/example_tracer.cpp.o -c /home/egorf/LiteRF/example_tracer/example_tracer.cpp
1.      /home/egorf/LiteRF/example_tracer/example_tracer.cpp:260:1: current parser token 'void'
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  libLLVM-17.so.1    0x00007fbdadacc406 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 54
1  libLLVM-17.so.1    0x00007fbdadaca5b0 llvm::sys::RunSignalHandlers() + 80
2  libLLVM-17.so.1    0x00007fbdada20d70
3  libc.so.6          0x00007fbdac642520
4  libclang-cpp.so.17 0x00007fbdb5d9bf0b
5  libclang-cpp.so.17 0x00007fbdb5dbba3e clang::Sema::buildOverloadedCallSet(clang::Scope*, clang::Expr*, clang::UnresolvedLookupExpr*, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::OverloadCandidateSet*, clang::ActionResult<clang::Expr*, true>*) + 110
6  clad.so            0x00007fbda9ef871a clad::DerivativeBuilder::noOverloadExists(clang::Expr*, llvm::MutableArrayRef<clang::Expr*>) + 488
7  clad.so            0x00007fbda9ef8e55 clad::DerivativeBuilder::BuildCallToCustomDerivativeOrNumericalDiff(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, llvm::SmallVectorImpl<clang::Expr*>&, clang::Scope*, clang::DeclContext*, bool, bool) + 1653
8  clad.so            0x00007fbdaa095d26 clad::ReverseModeVisitor::VisitCallExpr(clang::CallExpr const*) + 10510
9  clad.so            0x00007fbdaa07b7b8
10 clad.so            0x00007fbdaa078060
11 clad.so            0x00007fbdaa09cbd5 clad::ReverseModeVisitor::VisitImplicitCastExpr(clang::ImplicitCastExpr const*) + 89
12 clad.so            0x00007fbdaa07b940
13 clad.so            0x00007fbdaa078060
14 clad.so            0x00007fbdaa09b77e clad::ReverseModeVisitor::DifferentiateVarDecl(clang::VarDecl const*) + 2358
15 clad.so            0x00007fbdaa09c416 clad::ReverseModeVisitor::VisitDeclStmt(clang::DeclStmt const*) + 356
16 clad.so            0x00007fbdaa07a958
17 clad.so            0x00007fbdaa078060
18 clad.so            0x00007fbdaa09bfa7 clad::ReverseModeVisitor::DifferentiateSingleStmt(clang::Stmt const*, clang::Expr*) + 155
19 clad.so            0x00007fbdaa08f5fe clad::ReverseModeVisitor::VisitCompoundStmt(clang::CompoundStmt const*) + 338
20 clad.so            0x00007fbdaa07a8e8
21 clad.so            0x00007fbdaa078060
22 clad.so            0x00007fbdaa08deae clad::ReverseModeVisitor::DifferentiateWithClad() + 928
23 clad.so            0x00007fbdaa08cc6a clad::ReverseModeVisitor::Derive(clang::FunctionDecl const*, clad::DiffRequest const&) + 4158
24 clad.so            0x00007fbda9ef9776 clad::DerivativeBuilder::Derive(clad::DiffRequest const&) + 1606
25 clad.so            0x00007fbda9ee148f clad::plugin::CladPlugin::ProcessDiffRequest(clad::DiffRequest&) + 1383
26 clad.so            0x00007fbda9ee0c99 clad::plugin::CladPlugin::HandleTopLevelDecl(clang::DeclGroupRef) + 661
27 libclang-cpp.so.17 0x00007fbdb6d91d3c clang::MultiplexConsumer::HandleTopLevelDecl(clang::DeclGroupRef) + 44
28 libclang-cpp.so.17 0x00007fbdb50378ea clang::ParseAST(clang::Sema&, bool, bool) + 826
29 libclang-cpp.so.17 0x00007fbdb6d570c5 clang::FrontendAction::Execute() + 85
30 libclang-cpp.so.17 0x00007fbdb6cd26c4 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 708
31 libclang-cpp.so.17 0x00007fbdb6dd0e84 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 660
32 clang++-17         0x00005636d433c856 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) + 2454
33 clang++-17         0x00005636d433a3c5
34 libclang-cpp.so.17 0x00007fbdb6994c59
35 libLLVM-17.so.1    0x00007fbdada20b0c llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) + 140
36 libclang-cpp.so.17 0x00007fbdb699449e clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const + 366
37 libclang-cpp.so.17 0x00007fbdb695d40d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const + 877
38 libclang-cpp.so.17 0x00007fbdb695d66e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const + 142
39 libclang-cpp.so.17 0x00007fbdb69791ed clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) + 349
40 clang++-17         0x00005636d4339d2d clang_main(int, char**, llvm::ToolContext const&) + 11229
41 clang++-17         0x00005636d4346562 main + 50
42 libc.so.6          0x00007fbdac629d90
43 libc.so.6          0x00007fbdac629e40 __libc_start_main + 128
44 clang++-17         0x00005636d4336df5 _start + 37
clang++-17: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Ubuntu clang version 17.0.6 (++20231209124227+6009708b4367-1~exp1~20231209124336.77)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
clang++-17: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang++-17: note: diagnostic msg: /tmp/example_tracer-cd5b81.cpp
clang++-17: note: diagnostic msg: /tmp/example_tracer-cd5b81.sh
clang++-17: note: diagnostic msg: 

********************
make[2]: *** [CMakeFiles/testapp.dir/build.make:90: CMakeFiles/testapp.dir/example_tracer/example_tracer.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/testapp.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
vgvassilev commented 8 months ago

Can you attach the preprocessed files in /tmp/example_tracer-cd5b81.cpp and /tmp/example_tracer-cd5b81.sh. I see you are trying to use enzyme within clad. You can do that by using clad::gradient<clad::opts::use_enzyme>(...).

efeklisov commented 8 months ago

tmp.zip

I'm not really trying to mix them. It's just that Enzyme fails on me as well))