Skip to content

Commit

Permalink
Auto merge of #123708 - matthiaskrgr:rollup-uf9w1e9, r=matthiaskrgr
Browse files Browse the repository at this point in the history
Rollup of 7 pull requests

Successful merges:

 - #121884 (Port exit-code run-make test to use rust)
 - #122200 (Unconditionally show update nightly hint on ICE)
 - #123568 (Clean up tests/ui by removing `does-nothing.rs`)
 - #123609 (Don't use bytepos offsets when computing semicolon span for removal)
 - #123612 (Set target-abi module flag for RISC-V targets)
 - #123633 (Store all args in the unsupported Command implementation)
 - #123668 (async closure coroutine by move body MirPass refactoring)

Failed merges:

 - #123701 (Only assert for child/parent projection compatibility AFTER checking that theyre coming from the same place)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Apr 10, 2024
2 parents 93c131e + df068db commit 1c77f73
Show file tree
Hide file tree
Showing 36 changed files with 491 additions and 203 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ impl<'a> AstValidator<'a> {
in_impl: matches!(parent, TraitOrTraitImpl::TraitImpl { .. }),
const_context_label: parent_constness,
remove_const_sugg: (
self.session.source_map().span_extend_while(span, |c| c == ' ').unwrap_or(span),
self.session.source_map().span_extend_while_whitespace(span),
match parent_constness {
Some(_) => rustc_errors::Applicability::MachineApplicable,
None => rustc_errors::Applicability::MaybeIncorrect,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ pub(crate) fn run_pass_manager(
"LTOPostLink".as_ptr().cast(),
11,
) {
llvm::LLVMRustAddModuleFlag(
llvm::LLVMRustAddModuleFlagU32(
module.module_llvm.llmod(),
llvm::LLVMModFlagBehavior::Error,
c"LTOPostLink".as_ptr().cast(),
Expand Down
46 changes: 31 additions & 15 deletions compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,13 @@ pub unsafe fn create_module<'ll>(
// to ensure intrinsic calls don't use it.
if !sess.needs_plt() {
let avoid_plt = c"RtLibUseGOT".as_ptr().cast();
llvm::LLVMRustAddModuleFlag(llmod, llvm::LLVMModFlagBehavior::Warning, avoid_plt, 1);
llvm::LLVMRustAddModuleFlagU32(llmod, llvm::LLVMModFlagBehavior::Warning, avoid_plt, 1);
}

// Enable canonical jump tables if CFI is enabled. (See https://reviews.llvm.org/D65629.)
if sess.is_sanitizer_cfi_canonical_jump_tables_enabled() && sess.is_sanitizer_cfi_enabled() {
let canonical_jump_tables = c"CFI Canonical Jump Tables".as_ptr().cast();
llvm::LLVMRustAddModuleFlag(
llvm::LLVMRustAddModuleFlagU32(
llmod,
llvm::LLVMModFlagBehavior::Override,
canonical_jump_tables,
Expand All @@ -197,7 +197,7 @@ pub unsafe fn create_module<'ll>(
// Enable LTO unit splitting if specified or if CFI is enabled. (See https://reviews.llvm.org/D53891.)
if sess.is_split_lto_unit_enabled() || sess.is_sanitizer_cfi_enabled() {
let enable_split_lto_unit = c"EnableSplitLTOUnit".as_ptr().cast();
llvm::LLVMRustAddModuleFlag(
llvm::LLVMRustAddModuleFlagU32(
llmod,
llvm::LLVMModFlagBehavior::Override,
enable_split_lto_unit,
Expand All @@ -208,7 +208,7 @@ pub unsafe fn create_module<'ll>(
// Add "kcfi" module flag if KCFI is enabled. (See https://reviews.llvm.org/D119296.)
if sess.is_sanitizer_kcfi_enabled() {
let kcfi = c"kcfi".as_ptr().cast();
llvm::LLVMRustAddModuleFlag(llmod, llvm::LLVMModFlagBehavior::Override, kcfi, 1);
llvm::LLVMRustAddModuleFlagU32(llmod, llvm::LLVMModFlagBehavior::Override, kcfi, 1);
}

// Control Flow Guard is currently only supported by the MSVC linker on Windows.
Expand All @@ -217,7 +217,7 @@ pub unsafe fn create_module<'ll>(
CFGuard::Disabled => {}
CFGuard::NoChecks => {
// Set `cfguard=1` module flag to emit metadata only.
llvm::LLVMRustAddModuleFlag(
llvm::LLVMRustAddModuleFlagU32(
llmod,
llvm::LLVMModFlagBehavior::Warning,
c"cfguard".as_ptr() as *const _,
Expand All @@ -226,7 +226,7 @@ pub unsafe fn create_module<'ll>(
}
CFGuard::Checks => {
// Set `cfguard=2` module flag to emit metadata and checks.
llvm::LLVMRustAddModuleFlag(
llvm::LLVMRustAddModuleFlagU32(
llmod,
llvm::LLVMModFlagBehavior::Warning,
c"cfguard".as_ptr() as *const _,
Expand All @@ -238,26 +238,26 @@ pub unsafe fn create_module<'ll>(

if let Some(BranchProtection { bti, pac_ret }) = sess.opts.unstable_opts.branch_protection {
if sess.target.arch == "aarch64" {
llvm::LLVMRustAddModuleFlag(
llvm::LLVMRustAddModuleFlagU32(
llmod,
llvm::LLVMModFlagBehavior::Min,
c"branch-target-enforcement".as_ptr().cast(),
bti.into(),
);
llvm::LLVMRustAddModuleFlag(
llvm::LLVMRustAddModuleFlagU32(
llmod,
llvm::LLVMModFlagBehavior::Min,
c"sign-return-address".as_ptr().cast(),
pac_ret.is_some().into(),
);
let pac_opts = pac_ret.unwrap_or(PacRet { leaf: false, key: PAuthKey::A });
llvm::LLVMRustAddModuleFlag(
llvm::LLVMRustAddModuleFlagU32(
llmod,
llvm::LLVMModFlagBehavior::Min,
c"sign-return-address-all".as_ptr().cast(),
pac_opts.leaf.into(),
);
llvm::LLVMRustAddModuleFlag(
llvm::LLVMRustAddModuleFlagU32(
llmod,
llvm::LLVMModFlagBehavior::Min,
c"sign-return-address-with-bkey".as_ptr().cast(),
Expand All @@ -273,15 +273,15 @@ pub unsafe fn create_module<'ll>(

// Pass on the control-flow protection flags to LLVM (equivalent to `-fcf-protection` in Clang).
if let CFProtection::Branch | CFProtection::Full = sess.opts.unstable_opts.cf_protection {
llvm::LLVMRustAddModuleFlag(
llvm::LLVMRustAddModuleFlagU32(
llmod,
llvm::LLVMModFlagBehavior::Override,
c"cf-protection-branch".as_ptr().cast(),
1,
)
}
if let CFProtection::Return | CFProtection::Full = sess.opts.unstable_opts.cf_protection {
llvm::LLVMRustAddModuleFlag(
llvm::LLVMRustAddModuleFlagU32(
llmod,
llvm::LLVMModFlagBehavior::Override,
c"cf-protection-return".as_ptr().cast(),
Expand All @@ -290,7 +290,7 @@ pub unsafe fn create_module<'ll>(
}
if sess.opts.unstable_opts.virtual_function_elimination {
llvm::LLVMRustAddModuleFlag(
llvm::LLVMRustAddModuleFlagU32(
llmod,
llvm::LLVMModFlagBehavior::Error,
c"Virtual Function Elim".as_ptr().cast(),
Expand All @@ -300,7 +300,7 @@ pub unsafe fn create_module<'ll>(

// Set module flag to enable Windows EHCont Guard (/guard:ehcont).
if sess.opts.unstable_opts.ehcont_guard {
llvm::LLVMRustAddModuleFlag(
llvm::LLVMRustAddModuleFlagU32(
llmod,
llvm::LLVMModFlagBehavior::Warning,
c"ehcontguard".as_ptr() as *const _,
Expand All @@ -326,6 +326,22 @@ pub unsafe fn create_module<'ll>(
llvm::LLVMMDNodeInContext(llcx, &name_metadata, 1),
);

// Emit RISC-V specific target-abi metadata
// to workaround lld as the LTO plugin not
// correctly setting target-abi for the LTO object
// FIXME: https://github.com/llvm/llvm-project/issues/50591
// If llvm_abiname is empty, emit nothing.
let llvm_abiname = &sess.target.options.llvm_abiname;
if matches!(sess.target.arch.as_ref(), "riscv32" | "riscv64") && !llvm_abiname.is_empty() {
llvm::LLVMRustAddModuleFlagString(
llmod,
llvm::LLVMModFlagBehavior::Error,
c"target-abi".as_ptr(),
llvm_abiname.as_ptr().cast(),
llvm_abiname.len(),
);
}

// Add module flags specified via -Z llvm_module_flag
for (key, value, behavior) in &sess.opts.unstable_opts.llvm_module_flag {
let key = format!("{key}\0");
Expand All @@ -341,7 +357,7 @@ pub unsafe fn create_module<'ll>(
// We already checked this during option parsing
_ => unreachable!(),
};
llvm::LLVMRustAddModuleFlag(llmod, behavior, key.as_ptr().cast(), *value)
llvm::LLVMRustAddModuleFlagU32(llmod, behavior, key.as_ptr().cast(), *value)
}

llmod
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_llvm/src/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ impl<'ll, 'tcx> CodegenUnitDebugContext<'ll, 'tcx> {
.unstable_opts
.dwarf_version
.unwrap_or(sess.target.default_dwarf_version);
llvm::LLVMRustAddModuleFlag(
llvm::LLVMRustAddModuleFlagU32(
self.llmod,
llvm::LLVMModFlagBehavior::Warning,
c"Dwarf Version".as_ptr().cast(),
dwarf_version,
);
} else {
// Indicate that we want CodeView debug information on MSVC
llvm::LLVMRustAddModuleFlag(
llvm::LLVMRustAddModuleFlagU32(
self.llmod,
llvm::LLVMModFlagBehavior::Warning,
c"CodeView".as_ptr().cast(),
Expand All @@ -127,7 +127,7 @@ impl<'ll, 'tcx> CodegenUnitDebugContext<'ll, 'tcx> {
}

// Prevent bitcode readers from deleting the debug info.
llvm::LLVMRustAddModuleFlag(
llvm::LLVMRustAddModuleFlagU32(
self.llmod,
llvm::LLVMModFlagBehavior::Warning,
c"Debug Info Version".as_ptr().cast(),
Expand Down
11 changes: 10 additions & 1 deletion compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1801,12 +1801,21 @@ extern "C" {
///
/// In order for Rust-C LTO to work, module flags must be compatible with Clang. What
/// "compatible" means depends on the merge behaviors involved.
pub fn LLVMRustAddModuleFlag(
pub fn LLVMRustAddModuleFlagU32(
M: &Module,
merge_behavior: LLVMModFlagBehavior,
name: *const c_char,
value: u32,
);

pub fn LLVMRustAddModuleFlagString(
M: &Module,
merge_behavior: LLVMModFlagBehavior,
name: *const c_char,
value: *const c_char,
value_len: size_t,
);

pub fn LLVMRustHasModuleFlag(M: &Module, name: *const c_char, len: size_t) -> bool;

pub fn LLVMRustDIBuilderCreate(M: &Module) -> &mut DIBuilder<'_>;
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_driver_impl/messages.ftl
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
driver_impl_ice = the compiler unexpectedly panicked. this is a bug.
driver_impl_ice_bug_report = we would appreciate a bug report: {$bug_report_url}
driver_impl_ice_bug_report_internal_feature = using internal features is not supported and expected to cause internal compiler errors when used incorrectly
driver_impl_ice_bug_report_outdated =
it seems that this compiler `{$version}` is outdated, a newer nightly should have been released in the meantime
.update = please consider running `rustup update nightly` to update the nightly channel and check if this problem still persists
.url = if the problem still persists, we would appreciate a bug report: {$bug_report_url}
driver_impl_ice_bug_report_update_note = please make sure that you have updated to the latest nightly
driver_impl_ice_exclude_cargo_defaults = some of the compiler flags provided by cargo are hidden
driver_impl_ice_flags = compiler flags: {$flags}
Expand Down
38 changes: 8 additions & 30 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ use std::str;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, OnceLock};
use std::time::{Instant, SystemTime};
use time::{Date, OffsetDateTime, Time};
use time::OffsetDateTime;

#[allow(unused_macros)]
macro do_not_use_print($($t:tt)*) {
Expand Down Expand Up @@ -1385,9 +1385,6 @@ pub fn install_ice_hook(
using_internal_features
}

const DATE_FORMAT: &[time::format_description::FormatItem<'static>] =
&time::macros::format_description!("[year]-[month]-[day]");

/// Prints the ICE message, including query stack, but without backtrace.
///
/// The message will point the user at `bug_report_url` to report the ICE.
Expand Down Expand Up @@ -1416,33 +1413,14 @@ fn report_ice(
dcx.emit_err(session_diagnostics::Ice);
}

use time::ext::NumericalDuration;

// Try to hint user to update nightly if applicable when reporting an ICE.
// Attempt to calculate when current version was released, and add 12 hours
// as buffer. If the current version's release timestamp is older than
// the system's current time + 24 hours + 12 hours buffer if we're on
// nightly.
if let Some("nightly") = option_env!("CFG_RELEASE_CHANNEL")
&& let Some(version) = option_env!("CFG_VERSION")
&& let Some(ver_date_str) = option_env!("CFG_VER_DATE")
&& let Ok(ver_date) = Date::parse(&ver_date_str, DATE_FORMAT)
&& let ver_datetime = OffsetDateTime::new_utc(ver_date, Time::MIDNIGHT)
&& let system_datetime = OffsetDateTime::from(SystemTime::now())
&& system_datetime.checked_sub(36.hours()).is_some_and(|d| d > ver_datetime)
&& !using_internal_features.load(std::sync::atomic::Ordering::Relaxed)
{
dcx.emit_note(session_diagnostics::IceBugReportOutdated {
version,
bug_report_url,
note_update: (),
note_url: (),
});
if using_internal_features.load(std::sync::atomic::Ordering::Relaxed) {
dcx.emit_note(session_diagnostics::IceBugReportInternalFeature);
} else {
if using_internal_features.load(std::sync::atomic::Ordering::Relaxed) {
dcx.emit_note(session_diagnostics::IceBugReportInternalFeature);
} else {
dcx.emit_note(session_diagnostics::IceBugReport { bug_report_url });
dcx.emit_note(session_diagnostics::IceBugReport { bug_report_url });

// Only emit update nightly hint for users on nightly builds.
if rustc_feature::UnstableFeatures::from_environment(None).is_nightly_build() {
dcx.emit_note(session_diagnostics::UpdateNightlyNote);
}
}

Expand Down
15 changes: 4 additions & 11 deletions compiler/rustc_driver_impl/src/session_diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,12 @@ pub(crate) struct IceBugReport<'a> {
}

#[derive(Diagnostic)]
#[diag(driver_impl_ice_bug_report_internal_feature)]
pub(crate) struct IceBugReportInternalFeature;
#[diag(driver_impl_ice_bug_report_update_note)]
pub(crate) struct UpdateNightlyNote;

#[derive(Diagnostic)]
#[diag(driver_impl_ice_bug_report_outdated)]
pub(crate) struct IceBugReportOutdated<'a> {
pub version: &'a str,
pub bug_report_url: &'a str,
#[note(driver_impl_update)]
pub note_update: (),
#[note(driver_impl_url)]
pub note_url: (),
}
#[diag(driver_impl_ice_bug_report_internal_feature)]
pub(crate) struct IceBugReportInternalFeature;

#[derive(Diagnostic)]
#[diag(driver_impl_ice_version)]
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2023,8 +2023,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.tcx
.sess
.source_map()
.span_extend_while(range_start.span, |c| c.is_whitespace())
.unwrap_or(range_start.span)
.span_extend_while_whitespace(range_start.span)
.shrink_to_hi()
.to(range_end.span);

Expand Down
15 changes: 9 additions & 6 deletions compiler/rustc_infer/src/infer/error_reporting/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use rustc_middle::traits::{
};
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::{self as ty, GenericArgKind, IsSuggestable, Ty, TypeVisitableExt};
use rustc_span::{sym, BytePos, Span};
use rustc_span::{sym, Span};

use crate::errors::{
ConsiderAddingAwait, FnConsiderCasting, FnItemsAreDistinct, FnUniqTypes,
Expand Down Expand Up @@ -763,8 +763,14 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
let mac_call = rustc_span::source_map::original_sp(last_stmt.span, blk.span);
self.tcx.sess.source_map().mac_call_stmt_semi_span(mac_call)?
} else {
last_stmt.span.with_lo(last_stmt.span.hi() - BytePos(1))
self.tcx
.sess
.source_map()
.span_extend_while_whitespace(last_expr.span)
.shrink_to_hi()
.with_hi(last_stmt.span.hi())
};

Some((span, needs_box))
}

Expand Down Expand Up @@ -867,10 +873,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
format!(" {ident} ")
};
let left_span = sm.span_through_char(blk.span, '{').shrink_to_hi();
(
sm.span_extend_while(left_span, |c| c.is_whitespace()).unwrap_or(left_span),
sugg,
)
(sm.span_extend_while_whitespace(left_span), sugg)
};
Some(SuggestRemoveSemiOrReturnBinding::Add { sp: span, code: sugg, ident: *ident })
}
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_lint/src/context/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,7 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiag, diag: &mut Di
if let Some(deletion_span) = deletion_span {
let msg = "elide the single-use lifetime";
let (use_span, replace_lt) = if elide {
let use_span = sess
.source_map()
.span_extend_while(use_span, char::is_whitespace)
.unwrap_or(use_span);
let use_span = sess.source_map().span_extend_while_whitespace(use_span);
(use_span, String::new())
} else {
(use_span, "'_".to_owned())
Expand Down
12 changes: 11 additions & 1 deletion compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -817,14 +817,24 @@ extern "C" uint32_t LLVMRustVersionMinor() { return LLVM_VERSION_MINOR; }

extern "C" uint32_t LLVMRustVersionMajor() { return LLVM_VERSION_MAJOR; }

extern "C" void LLVMRustAddModuleFlag(
extern "C" void LLVMRustAddModuleFlagU32(
LLVMModuleRef M,
Module::ModFlagBehavior MergeBehavior,
const char *Name,
uint32_t Value) {
unwrap(M)->addModuleFlag(MergeBehavior, Name, Value);
}

extern "C" void LLVMRustAddModuleFlagString(
LLVMModuleRef M,
Module::ModFlagBehavior MergeBehavior,
const char *Name,
const char *Value,
size_t ValueLen) {
unwrap(M)->addModuleFlag(MergeBehavior, Name,
MDString::get(unwrap(M)->getContext(), StringRef(Value, ValueLen)));
}

extern "C" bool LLVMRustHasModuleFlag(LLVMModuleRef M, const char *Name,
size_t Len) {
return unwrap(M)->getModuleFlag(StringRef(Name, Len)) != nullptr;
Expand Down
Loading

0 comments on commit 1c77f73

Please sign in to comment.