Segfault using pybind datatypes
- Dominant language
- LLVM
- Stars
- 1.7k
- Forks
- 188
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 22
Description
Enzyme segfaults and yield following error on trying to compile a function using pybind11/Python datatypes. Portion of error message is posted at the bottom.
The offending piece of code is I believe a python datatype
```C++
typedef struct _object {
_PyObject_HEAD_EXTRA
Py_ssize_t ob_refcnt;
PyTypeObject *ob_type;
} PyObject;
```
Where enzyme cant determine `Py_ssize_t` type integer (alias for sstize_t)?
Will try to reproduce in simpler example.
```
could not deduce type of integer %2 = getelementptr inbounds %struct._object, %struct._object* %0, i32 0, i32 0, !dbg !127191 num:8 q:{[]:Pointer}
In file included from /home/amit/Projects/ext/cm.cpp:15:
In file included from /home/amit/Projects/ext/cm.h:21:
In file included from /usr/include/pybind11/numpy.h:12:
In file included from /usr/include/pybind11/pybind11.h:44:
In file included from /usr/include/pybind11/detail/../attr.h:13:
In file included from /usr/include/pybind11/cast.h:13:
In file included from /usr/include/pybind11/detail/../pytypes.h:12:
In file included from /usr/include/pybind11/detail/common.h:112:
In file included from /opt/python39/install/include/python3.9/Python.h:81:
In file included from /opt/python39/install/include/python3.9/pytime.h:6:
/opt/python39/install/include/python3.9/object.h:422:15: warning: failed to deduce type of value %2 = getelementptr inbounds %struct._object, %struct._object* %0, i32 0, i32 0, !dbg !127191 [-Wpass-failed=enzyme]
if (--op->ob_refcnt != 0) {
^
clang++: ../Enzyme/TypeAnalysis/TypeAnalysis.cpp:4959: ConcreteType TypeResults::firstPointer(size_t, llvm::Value *, bool, bool): Assertion `0 && "could not deduce type of integer"' failed.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: /opt/llvm_12/clang_12_prebuilt/bin/clang++ -Dext_EXPORTS -I/home/amit/Projects/dependencies/eigen -I/opt/python39/install/include/python3.9 -g -fPIC -fvisibility=hidden -Xclang -load -Xclang /opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so -std=gnu++14 -MD -MT CMakeFiles/ext.dir/cm.cpp.o -MF CMakeFiles/ext.dir/cm.cpp.o.d -o CMakeFiles/ext.dir/cm.cpp.o -c /home/amit/Projects/ext/cm.cpp
1. parser at end of file
2. Per-module optimization passes
3. Running pass 'Enzyme Pass' on module '/home/amit/Projects/ext/cm.cpp'.
#0 0x00000000024c18a3 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/llvm_12/clang_12_prebuilt/bin/clang+++0x24c18a3)
#1 0x00000000024bf7ee llvm::sys::RunSignalHandlers() (/opt/llvm_12/clang_12_prebuilt/bin/clang+++0x24bf7ee)
#2 0x00000000024c0d5d llvm::sys::CleanupOnSignal(unsigned long) (/opt/llvm_12/clang_12_prebuilt/bin/clang+++0x24c0d5d)
#3 0x000000000244d170 CrashRecoverySignalHandler(int) (/opt/llvm_12/clang_12_prebuilt/bin/clang+++0x244d170)
#4 0x00007f29026e63c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x143c0)
#5 0x00007f29021c503b raise /build/glibc-sMfBJT/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
#6 0x00007f29021a4859 abort /build/glibc-sMfBJT/glibc-2.31/stdlib/abort.c:81:7
#7 0x00007f29021a4729 get_sysdep_segment_value /build/glibc-sMfBJT/glibc-2.31/intl/loadmsgcat.c:509:8
#8 0x00007f29021a4729 _nl_load_domain /build/glibc-sMfBJT/glibc-2.31/intl/loadmsgcat.c:970:34
#9 0x00007f29021b6006 (/lib/x86_64-linux-gnu/libc.so.6+0x34006)
#10 0x00007f2901f82a74 TypeResults::firstPointer(unsigned long, llvm::Value*, bool, bool) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x7f0a74)
#11 0x00007f2901e1870a AdjointGenerator::visitCommonStore(llvm::Instruction&, llvm::Value*, llvm::Value*, llvm::MaybeAlign, bool, llvm::AtomicOrdering, unsigned char, llvm::Value*) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x68670a)
#12 0x00007f2901e18361 AdjointGenerator::visitStoreInst(llvm::StoreInst&) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x686361)
#13 0x00007f2901e093ed llvm::InstVisitor, void>::visitStore(llvm::StoreInst&) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x6773ed)
#14 0x00007f2901e08b5c llvm::InstVisitor, void>::visit(llvm::Instruction&) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x676b5c)
#15 0x00007f2901d3a06d llvm::InstVisitor, void>::visit(llvm::Instruction*) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x5a806d)
#16 0x00007f2901d1fe65 EnzymeLogic::CreatePrimalAndGradient(ReverseCacheKey const&&, TypeAnalysis&, AugmentedReturn const*, bool) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x58de65)
#17 0x00007f2901e35676 AdjointGenerator::visitCallInst(llvm::CallInst&) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x6a3676)
#18 0x00007f2901e1ab4b llvm::InstVisitor, void>::delegateCallInst(llvm::CallInst&) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x688b4b)
#19 0x00007f2901e0983d llvm::InstVisitor, void>::visitCall(llvm::CallInst&) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x67783d)
#20 0x00007f2901e08cfa llvm::InstVisitor, void>::visit(llvm::Instruction&) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x676cfa)
#21 0x00007f2901d3a06d llvm::InstVisitor, void>::visit(llvm::Instruction*) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x5a806d)
#22 0x00007f2901d1fe65 EnzymeLogic::CreatePrimalAndGradient(ReverseCacheKey const&&, TypeAnalysis&, AugmentedReturn const*, bool) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x58de65)
#23 0x00007f2901e35676 AdjointGenerator::visitCallInst(llvm::CallInst&) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x6a3676)
#24 0x00007f2901e1ab4b llvm::InstVisitor, void>::delegateCallInst(llvm::CallInst&) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x688b4b)
#25 0x00007f2901e0983d llvm::InstVisitor, void>::visitCall(llvm::CallInst&) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x67783d)
#26 0x00007f2901e08cfa llvm::InstVisitor, void>::visit(llvm::Instruction&) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x676cfa)
#27 0x00007f2901d3a06d llvm::InstVisitor, void>::visit(llvm::Instruction*) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x5a806d)
#28 0x00007f2901d1fe65 EnzymeLogic::CreatePrimalAndGradient(ReverseCacheKey const&&, TypeAnalysis&, AugmentedReturn const*, bool) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x58de65)
#29 0x00007f2901e35676 AdjointGenerator::visitCallInst(llvm::CallInst&) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x6a3676)
#30 0x00007f2901e1ab4b llvm::InstVisitor, void>::delegateCallInst(llvm::CallInst&) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x688b4b)
#31 0x00007f2901e0983d llvm::InstVisitor, void>::visitCall(llvm::CallInst&) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x67783d)
#32 0x00007f2901e08cfa llvm::InstVisitor, void>::visit(llvm::Instruction&) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x676cfa)
#33 0x00007f2901d3a06d llvm::InstVisitor, void>::visit(llvm::Instruction*) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x5a806d)
#34 0x00007f2901d1fe65 EnzymeLogic::CreatePrimalAndGradient(ReverseCacheKey const&&, TypeAnalysis&, AugmentedReturn const*, bool) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x58de65)
#35 0x00007f2901e35676 AdjointGenerator::visitCallInst(llvm::CallInst&) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x6a3676)
#36 0x00007f2901e1ab4b llvm::InstVisitor, void>::delegateCallInst(llvm::CallInst&) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x688b4b)
#37 0x00007f2901e0983d llvm::InstVisitor, void>::visitCall(llvm::CallInst&) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x67783d)
#38 0x00007f2901e08cfa llvm::InstVisitor, void>::visit(llvm::Instruction&) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x676cfa)
#39 0x00007f2901d3a06d llvm::InstVisitor, void>::visit(llvm::Instruction*) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x5a806d)
#40 0x00007f2901d1fe65 EnzymeLogic::CreatePrimalAndGradient(ReverseCacheKey const&&, TypeAnalysis&, AugmentedReturn const*, bool) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x58de65)
#41 0x00007f2901e35676 AdjointGenerator::visitCallInst(llvm::CallInst&) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x6a3676)
#42 0x00007f2901e1ab4b llvm::InstVisitor, void>::delegateCallInst(llvm::CallInst&) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x688b4b)
#43 0x00007f2901e0983d llvm::InstVisitor, void>::visitCall(llvm::CallInst&) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x67783d)
#44 0x00007f2901e08cfa llvm::InstVisitor, void>::visit(llvm::Instruction&) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x676cfa)
#45 0x00007f2901d3a06d llvm::InstVisitor, void>::visit(llvm::Instruction*) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x5a806d)
#46 0x00007f2901d1fe65 EnzymeLogic::CreatePrimalAndGradient(ReverseCacheKey const&&, TypeAnalysis&, AugmentedReturn const*, bool) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x58de65)
#47 0x00007f2901e35676 AdjointGenerator::visitCallInst(llvm::CallInst&) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x6a3676)
#48 0x00007f2901e1ab4b llvm::InstVisitor, void>::delegateCallInst(llvm::CallInst&) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x688b4b)
#49 0x00007f2901e0983d llvm::InstVisitor, void>::visitCall(llvm::CallInst&) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x67783d)
#50 0x00007f2901e08cfa llvm::InstVisitor, void>::visit(llvm::Instruction&) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x676cfa)
#51 0x00007f2901d3a06d llvm::InstVisitor, void>::visit(llvm::Instruction*) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x5a806d)
#52 0x00007f2901d1fe65 EnzymeLogic::CreatePrimalAndGradient(ReverseCacheKey const&&, TypeAnalysis&, AugmentedReturn const*, bool) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x58de65)
#53 0x00007f2901e35676 AdjointGenerator::visitCallInst(llvm::CallInst&) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x6a3676)
#54 0x00007f2901e1ab4b llvm::InstVisitor, void>::delegateCallInst(llvm::CallInst&) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x688b4b)
#55 0x00007f2901e0983d llvm::InstVisitor, void>::visitCall(llvm::CallInst&) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x67783d)
#56 0x00007f2901e08cfa llvm::InstVisitor, void>::visit(llvm::Instruction&) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x676cfa)
#57 0x00007f2901d3a06d llvm::InstVisitor, void>::visit(llvm::Instruction*) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x5a806d)
#58 0x00007f2901d1fe65 EnzymeLogic::CreatePrimalAndGradient(ReverseCacheKey const&&, TypeAnalysis&, AugmentedReturn const*, bool) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x58de65)
#59 0x00007f2901ceeebc (anonymous namespace)::Enzyme::HandleAutoDiff(llvm::CallInst*, llvm::TargetLibraryInfo&, DerivativeMode, bool) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x55cebc)
#60 0x00007f2901cebadb (anonymous namespace)::Enzyme::lowerEnzymeCalls(llvm::Function&, bool&, std::set, std::allocator >&) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x559adb)
#61 0x00007f2901ce625e (anonymous namespace)::Enzyme::runOnModule(llvm::Module&) (/opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so+0x55425e)
#62 0x0000000001e6d08f llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/llvm_12/clang_12_prebuilt/bin/clang+++0x1e6d08f)
#63 0x000000000269d3b5 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 >) (/opt/llvm_12/clang_12_prebuilt/bin/clang+++0x269d3b5)
#64 0x000000000319415f clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/llvm_12/clang_12_prebuilt/bin/clang+++0x319415f)
#65 0x0000000002c1e8ec clang::MultiplexConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/llvm_12/clang_12_prebuilt/bin/clang+++0x2c1e8ec)
#66 0x0000000003be7554 clang::ParseAST(clang::Sema&, bool, bool) (/opt/llvm_12/clang_12_prebuilt/bin/clang+++0x3be7554)
#67 0x0000000002bea627 clang::FrontendAction::Execute() (/opt/llvm_12/clang_12_prebuilt/bin/clang+++0x2bea627)
#68 0x0000000002b75151 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/llvm_12/clang_12_prebuilt/bin/clang+++0x2b75151)
#69 0x0000000002c7f38c clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/llvm_12/clang_12_prebuilt/bin/clang+++0x2c7f38c)
#70 0x0000000000a06e72 cc1_main(llvm::ArrayRef, char const*, void*) (/opt/llvm_12/clang_12_prebuilt/bin/clang+++0xa06e72)
#71 0x0000000000a056b7 ExecuteCC1Tool(llvm::SmallVectorImpl&) (/opt/llvm_12/clang_12_prebuilt/bin/clang+++0xa056b7)
#72 0x0000000002a39b12 void llvm::function_ref::callback_fn >, std::__cxx11::basic_string, std::allocator >*, bool*) const::$_1>(long) (/opt/llvm_12/clang_12_prebuilt/bin/clang+++0x2a39b12)
#73 0x000000000244cf5d llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/llvm_12/clang_12_prebuilt/bin/clang+++0x244cf5d)
#74 0x0000000002a394b9 clang::driver::CC1Command::Execute(llvm::ArrayRef >, std::__cxx11::basic_string, std::allocator >*, bool*) const (/opt/llvm_12/clang_12_prebuilt/bin/clang+++0x2a394b9)
#75 0x0000000002a0941d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&) const (/opt/llvm_12/clang_12_prebuilt/bin/clang+++0x2a0941d)
#76 0x0000000002a09667 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl >&) const (/opt/llvm_12/clang_12_prebuilt/bin/clang+++0x2a09667)
#77 0x0000000002a21208 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl >&) (/opt/llvm_12/clang_12_prebuilt/bin/clang+++0x2a21208)
#78 0x0000000000a0506d main (/opt/llvm_12/clang_12_prebuilt/bin/clang+++0xa0506d)
#79 0x00007f29021a60b3 __libc_start_main /build/glibc-sMfBJT/glibc-2.31/csu/../csu/libc-start.c:342:3
#80 0x0000000000a023d9 _start (/opt/llvm_12/clang_12_prebuilt/bin/clang+++0xa023d9)
clang-12: error: clang frontend command failed with exit code 134 (use -v to see invocation)
clang version 12.0.1
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/llvm_12/clang_12_prebuilt/bin
```
Contributor guide
Assessment
This issue has not been assessed yet.