Detect/log/recover mismatch between expression and nullability vector

The nullability vector for an expr is supposed to match that expr's type.
If not, it's meaningless because we can't correspond entries to PointerTypes.
This requires various places that manipulate nullability vectors to be in sync,
but they very often go out of sync e.g. due to unhandled nodes.
Currently this mostly results in the contents being misinterpreted in arbitrary
ways.

Often (not always!) we can detect this as a nullability vector with the wrong
length. For now this is way too common for us to CHECK, but we can log the error
and continue by discarding all nullability info.

Logs look like:

	[ RUN      ] PointerNullabilityTest.NonNullPtrImplicitCastToBool
	=== Bad computed nullability: ===
	Expression:
	ImplicitCastExpr 0x172fbf641688 '_Bool' <PointerToBoolean>
	`-ImplicitCastExpr 0x172fbf641670 'int * _Nonnull':'int *' <LValueToRValue>
	  `-DeclRefExpr 0x172fbf641650 'int * _Nonnull':'int *' lvalue ParmVar 0x172fbf641410 'x' 'int * _Nonnull':'int *'

	Nullability (1 pointers): [_Nonnull]

	Type (0 pointers):
	BuiltinType 0x172fbfdea5d0 '_Bool'
	=================================
	=== Bad computed nullability: ===
	Expression:
	ImplicitCastExpr 0x172fbf73c908 '_Bool' <PointerToBoolean>
	`-ImplicitCastExpr 0x172fbf73c8f0 'int * _Nonnull':'int *' <LValueToRValue>
	  `-DeclRefExpr 0x172fbf73c8d0 'int * _Nonnull':'int *' lvalue ParmVar 0x172fbf73c690 'x' 'int * _Nonnull':'int *'

	Nullability (1 pointers): [_Nonnull]

	Type (0 pointers):
	BuiltinType 0x172fbf60aad0 '_Bool'
	=================================
	[       OK ] PointerNullabilityTest.NonNullPtrImplicitCastToBool (13 ms)

PiperOrigin-RevId: 502833813
5 files changed
tree: 8dbb54ba883d33e0ba0432378eaa9fafa5529a9c
  1. .bazelci/
  2. bazel/
  3. cc_bindings_from_rs/
  4. cc_import/
  5. cc_template/
  6. common/
  7. docs/
  8. lifetime_analysis/
  9. lifetime_annotations/
  10. migrator/
  11. nullability_verification/
  12. rs_bindings_from_cc/
  13. support/
  14. .bazelrc
  15. .gitignore
  16. BUILD
  17. Cargo.Bazel.lock
  18. CODE_OF_CONDUCT
  19. CONTRIBUTING
  20. LICENSE
  21. README.md
  22. WORKSPACE
README.md

Crubit: C++/Rust Bidirectional Interop Tool

Build status

Extremely experimental interop tooling for C++ and Rust.

Please don‘t use, this is an experiment and we don’t yet know where will it take us. There will be breaking changes without warning. Unfortunately, we can't take contributions at this point.

Building Crubit

$ apt install clang lld bazel
$ git clone git@github.com:google/crubit.git
$ cd crubit
$ bazel build --linkopt=-fuse-ld=/usr/bin/ld.lld //rs_bindings_from_cc:rs_bindings_from_cc_impl

Using a prebuilt LLVM tree

$ git clone https://github.com/llvm/llvm-project
$ cd llvm-project
$ CC=clang CXX=clang++ cmake -S llvm -B build -DLLVM_ENABLE_PROJECTS='clang' -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=install
$ cmake --build build -j
$ # wait...
$ cmake --install build
$ cd ../crubit
$ LLVM_INSTALL_PATH=../llvm-project/install bazel build //rs_bindings_from_cc:rs_bindings_from_cc_impl