gecko-dev/xpcom/idl-parser
Mike Hommey d4175c7e4c Bug 1831467 - Avoid more UB from transmuting a ref to a ref with interior mutability. r=emilio, a=dsmith
aka one specific change in LLVM 16 introducing UB in Rust, take 3? 4?

This time, we have multiple types like:
  #[xpcom(implement(nsISomething))]
  struct Foo {
      foo: RefCell<Something>,
  }

  impl Foo {
      fn from_interface(obj: &nsISomething) -> &Self {
          unsafe { ::std::mem::transmute(obj) }
      }
  }

At first glance, this looks innocuous. But the problem is that
nsISomething, as far as LLVM is informed by Rust, is readonly,
but Foo, via the RefCell, has interious mutability.

LLVM ends up assuming that any mutability that happens to that returned
&Foo can't happen, and removes it.

This is yet another case where https://github.com/rust-lang/rust/issues/111229
would save our feet from this footgun LLVM 16 added and that the rust
compiler doesn't help us prevent the least.

Differential Revision: https://phabricator.services.mozilla.com/D183569
***
Bug 1831467 fix comment a=dsmith
2023-07-17 11:38:56 -04:00
..
xpidl Bug 1831467 - Avoid more UB from transmuting a ref to a ref with interior mutability. r=emilio, a=dsmith 2023-07-17 11:38:56 -04:00
setup.py Bug 1790816 - Reformat xpcom/ with isort. r=mccr8 DONTBUILD 2022-11-22 13:37:48 +00:00