Crash with `llvm-15` + exporting a new libc++ std::string
Hi, and thanks for taking a look! :)
Input C/C++ Header
template <class _Allocator> struct __attribute__Trans_NS___1_basic_string {
int : sizeof(_Allocator);
};
Bindgen Invocation
bindgen::Builder::default()
.allowlist_type(".*")
.header("wrapper.hpp")
.generate()
.expect("Generating bindings");
or
Actual Results
Unfortunately, I can't get a backtrace (I presume this is because the crash is in LLVM), but I can give an assertion failure:
(build-script-build: /usr/local/google/home/gbiv/llvm/bindgen/clang/lib/AST/ExprConstant.cpp:15104: llvm::APSInt clang::Expr::EvaluateKnownConstInt(const clang::ASTContext &, SmallVectorImpl<clang::PartialDiagnosticAt> *) const: Assertion `!isValueDependent() && "Expression evaluator can't be called on a dependent expression."' failed)
Expected Results
I'm not sure, actually :)
The reduced code is a part of libc++'s string implementation, apparently as of somewhat-recently. I'm trying to figure out whether an existing project's use of allowlist_type("std::string") is intended to be supported or not.
For what it's worth, it seems the crash with the reduced header only starts happening at llvm/llvm-project@a2601c98873376bbbeff4b6eddf0f4d920535f8b (the version 15 bump). My invocations for use with my local LLVM builds look like:
$ env RUST_BACKTRACE=1 LLVM_CONFIG_PATH=$HOME/llvm/bindgen/build/release/bin/llvm-config LIBCLANG_STATIC_PATH=$HOME/llvm/bindgen/build/release/lib/ cargo build
At LLVM's a2601c98873376bbbeff4b6eddf0f4d920535f8b~, the invocation above exits successfully. I haven't looked into how static library selection is done, so I did rm -rf $HOME/llvm/bindgen/build/release/lib/libclang* between builds in hopes of removing old versioned artifacts.
I have the same issue (found while trying to compile Firefox). I got a backtrace with gdb:
#0 0x0000677f222ffab0 in memcpy () from /lib/ld-musl-x86_64.so.1
#1 0x0000677f1ff2f6c3 in clang::Expr::EvaluateKnownConstInt(clang::ASTContext const&, llvm::SmallVectorImpl<std::__1::pair<clang::SourceLocation, clang::PartialDiagnostic> >*) const ()
from /usr/lib/libclang.so.15.0.0
#2 0x0000677f1febd84e in clang::FieldDecl::getBitWidthValue(clang::ASTContext const&) const () from /usr/lib/libclang.so.15.0.0
#3 0x0000049eb7005b5f in clang_sys::clang_getFieldDeclBitWidth ()
#4 0x0000049eb6f12d20 in _ZN7bindgen5clang14visit_children17hb80508fbcfe36966E.llvm.15050955147846127459 ()
#5 0x0000677f1fdb111d in clang::cxcursor::CursorVisitor::handleDeclForVisitation(clang::Decl const*) () from /usr/lib/libclang.so.15.0.0
#6 0x0000677f1fdb2068 in clang::cxcursor::CursorVisitor::VisitCXXRecordDecl(clang::CXXRecordDecl*) () from /usr/lib/libclang.so.15.0.0
#7 0x0000677f1fdaf9a6 in clang::cxcursor::CursorVisitor::VisitChildren(CXCursor) () from /usr/lib/libclang.so.15.0.0
#8 0x0000677f1fdbe7ae in clang_visitChildren () from /usr/lib/libclang.so.15.0.0
#9 0x0000049eb700672f in clang_sys::clang_visitChildren ()
#10 0x0000049eb6f33185 in bindgen::ir::comp::CompInfo::from_ty ()
#11 0x0000049eb6eee38b in bindgen::ir::ty::Type::from_clang_ty ()
#12 0x0000049eb6f0d203 in <bindgen::ir::item::Item as bindgen::parse::ClangItemParser>::from_ty_with_id ()
#13 0x0000049eb6f0c2de in <bindgen::ir::item::Item as bindgen::parse::ClangItemParser>::from_ty ()
#14 0x0000049eb6f0b4ea in <bindgen::ir::item::Item as bindgen::parse::ClangItemParser>::parse ()
#15 0x0000049eb6f12a70 in _ZN7bindgen5clang14visit_children17hb1d7b1b3b70414c7E.llvm.15050955147846127459 ()
#16 0x0000677f1fdb111d in clang::cxcursor::CursorVisitor::handleDeclForVisitation(clang::Decl const*) () from /usr/lib/libclang.so.15.0.0
#17 0x0000677f1fdb1288 in clang::cxcursor::CursorVisitor::VisitDeclContext(clang::DeclContext*) () from /usr/lib/libclang.so.15.0.0
#18 0x0000677f1fdafccd in clang::cxcursor::CursorVisitor::VisitChildren(CXCursor) () from /usr/lib/libclang.so.15.0.0
#19 0x0000677f1fdbe7ae in clang_visitChildren () from /usr/lib/libclang.so.15.0.0
#20 0x0000049eb700672f in clang_sys::clang_visitChildren ()
#21 0x0000049eb6ed9dc1 in bindgen::Builder::generate ()
#22 0x0000049eb6ece035 in bindgen_crash::main ()
#23 0x0000049eb6ecc493 in _ZN3std2rt10lang_start28_$u7b$$u7b$closure$u7d$$u7d$17h29c51ea36b0d6efbE.llvm.11762056675201810433 ()
#24 0x0000049eb7038522 in std::rt::lang_start_internal ()
#25 0x0000049eb6ece998 in main ()
EDIT: This might be a duplicate of https://github.com/rust-lang/rust-bindgen/issues/2239. I no longer have the crash after I update to the latest commit ( 61636e94ca315278d9ac5f1210ffca6cca697428).
Good catch, @greg904 :)
I'll ask folks to verify whether #2239's PR fixes this on our side, and close if so.
Yeah, looks like that fixes things. Closing this out; thanks again!
How far are we from a release containing the fix for this?