Skip to content

Commit 2cb0b85

Browse files
committed
Auto merge of #69833 - Centril:rollup-mh74yue, r=Centril
Rollup of 7 pull requests Successful merges: - #69120 (Don't give invalid suggestion on desugared span.) - #69326 (mir-interpret: add method to read wide strings from Memory) - #69608 (Expose target libdir information via print command) - #69734 (Change DIBuilderCreateEnumerator signature to match LLVM 9) - #69800 (Compile address sanitizer test with debuginfo) - #69807 (Cleanup E0391 explanation) - #69820 (clean up E0392 explanation) Failed merges: r? @ghost
2 parents 564758c + c934c94 commit 2cb0b85

File tree

15 files changed

+152
-72
lines changed

15 files changed

+152
-72
lines changed

src/doc/rustc/src/command-line-arguments.md

+1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ The valid types of print values are:
146146
- `crate-name` — The name of the crate.
147147
- `file-names` — The names of the files created by the `link` emit kind.
148148
- `sysroot` — Path to the sysroot.
149+
- `target-libdir` - Path to the target libdir.
149150
- `cfg` — List of cfg values. See [conditional compilation] for more
150151
information about cfg values.
151152
- `target-list` — List of known targets. The target may be selected with the

src/librustc/mir/interpret/value.rs

+10
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,11 @@ impl<'tcx, Tag> ScalarMaybeUndef<Tag> {
612612
self.not_undef()?.to_u8()
613613
}
614614

615+
#[inline(always)]
616+
pub fn to_u16(self) -> InterpResult<'tcx, u16> {
617+
self.not_undef()?.to_u16()
618+
}
619+
615620
#[inline(always)]
616621
pub fn to_u32(self) -> InterpResult<'tcx, u32> {
617622
self.not_undef()?.to_u32()
@@ -632,6 +637,11 @@ impl<'tcx, Tag> ScalarMaybeUndef<Tag> {
632637
self.not_undef()?.to_i8()
633638
}
634639

640+
#[inline(always)]
641+
pub fn to_i16(self) -> InterpResult<'tcx, i16> {
642+
self.not_undef()?.to_i16()
643+
}
644+
635645
#[inline(always)]
636646
pub fn to_i32(self) -> InterpResult<'tcx, i32> {
637647
self.not_undef()?.to_i32()

src/librustc_codegen_llvm/debuginfo/metadata.rs

+16-7
Original file line numberDiff line numberDiff line change
@@ -1779,13 +1779,20 @@ fn prepare_enum_metadata(
17791779
.discriminants(cx.tcx)
17801780
.zip(&def.variants)
17811781
.map(|((_, discr), v)| {
1782-
let name = SmallCStr::new(&v.ident.as_str());
1782+
let name = v.ident.as_str();
1783+
let is_unsigned = match discr.ty.kind {
1784+
ty::Int(_) => false,
1785+
ty::Uint(_) => true,
1786+
_ => bug!("non integer discriminant"),
1787+
};
17831788
unsafe {
17841789
Some(llvm::LLVMRustDIBuilderCreateEnumerator(
17851790
DIB(cx),
1786-
name.as_ptr(),
1791+
name.as_ptr().cast(),
1792+
name.len(),
17871793
// FIXME: what if enumeration has i128 discriminant?
1788-
discr.val as u64,
1794+
discr.val as i64,
1795+
is_unsigned,
17891796
))
17901797
}
17911798
})
@@ -1794,13 +1801,15 @@ fn prepare_enum_metadata(
17941801
.as_generator()
17951802
.variant_range(enum_def_id, cx.tcx)
17961803
.map(|variant_index| {
1797-
let name = SmallCStr::new(&substs.as_generator().variant_name(variant_index));
1804+
let name = substs.as_generator().variant_name(variant_index);
17981805
unsafe {
17991806
Some(llvm::LLVMRustDIBuilderCreateEnumerator(
18001807
DIB(cx),
1801-
name.as_ptr(),
1802-
// FIXME: what if enumeration has i128 discriminant?
1803-
variant_index.as_usize() as u64,
1808+
name.as_ptr().cast(),
1809+
name.len(),
1810+
// Generators use u32 as discriminant type.
1811+
variant_index.as_u32().into(),
1812+
true, // IsUnsigned
18041813
))
18051814
}
18061815
})

src/librustc_codegen_llvm/llvm/ffi.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1776,7 +1776,9 @@ extern "C" {
17761776
pub fn LLVMRustDIBuilderCreateEnumerator(
17771777
Builder: &DIBuilder<'a>,
17781778
Name: *const c_char,
1779-
Val: u64,
1779+
NameLen: size_t,
1780+
Value: i64,
1781+
IsUnsigned: bool,
17801782
) -> &'a DIEnumerator;
17811783

17821784
pub fn LLVMRustDIBuilderCreateEnumerationType(

src/librustc_driver/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,10 @@ impl RustcDefaultCalls {
680680
println!("{}", targets.join("\n"));
681681
}
682682
Sysroot => println!("{}", sess.sysroot.display()),
683+
TargetLibdir => println!(
684+
"{}",
685+
sess.target_tlib_path.as_ref().unwrap_or(&sess.host_tlib_path).dir.display()
686+
),
683687
TargetSpec => println!("{}", sess.target.target.to_json().pretty()),
684688
FileNames | CrateName => {
685689
let input = input.unwrap_or_else(|| {
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
This error indicates that some types or traits depend on each other
2-
and therefore cannot be constructed.
1+
A type dependency cycle has been encountered.
32

4-
The following example contains a circular dependency between two traits:
3+
Erroneous code example:
54

65
```compile_fail,E0391
76
trait FirstTrait : SecondTrait {
@@ -12,3 +11,6 @@ trait SecondTrait : FirstTrait {
1211
1312
}
1413
```
14+
15+
The previous example contains a circular dependency between two traits:
16+
`FirstTrait` depends on `SecondTrait` which itself depends on `FirstTrait`.

src/librustc_error_codes/error_codes/E0392.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
This error indicates that a type or lifetime parameter has been declared
2-
but not actually used. Here is an example that demonstrates the error:
1+
A type or lifetime parameter has been declared but is not actually used.
2+
3+
Erroneous code example:
34

45
```compile_fail,E0392
56
enum Foo<T> {

src/librustc_mir/borrow_check/diagnostics/mutability_errors.rs

+45-43
Original file line numberDiff line numberDiff line change
@@ -329,58 +329,60 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
329329
if self.body.local_decls[local].is_user_variable() =>
330330
{
331331
let local_decl = &self.body.local_decls[local];
332-
let suggestion = match local_decl.local_info {
333-
LocalInfo::User(ClearCrossCrate::Set(mir::BindingForm::ImplicitSelf(_))) => {
334-
Some(suggest_ampmut_self(self.infcx.tcx, local_decl))
335-
}
336-
337-
LocalInfo::User(ClearCrossCrate::Set(mir::BindingForm::Var(
338-
mir::VarBindingForm {
339-
binding_mode: ty::BindingMode::BindByValue(_),
340-
opt_ty_info,
341-
..
342-
},
343-
))) => Some(suggest_ampmut(
344-
self.infcx.tcx,
345-
self.body,
346-
local,
347-
local_decl,
348-
opt_ty_info,
349-
)),
350-
351-
LocalInfo::User(ClearCrossCrate::Set(mir::BindingForm::Var(
352-
mir::VarBindingForm {
353-
binding_mode: ty::BindingMode::BindByReference(_),
354-
..
355-
},
356-
))) => {
357-
let pattern_span = local_decl.source_info.span;
358-
suggest_ref_mut(self.infcx.tcx, pattern_span)
359-
.map(|replacement| (pattern_span, replacement))
360-
}
361-
362-
LocalInfo::User(ClearCrossCrate::Clear) => bug!("saw cleared local state"),
363-
364-
_ => unreachable!(),
365-
};
366332

367333
let (pointer_sigil, pointer_desc) = if local_decl.ty.is_region_ptr() {
368334
("&", "reference")
369335
} else {
370336
("*const", "pointer")
371337
};
372338

373-
if let Some((err_help_span, suggested_code)) = suggestion {
374-
err.span_suggestion(
375-
err_help_span,
376-
&format!("consider changing this to be a mutable {}", pointer_desc),
377-
suggested_code,
378-
Applicability::MachineApplicable,
379-
);
380-
}
381-
382339
match self.local_names[local] {
383340
Some(name) if !local_decl.from_compiler_desugaring() => {
341+
let suggestion = match local_decl.local_info {
342+
LocalInfo::User(ClearCrossCrate::Set(
343+
mir::BindingForm::ImplicitSelf(_),
344+
)) => Some(suggest_ampmut_self(self.infcx.tcx, local_decl)),
345+
346+
LocalInfo::User(ClearCrossCrate::Set(mir::BindingForm::Var(
347+
mir::VarBindingForm {
348+
binding_mode: ty::BindingMode::BindByValue(_),
349+
opt_ty_info,
350+
..
351+
},
352+
))) => Some(suggest_ampmut(
353+
self.infcx.tcx,
354+
self.body,
355+
local,
356+
local_decl,
357+
opt_ty_info,
358+
)),
359+
360+
LocalInfo::User(ClearCrossCrate::Set(mir::BindingForm::Var(
361+
mir::VarBindingForm {
362+
binding_mode: ty::BindingMode::BindByReference(_),
363+
..
364+
},
365+
))) => {
366+
let pattern_span = local_decl.source_info.span;
367+
suggest_ref_mut(self.infcx.tcx, pattern_span)
368+
.map(|replacement| (pattern_span, replacement))
369+
}
370+
371+
LocalInfo::User(ClearCrossCrate::Clear) => {
372+
bug!("saw cleared local state")
373+
}
374+
375+
_ => unreachable!(),
376+
};
377+
378+
if let Some((err_help_span, suggested_code)) = suggestion {
379+
err.span_suggestion(
380+
err_help_span,
381+
&format!("consider changing this to be a mutable {}", pointer_desc),
382+
suggested_code,
383+
Applicability::MachineApplicable,
384+
);
385+
}
384386
err.span_label(
385387
span,
386388
format!(

src/librustc_mir/interpret/memory.rs

+27
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,33 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
798798
self.get_raw(ptr.alloc_id)?.read_c_str(self, ptr)
799799
}
800800

801+
/// Reads a 0x0000-terminated u16-sequence from memory. Returns them as a Vec<u16>.
802+
/// Terminator 0x0000 is not included in the returned Vec<u16>.
803+
///
804+
/// Performs appropriate bounds checks.
805+
pub fn read_wide_str(&self, ptr: Scalar<M::PointerTag>) -> InterpResult<'tcx, Vec<u16>> {
806+
let size_2bytes = Size::from_bytes(2);
807+
let align_2bytes = Align::from_bytes(2).unwrap();
808+
// We need to read at least 2 bytes, so we *need* a ptr.
809+
let mut ptr = self.force_ptr(ptr)?;
810+
let allocation = self.get_raw(ptr.alloc_id)?;
811+
let mut u16_seq = Vec::new();
812+
813+
loop {
814+
ptr = self
815+
.check_ptr_access(ptr.into(), size_2bytes, align_2bytes)?
816+
.expect("cannot be a ZST");
817+
let single_u16 = allocation.read_scalar(self, ptr, size_2bytes)?.to_u16()?;
818+
if single_u16 != 0x0000 {
819+
u16_seq.push(single_u16);
820+
ptr = ptr.offset(size_2bytes, self)?;
821+
} else {
822+
break;
823+
}
824+
}
825+
Ok(u16_seq)
826+
}
827+
801828
/// Writes the given stream of bytes into memory.
802829
///
803830
/// Performs appropriate bounds checks.

src/librustc_session/config.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ impl ExternEntry {
391391
pub enum PrintRequest {
392392
FileNames,
393393
Sysroot,
394+
TargetLibdir,
394395
CrateName,
395396
Cfg,
396397
TargetList,
@@ -912,7 +913,7 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
912913
"",
913914
"print",
914915
"Compiler information to print on stdout",
915-
"[crate-name|file-names|sysroot|cfg|target-list|\
916+
"[crate-name|file-names|sysroot|target-libdir|cfg|target-list|\
916917
target-cpus|target-features|relocation-models|\
917918
code-models|tls-models|target-spec-json|native-static-libs]",
918919
),
@@ -1344,6 +1345,7 @@ fn collect_print_requests(
13441345
"crate-name" => PrintRequest::CrateName,
13451346
"file-names" => PrintRequest::FileNames,
13461347
"sysroot" => PrintRequest::Sysroot,
1348+
"target-libdir" => PrintRequest::TargetLibdir,
13471349
"cfg" => PrintRequest::Cfg,
13481350
"target-list" => PrintRequest::TargetList,
13491351
"target-cpus" => PrintRequest::TargetCPUs,

src/rustllvm/RustWrapper.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -891,10 +891,10 @@ extern "C" LLVMValueRef LLVMRustDIBuilderInsertDeclareAtEnd(
891891
unwrap(InsertAtEnd)));
892892
}
893893

894-
extern "C" LLVMMetadataRef
895-
LLVMRustDIBuilderCreateEnumerator(LLVMRustDIBuilderRef Builder,
896-
const char *Name, uint64_t Val) {
897-
return wrap(Builder->createEnumerator(Name, Val));
894+
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateEnumerator(
895+
LLVMRustDIBuilderRef Builder, const char *Name, size_t NameLen,
896+
int64_t Value, bool IsUnsigned) {
897+
return wrap(Builder->createEnumerator({Name, NameLen}, Value, IsUnsigned));
898898
}
899899

900900
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateEnumerationType(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Verify that DIEnumerator uses isUnsigned flag when appropriate.
2+
//
3+
// compile-flags: -g -C no-prepopulate-passes
4+
5+
#[repr(i64)]
6+
pub enum I64 {
7+
I64Min = std::i64::MIN,
8+
I64Max = std::i64::MAX,
9+
}
10+
11+
#[repr(u64)]
12+
pub enum U64 {
13+
U64Min = std::u64::MIN,
14+
U64Max = std::u64::MAX,
15+
}
16+
17+
fn main() {
18+
let _a = I64::I64Min;
19+
let _b = I64::I64Max;
20+
let _c = U64::U64Min;
21+
let _d = U64::U64Max;
22+
}
23+
24+
// CHECK: !DIEnumerator(name: "I64Min", value: -9223372036854775808)
25+
// CHECK: !DIEnumerator(name: "I64Max", value: 9223372036854775807)
26+
// CHECK: !DIEnumerator(name: "U64Min", value: 0, isUnsigned: true)
27+
// CHECK: !DIEnumerator(name: "U64Max", value: 18446744073709551615, isUnsigned: true)

src/test/ui/async-await/dont-print-desugared-async.stderr

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ error[E0596]: cannot borrow data in a `&` reference as mutable
22
--> $DIR/dont-print-desugared-async.rs:5:20
33
|
44
LL | async fn async_fn(&ref mut s: &[i32]) {}
5-
| -^^^^^^^^^
6-
| ||
7-
| |cannot borrow as mutable through `&` reference
8-
| help: consider changing this to be a mutable reference: `&mut ref mut s`
5+
| ^^^^^^^^^ cannot borrow as mutable through `&` reference
96

107
error: aborting due to previous error
118

src/test/ui/nll/dont-print-desugared.stderr

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ error[E0596]: cannot borrow data in a `&` reference as mutable
22
--> $DIR/dont-print-desugared.rs:4:10
33
|
44
LL | for &ref mut x in s {}
5-
| -^^^^^^^^^
6-
| ||
7-
| |cannot borrow as mutable through `&` reference
8-
| help: consider changing this to be a mutable reference: `&mut ref mut x`
5+
| ^^^^^^^^^ cannot borrow as mutable through `&` reference
96

107
error[E0597]: `y` does not live long enough
118
--> $DIR/dont-print-desugared.rs:17:16

src/test/ui/sanitize/address.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
// needs-sanitizer-support
22
// only-x86_64
33
//
4-
// compile-flags: -Z sanitizer=address -O
4+
// compile-flags: -Z sanitizer=address -O -g
55
//
66
// run-fail
77
// error-pattern: AddressSanitizer: stack-buffer-overflow
8-
// error-pattern: 'xs' <== Memory access at offset
8+
// error-pattern: 'xs' (line 15) <== Memory access at offset
99

1010
#![feature(test)]
1111

1212
use std::hint::black_box;
13-
use std::mem;
1413

1514
fn main() {
1615
let xs = [0, 1, 2, 3];

0 commit comments

Comments
 (0)