Skip to content

Commit 88ad3d4

Browse files
committed
Auto merge of #151436 - jhpratt:rollup-Rp5KtGe, r=jhpratt
Rollup of 6 pull requests Successful merges: - #150436 (`c_variadic`: impl `va_copy` and `va_end` as Rust intrinsics) - #151340 (Port `#[patchable_function_entry]` to attr parser) - #151351 (Deduplicate diagnostics for const trait supertraits) - #151424 (missing colon after the compile-flags directive) - #151428 (Port variance attrs to attr parser.) - #151429 (s390x: Support aligned stack datalayout) Failed merges: - #151343 (Port some crate level attrs to the attribute parser) r? @ghost
2 parents d276646 + db9ff0d commit 88ad3d4

38 files changed

Lines changed: 625 additions & 515 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,3 +717,100 @@ impl<S: Stage> NoArgsAttributeParser<S> for EiiForeignItemParser {
717717
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::ForeignFn)]);
718718
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::EiiForeignItem;
719719
}
720+
721+
pub(crate) struct PatchableFunctionEntryParser;
722+
723+
impl<S: Stage> SingleAttributeParser<S> for PatchableFunctionEntryParser {
724+
const PATH: &[Symbol] = &[sym::patchable_function_entry];
725+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
726+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
727+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Fn)]);
728+
const TEMPLATE: AttributeTemplate = template!(List: &["prefix_nops = m, entry_nops = n"]);
729+
730+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
731+
let Some(meta_item_list) = args.list() else {
732+
cx.expected_list(cx.attr_span, args);
733+
return None;
734+
};
735+
736+
let mut prefix = None;
737+
let mut entry = None;
738+
739+
if meta_item_list.len() == 0 {
740+
cx.expected_list(meta_item_list.span, args);
741+
return None;
742+
}
743+
744+
let mut errored = false;
745+
746+
for item in meta_item_list.mixed() {
747+
let Some(meta_item) = item.meta_item() else {
748+
errored = true;
749+
cx.expected_name_value(item.span(), None);
750+
continue;
751+
};
752+
753+
let Some(name_value_lit) = meta_item.args().name_value() else {
754+
errored = true;
755+
cx.expected_name_value(item.span(), None);
756+
continue;
757+
};
758+
759+
let attrib_to_write = match meta_item.ident().map(|ident| ident.name) {
760+
Some(sym::prefix_nops) => {
761+
// Duplicate prefixes are not allowed
762+
if prefix.is_some() {
763+
errored = true;
764+
cx.duplicate_key(meta_item.path().span(), sym::prefix_nops);
765+
continue;
766+
}
767+
&mut prefix
768+
}
769+
Some(sym::entry_nops) => {
770+
// Duplicate entries are not allowed
771+
if entry.is_some() {
772+
errored = true;
773+
cx.duplicate_key(meta_item.path().span(), sym::entry_nops);
774+
continue;
775+
}
776+
&mut entry
777+
}
778+
_ => {
779+
errored = true;
780+
cx.expected_specific_argument(
781+
meta_item.path().span(),
782+
&[sym::prefix_nops, sym::entry_nops],
783+
);
784+
continue;
785+
}
786+
};
787+
788+
let rustc_ast::LitKind::Int(val, _) = name_value_lit.value_as_lit().kind else {
789+
errored = true;
790+
cx.expected_integer_literal(name_value_lit.value_span);
791+
continue;
792+
};
793+
794+
let Ok(val) = val.get().try_into() else {
795+
errored = true;
796+
cx.expected_integer_literal_in_range(
797+
name_value_lit.value_span,
798+
u8::MIN as isize,
799+
u8::MAX as isize,
800+
);
801+
continue;
802+
};
803+
804+
*attrib_to_write = Some(val);
805+
}
806+
807+
if errored {
808+
None
809+
} else {
810+
Some(AttributeKind::PatchableFunctionEntry {
811+
prefix: prefix.unwrap_or(0),
812+
entry: entry.unwrap_or(0),
813+
})
814+
}
815+
}
816+
}

compiler/rustc_attr_parsing/src/attributes/test_attrs.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,25 @@ impl<S: Stage> SingleAttributeParser<S> for ShouldPanicParser {
9191
})
9292
}
9393
}
94+
95+
pub(crate) struct RustcVarianceParser;
96+
97+
impl<S: Stage> NoArgsAttributeParser<S> for RustcVarianceParser {
98+
const PATH: &[Symbol] = &[sym::rustc_variance];
99+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
100+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
101+
Allow(Target::Struct),
102+
Allow(Target::Enum),
103+
Allow(Target::Union),
104+
]);
105+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcVariance;
106+
}
107+
108+
pub(crate) struct RustcVarianceOfOpaquesParser;
109+
110+
impl<S: Stage> NoArgsAttributeParser<S> for RustcVarianceOfOpaquesParser {
111+
const PATH: &[Symbol] = &[sym::rustc_variance_of_opaques];
112+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
113+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
114+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcVarianceOfOpaques;
115+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ use crate::attributes::cfi_encoding::CfiEncodingParser;
2323
use crate::attributes::codegen_attrs::{
2424
ColdParser, CoverageParser, EiiForeignItemParser, ExportNameParser, ForceTargetFeatureParser,
2525
NakedParser, NoMangleParser, ObjcClassParser, ObjcSelectorParser, OptimizeParser,
26-
RustcPassIndirectlyInNonRusticAbisParser, SanitizeParser, TargetFeatureParser,
27-
ThreadLocalParser, TrackCallerParser, UsedParser,
26+
PatchableFunctionEntryParser, RustcPassIndirectlyInNonRusticAbisParser, SanitizeParser,
27+
TargetFeatureParser, ThreadLocalParser, TrackCallerParser, UsedParser,
2828
};
2929
use crate::attributes::confusables::ConfusablesParser;
3030
use crate::attributes::crate_level::{
@@ -85,7 +85,9 @@ use crate::attributes::semantics::MayDangleParser;
8585
use crate::attributes::stability::{
8686
BodyStabilityParser, ConstStabilityIndirectParser, ConstStabilityParser, StabilityParser,
8787
};
88-
use crate::attributes::test_attrs::{IgnoreParser, ShouldPanicParser};
88+
use crate::attributes::test_attrs::{
89+
IgnoreParser, RustcVarianceOfOpaquesParser, RustcVarianceParser, ShouldPanicParser,
90+
};
8991
use crate::attributes::traits::{
9092
AllowIncoherentImplParser, CoinductiveParser, DenyExplicitImplParser,
9193
DoNotImplementViaObjectParser, FundamentalParser, MarkerParser, ParenSugarParser,
@@ -221,6 +223,7 @@ attribute_parsers!(
221223
Single<ObjcClassParser>,
222224
Single<ObjcSelectorParser>,
223225
Single<OptimizeParser>,
226+
Single<PatchableFunctionEntryParser>,
224227
Single<PathAttributeParser>,
225228
Single<PatternComplexityLimitParser>,
226229
Single<ProcMacroDeriveParser>,
@@ -298,6 +301,8 @@ attribute_parsers!(
298301
Single<WithoutArgs<RustcPassIndirectlyInNonRusticAbisParser>>,
299302
Single<WithoutArgs<RustcReallocatorParser>>,
300303
Single<WithoutArgs<RustcShouldNotBeCalledOnConstItems>>,
304+
Single<WithoutArgs<RustcVarianceOfOpaquesParser>>,
305+
Single<WithoutArgs<RustcVarianceParser>>,
301306
Single<WithoutArgs<SpecializationTraitParser>>,
302307
Single<WithoutArgs<StdInternalSymbolParser>>,
303308
Single<WithoutArgs<ThreadLocalParser>>,
@@ -501,6 +506,18 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
501506
self.emit_parse_error(span, AttributeParseErrorReason::ExpectedIntegerLiteral)
502507
}
503508

509+
pub(crate) fn expected_integer_literal_in_range(
510+
&self,
511+
span: Span,
512+
lower_bound: isize,
513+
upper_bound: isize,
514+
) -> ErrorGuaranteed {
515+
self.emit_parse_error(
516+
span,
517+
AttributeParseErrorReason::ExpectedIntegerLiteralInRange { lower_bound, upper_bound },
518+
)
519+
}
520+
504521
pub(crate) fn expected_list(&self, span: Span, args: &ArgParser) -> ErrorGuaranteed {
505522
let span = match args {
506523
ArgParser::NoArgs => span,

compiler/rustc_attr_parsing/src/session_diagnostics.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,10 @@ pub(crate) enum AttributeParseErrorReason<'a> {
525525
byte_string: Option<Span>,
526526
},
527527
ExpectedIntegerLiteral,
528+
ExpectedIntegerLiteralInRange {
529+
lower_bound: isize,
530+
upper_bound: isize,
531+
},
528532
ExpectedAtLeastOneArgument,
529533
ExpectedSingleArgument,
530534
ExpectedList,
@@ -596,6 +600,17 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for AttributeParseError<'_> {
596600
AttributeParseErrorReason::ExpectedIntegerLiteral => {
597601
diag.span_label(self.span, "expected an integer literal here");
598602
}
603+
AttributeParseErrorReason::ExpectedIntegerLiteralInRange {
604+
lower_bound,
605+
upper_bound,
606+
} => {
607+
diag.span_label(
608+
self.span,
609+
format!(
610+
"expected an integer literal in the range of {lower_bound}..={upper_bound}"
611+
),
612+
);
613+
}
599614
AttributeParseErrorReason::ExpectedSingleArgument => {
600615
diag.span_label(self.span, "expected a single argument here");
601616
diag.code(E0805);

compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1506,7 +1506,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
15061506
}
15071507

15081508
// FIXME implement variadics in cranelift
1509-
sym::va_copy | sym::va_arg | sym::va_end => {
1509+
sym::va_arg | sym::va_end => {
15101510
fx.tcx.dcx().span_fatal(
15111511
source_info.span,
15121512
"Defining variadic functions is not yet supported by Cranelift",

compiler/rustc_codegen_gcc/src/intrinsic/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,6 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
391391
sym::breakpoint => {
392392
unimplemented!();
393393
}
394-
sym::va_copy => {
395-
unimplemented!();
396-
}
397394
sym::va_arg => {
398395
unimplemented!();
399396
}

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,12 @@ pub(crate) unsafe fn create_module<'ll>(
221221
target_data_layout = target_data_layout.replace("-m:e", "");
222222
}
223223
}
224+
if llvm_version < (23, 0, 0) {
225+
if sess.target.arch == Arch::S390x {
226+
// LLVM 23 updated the s390x layout to specify the stack alignment: https://github.com/llvm/llvm-project/pull/176041
227+
target_data_layout = target_data_layout.replace("-S64", "");
228+
}
229+
}
224230

225231
// Ensure the data-layout values hardcoded remain the defaults.
226232
{

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -269,14 +269,6 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
269269
return Ok(());
270270
}
271271
sym::breakpoint => self.call_intrinsic("llvm.debugtrap", &[], &[]),
272-
sym::va_copy => {
273-
let dest = args[0].immediate();
274-
self.call_intrinsic(
275-
"llvm.va_copy",
276-
&[self.val_ty(dest)],
277-
&[dest, args[1].immediate()],
278-
)
279-
}
280272
sym::va_arg => {
281273
match result.layout.backend_repr {
282274
BackendRepr::Scalar(scalar) => {

compiler/rustc_codegen_ssa/messages.ftl

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ codegen_ssa_error_creating_remark_dir = failed to create remark directory: {$err
4848
codegen_ssa_error_writing_def_file =
4949
error writing .DEF file: {$error}
5050
51-
codegen_ssa_expected_name_value_pair = expected name value pair
52-
5351
codegen_ssa_extern_funcs_not_found = some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
5452
5553
codegen_ssa_extract_bundled_libs_archive_member = failed to get data from archive member '{$rlib}': {$error}
@@ -90,9 +88,6 @@ codegen_ssa_incorrect_cgu_reuse_type =
9088
9189
codegen_ssa_insufficient_vs_code_product = VS Code is a different product, and is not sufficient.
9290
93-
codegen_ssa_invalid_literal_value = invalid literal value
94-
.label = value must be an integer between `0` and `255`
95-
9691
codegen_ssa_invalid_monomorphization_basic_float_type = invalid monomorphization of `{$name}` intrinsic: expected basic float type, found `{$ty}`
9792
9893
codegen_ssa_invalid_monomorphization_basic_integer_or_ptr_type = invalid monomorphization of `{$name}` intrinsic: expected basic integer or pointer type, found `{$ty}`
@@ -225,9 +220,6 @@ codegen_ssa_no_natvis_directory = error enumerating natvis directory: {$error}
225220
226221
codegen_ssa_no_saved_object_file = cached cgu {$cgu_name} should have an object file, but doesn't
227222
228-
codegen_ssa_out_of_range_integer = integer value out of range
229-
.label = value must be between `0` and `255`
230-
231223
codegen_ssa_processing_dymutil_failed = processing debug info with `dsymutil` failed: {$status}
232224
.note = {$output}
233225
@@ -357,9 +349,6 @@ codegen_ssa_unable_to_run_dsymutil = unable to run `dsymutil`: {$error}
357349
358350
codegen_ssa_unable_to_write_debugger_visualizer = unable to write debugger visualizer file `{$path}`: {$error}
359351
360-
codegen_ssa_unexpected_parameter_name = unexpected parameter name
361-
.label = expected `{$prefix_nops}` or `{$entry_nops}`
362-
363352
codegen_ssa_unknown_archive_kind =
364353
don't know how to build archive of type: {$kind}
365354

0 commit comments

Comments
 (0)