Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a052f2c
Add the `#[derive_const]` attribute
fee1-dead Sep 20, 2022
2f7b4d9
Don't internalize __llvm_profile_counter_bias
abrachet Oct 10, 2022
9bcc083
run-make-fulldeps: fix split debuginfo test
davidtwco Nov 7, 2022
29dc083
llvm: dwo only emitted when object code emitted
davidtwco Nov 7, 2022
0e0bcd9
prevent uninitialized access in black_box for zero-sized-types
krasimirgg Nov 4, 2022
3074678
Mark `trait_upcasting` feature no longer incomplete.
crlf0710 Nov 7, 2022
c467006
suggest removing unnecessary . to use a floating point literal
TaKO8Ki Nov 8, 2022
004986b
avoid unnecessary `format!`
TaKO8Ki Nov 8, 2022
6018f11
emit errors when using `RangeFrom` and `RangeTo`
TaKO8Ki Nov 9, 2022
84e1fbc
Add no_std AArch64 support for the QNX Neutrino (nto) 7.1 RTOS
flba-eb Sep 5, 2022
ae71df9
Add `nto` as known `target_os`
flba-eb Oct 5, 2022
014f7f4
Remove some redundant arguments
oli-obk Nov 3, 2022
21ce587
Don't add message that will never be shown to users
oli-obk Nov 11, 2022
df2adc4
Print all labels, even if they have no span. Fall back to main item's…
oli-obk Nov 4, 2022
f149837
Add Tristan as maintainer
flba-eb Nov 11, 2022
f6d7f08
Issue error when `-C link-self-contained` option is used on unsupport…
StackDoubleFlow Nov 8, 2022
934c414
Update cargo
weihanglo Nov 11, 2022
f88bbba
Rollup merge of #102049 - fee1-dead-contrib:derive_const, r=oli-obk
Manishearth Nov 11, 2022
988a938
Rollup merge of #102701 - flba-eb:add_qnx_nostd_support, r=cjgillot
Manishearth Nov 11, 2022
4759140
Rollup merge of #102900 - abrachet:master, r=bjorn3
Manishearth Nov 11, 2022
20d7207
Rollup merge of #103970 - oli-obk:unhide_unknown_spans, r=estebank
Manishearth Nov 11, 2022
cbffebb
Rollup merge of #104105 - davidtwco:split-dwarf-lto, r=michaelwoerister
Manishearth Nov 11, 2022
401963b
Rollup merge of #104110 - krasimirgg:msan-16, r=nagisa
Manishearth Nov 11, 2022
83b5e07
Rollup merge of #104117 - crlf0710:update_feature_gate, r=jackh726
Manishearth Nov 11, 2022
02a768b
Rollup merge of #104137 - StackDoubleFlow:err-lsc-unsupported, r=petr…
Manishearth Nov 11, 2022
081cc38
Rollup merge of #104144 - TaKO8Ki:suggest-removing-unnecessary-dot, r…
Manishearth Nov 11, 2022
82f5085
Rollup merge of #104302 - weihanglo:update-cargo, r=weihanglo
Manishearth Nov 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
prevent uninitialized access in black_box for zero-sized-types
  • Loading branch information
krasimirgg committed Nov 8, 2022
commit 0e0bcd95cda4293915ecd68921320a0928cdd0bb
15 changes: 12 additions & 3 deletions compiler/rustc_codegen_llvm/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,17 +340,26 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {

sym::black_box => {
args[0].val.store(self, result);

let result_val_span = [result.llval];
// We need to "use" the argument in some way LLVM can't introspect, and on
// targets that support it we can typically leverage inline assembly to do
// this. LLVM's interpretation of inline assembly is that it's, well, a black
// box. This isn't the greatest implementation since it probably deoptimizes
// more than we want, but it's so far good enough.
//
// For zero-sized types, the location pointed to by the result may be
// uninitialized. Do not "use" the result in this case; instead just clobber
// the memory.
let (constraint, inputs): (&str, &[_]) = if result.layout.is_zst() {
("~{memory}", &[])
} else {
("r,~{memory}", &result_val_span)
};
crate::asm::inline_asm_call(
self,
"",
"r,~{memory}",
&[result.llval],
constraint,
inputs,
self.type_void(),
true,
false,
Expand Down
32 changes: 32 additions & 0 deletions src/test/ui/sanitize/memory-passing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// needs-sanitizer-support
// needs-sanitizer-memory
//
// revisions: unoptimized optimized
//
// [optimized]compile-flags: -Z sanitizer=memory -Zsanitizer-memory-track-origins -O
// [unoptimized]compile-flags: -Z sanitizer=memory -Zsanitizer-memory-track-origins
//
// run-pass
//
// This test case intentionally limits the usage of the std,
// since it will be linked with an uninstrumented version of it.

#![feature(core_intrinsics)]
#![feature(start)]
#![allow(invalid_value)]

use std::hint::black_box;

fn calling_black_box_on_zst_ok() {
// It's OK to call black_box on a value of a zero-sized type, even if its
// underlying the memory location is uninitialized. For non-zero-sized types,
// this would be an MSAN error.
let zst = ();
black_box(zst);
}

#[start]
fn main(_: isize, _: *const *const u8) -> isize {
calling_black_box_on_zst_ok();
0
}