diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-01-09 00:22:05 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-09 00:22:05 +0100 |
| commit | 60bef14bbc030f4b129de4967e5a9302067d1712 (patch) | |
| tree | 5e991335c214dcb0f20c8c873a34940c44b5e335 /src | |
| parent | caa231d998a5e853c7ba1455d7a05b500df9d63c (diff) | |
| parent | 097e14d19d6b74ab0a37846ae323862ace6ac259 (diff) | |
| download | rust-60bef14bbc030f4b129de4967e5a9302067d1712.tar.gz rust-60bef14bbc030f4b129de4967e5a9302067d1712.zip | |
Rollup merge of #67630 - oli-obk:extern_ptr_dangling, r=spastorino
Treat extern statics just like statics in the "const pointer to static" representation fixes #67612 r? @spastorino cc @RalfJung this does not affect runtime promotion at all. This is just about promotion within static item bodies.
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/ty/util.rs | 2 | ||||
| -rw-r--r-- | src/test/mir-opt/const-promotion-extern-static.rs | 71 |
2 files changed, 71 insertions, 2 deletions
diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs index aa93f35661a..ddff8258c6d 100644 --- a/src/librustc/ty/util.rs +++ b/src/librustc/ty/util.rs @@ -533,8 +533,6 @@ impl<'tcx> TyCtxt<'tcx> { if self.is_mutable_static(def_id) { self.mk_mut_ptr(static_ty) - } else if self.is_foreign_item(def_id) { - self.mk_imm_ptr(static_ty) } else { self.mk_imm_ref(self.lifetimes.re_erased, static_ty) } diff --git a/src/test/mir-opt/const-promotion-extern-static.rs b/src/test/mir-opt/const-promotion-extern-static.rs new file mode 100644 index 00000000000..d611ec22c38 --- /dev/null +++ b/src/test/mir-opt/const-promotion-extern-static.rs @@ -0,0 +1,71 @@ +extern "C" { + static X: i32; +} + +static Y: i32 = 42; + +static mut BAR: *const &'static i32 = [&Y].as_ptr(); + +static mut FOO: *const &'static i32 = [unsafe { &X }].as_ptr(); + +fn main() {} + +// END RUST SOURCE +// START rustc.FOO.PromoteTemps.before.mir +// bb0: { +// ... +// _5 = const Scalar(AllocId(1).0x0) : &i32; +// _4 = &(*_5); +// _3 = [move _4]; +// _2 = &_3; +// _1 = move _2 as &[&'static i32] (Pointer(Unsize)); +// _0 = const core::slice::<impl [&'static i32]>::as_ptr(move _1) -> [return: bb2, unwind: bb1]; +// } +// ... +// bb2: { +// StorageDead(_5); +// StorageDead(_3); +// return; +// } +// END rustc.FOO.PromoteTemps.before.mir +// START rustc.BAR.PromoteTemps.before.mir +// bb0: { +// ... +// _5 = const Scalar(AllocId(0).0x0) : &i32; +// _4 = &(*_5); +// _3 = [move _4]; +// _2 = &_3; +// _1 = move _2 as &[&'static i32] (Pointer(Unsize)); +// _0 = const core::slice::<impl [&'static i32]>::as_ptr(move _1) -> [return: bb2, unwind: bb1]; +// } +// ... +// bb2: { +// StorageDead(_5); +// StorageDead(_3); +// return; +// } +// END rustc.BAR.PromoteTemps.before.mir +// START rustc.BAR.PromoteTemps.after.mir +// bb0: { +// ... +// _2 = &(promoted[0]: [&'static i32; 1]); +// _1 = move _2 as &[&'static i32] (Pointer(Unsize)); +// _0 = const core::slice::<impl [&'static i32]>::as_ptr(move _1) -> [return: bb2, unwind: bb1]; +// } +// ... +// bb2: { +// return; +// } +// END rustc.BAR.PromoteTemps.after.mir +// START rustc.FOO.PromoteTemps.after.mir +// bb0: { +// ... +// _2 = &(promoted[0]: [&'static i32; 1]); +// _1 = move _2 as &[&'static i32] (Pointer(Unsize)); +// _0 = const core::slice::<impl [&'static i32]>::as_ptr(move _1) -> [return: bb2, unwind: bb1]; +// } +// ... +// bb2: { +// return; +// } +// END rustc.FOO.PromoteTemps.after.mir |
