Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 33 additions & 0 deletions compiler/rustc_attr_parsing/src/attributes/cfi_encoding.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use super::prelude::*;
pub(crate) struct CfiEncodingParser;
impl<S: Stage> SingleAttributeParser<S> for CfiEncodingParser {
const PATH: &[Symbol] = &[sym::cfi_encoding];
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowListWarnRest(&[
Allow(Target::Struct),
Allow(Target::ForeignTy),
Allow(Target::Enum),
Allow(Target::Union),
]);
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "encoding");

fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
let Some(name_value) = args.name_value() else {
cx.expected_name_value(cx.attr_span, Some(sym::cfi_encoding));
return None;
};

let Some(value_str) = name_value.value_as_str() else {
cx.expected_string_literal(name_value.value_span, None);
return None;
};

if value_str.as_str().trim().is_empty() {
cx.expected_non_empty_string_literal(name_value.value_span);
return None;
}

Some(AttributeKind::CfiEncoding { encoding: value_str })
}
}
1 change: 1 addition & 0 deletions compiler/rustc_attr_parsing/src/attributes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub(crate) mod allow_unstable;
pub(crate) mod body;
pub(crate) mod cfg;
pub(crate) mod cfg_select;
pub(crate) mod cfi_encoding;
pub(crate) mod codegen_attrs;
pub(crate) mod confusables;
pub(crate) mod crate_level;
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_attr_parsing/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::attributes::allow_unstable::{
AllowConstFnUnstableParser, AllowInternalUnstableParser, UnstableFeatureBoundParser,
};
use crate::attributes::body::CoroutineParser;
use crate::attributes::cfi_encoding::CfiEncodingParser;
use crate::attributes::codegen_attrs::{
ColdParser, CoverageParser, EiiExternItemParser, ExportNameParser, ForceTargetFeatureParser,
NakedParser, NoMangleParser, ObjcClassParser, ObjcSelectorParser, OptimizeParser,
Expand Down Expand Up @@ -187,6 +188,7 @@ attribute_parsers!(
// tidy-alphabetical-end

// tidy-alphabetical-start
Single<CfiEncodingParser>,
Single<CoverageParser>,
Single<CrateNameParser>,
Single<CustomMirParser>,
Expand Down Expand Up @@ -498,6 +500,10 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
self.emit_parse_error(span, AttributeParseErrorReason::ExpectedNameValueOrNoArgs)
}

pub(crate) fn expected_non_empty_string_literal(&self, span: Span) -> ErrorGuaranteed {
self.emit_parse_error(span, AttributeParseErrorReason::ExpectedNonEmptyStringLiteral)
}

pub(crate) fn expected_no_args(&self, span: Span) -> ErrorGuaranteed {
self.emit_parse_error(span, AttributeParseErrorReason::ExpectedNoArgs)
}
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_attr_parsing/src/session_diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ pub(crate) enum AttributeParseErrorReason<'a> {
ExpectedList,
ExpectedListOrNoArgs,
ExpectedNameValueOrNoArgs,
ExpectedNonEmptyStringLiteral,
UnexpectedLiteral,
ExpectedNameValue(Option<Symbol>),
DuplicateKey(Symbol),
Expand Down Expand Up @@ -599,6 +600,9 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for AttributeParseError<'_> {
AttributeParseErrorReason::ExpectedNameValueOrNoArgs => {
diag.span_label(self.span, "didn't expect a list here");
}
AttributeParseErrorReason::ExpectedNonEmptyStringLiteral => {
diag.span_label(self.span, "string is not allowed to be empty");
}
AttributeParseErrorReason::DuplicateKey(key) => {
diag.span_label(self.span, format!("found `{key}` used as a key more than once"));
diag.code(E0538);
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_hir/src/attrs/data_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,9 @@ pub enum AttributeKind {
span: Span,
},

/// Represents `#[cfi_encoding]`
CfiEncoding { encoding: Symbol },

/// Represents `#[rustc_coinductive]`.
Coinductive(Span),

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir/src/attrs/encode_cross_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ impl AttributeKind {
AsPtr(..) => Yes,
AutomaticallyDerived(..) => Yes,
BodyStability { .. } => No,
CfiEncoding { .. } => Yes,
Coinductive(..) => No,
Cold(..) => No,
Confusables { .. } => Yes,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
| AttributeKind::PinV2(..)
| AttributeKind::WindowsSubsystem(..)
| AttributeKind::ThreadLocal
| AttributeKind::CfiEncoding { .. }
) => { /* do nothing */ }
Attribute::Unparsed(attr_item) => {
style = Some(attr_item.style);
Expand Down Expand Up @@ -336,7 +337,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
| sym::cfg_trace
| sym::cfg_attr_trace
// need to be fixed
| sym::cfi_encoding // FIXME(cfi_encoding)
| sym::instruction_set // broken on stable!!!
| sym::patchable_function_entry // FIXME(patchable_function_entry)
| sym::deprecated_safe // FIXME(deprecated_safe)
Expand Down
68 changes: 19 additions & 49 deletions compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ use rustc_abi::{ExternAbi, Integer};
use rustc_data_structures::base_n::{ALPHANUMERIC_ONLY, CASE_INSENSITIVE, ToBaseN};
use rustc_data_structures::fx::FxHashMap;
use rustc_hir as hir;
use rustc_hir::attrs::AttributeKind;
use rustc_hir::find_attr;
use rustc_middle::bug;
use rustc_middle::ty::layout::IntegerExt;
use rustc_middle::ty::{
self, Const, ExistentialPredicate, FloatTy, FnSig, GenericArg, GenericArgKind, GenericArgsRef,
IntTy, List, Region, RegionKind, TermKind, Ty, TyCtxt, TypeFoldable, UintTy,
};
use rustc_span::def_id::DefId;
use rustc_span::sym;
use tracing::instrument;

use crate::cfi::typeid::TypeIdOptions;
Expand Down Expand Up @@ -446,36 +447,20 @@ pub(crate) fn encode_ty<'tcx>(
ty::Adt(adt_def, args) => {
let mut s = String::new();
let def_id = adt_def.did();
if let Some(cfi_encoding) = tcx.get_attr(def_id, sym::cfi_encoding) {
if let Some(encoding) = find_attr!(tcx.get_all_attrs(def_id), AttributeKind::CfiEncoding { encoding } => encoding)
{
let encoding = encoding.as_str().trim();
// Use user-defined CFI encoding for type
if let Some(value_str) = cfi_encoding.value_str() {
let value_str = value_str.as_str().trim();
if !value_str.is_empty() {
s.push_str(value_str);
// Don't compress user-defined builtin types (see
// https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling-builtin and
// https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling-compression).
let builtin_types = [
"v", "w", "b", "c", "a", "h", "s", "t", "i", "j", "l", "m", "x", "y",
"n", "o", "f", "d", "e", "g", "z", "Dh",
];
if !builtin_types.contains(&value_str) {
compress(dict, DictKey::Ty(ty, TyQ::None), &mut s);
}
} else {
#[allow(
rustc::diagnostic_outside_of_impl,
rustc::untranslatable_diagnostic
)]
tcx.dcx()
.struct_span_err(
cfi_encoding.span(),
format!("invalid `cfi_encoding` for `{:?}`", ty.kind()),
)
.emit();
}
} else {
bug!("encode_ty: invalid `cfi_encoding` for `{:?}`", ty.kind());
s.push_str(&encoding);
// Don't compress user-defined builtin types (see
// https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling-builtin and
// https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling-compression).
let builtin_types = [
"v", "w", "b", "c", "a", "h", "s", "t", "i", "j", "l", "m", "x", "y", "n", "o",
"f", "d", "e", "g", "z", "Dh",
];
if !builtin_types.contains(&encoding) {
compress(dict, DictKey::Ty(ty, TyQ::None), &mut s);
}
} else if options.contains(EncodeTyOptions::GENERALIZE_REPR_C) && adt_def.repr().c() {
// For cross-language LLVM CFI support, the encoding must be compatible at the FFI
Expand Down Expand Up @@ -508,26 +493,11 @@ pub(crate) fn encode_ty<'tcx>(
ty::Foreign(def_id) => {
// <length><name>, where <name> is <unscoped-name>
let mut s = String::new();
if let Some(cfi_encoding) = tcx.get_attr(*def_id, sym::cfi_encoding) {

if let Some(encoding) = find_attr!(tcx.get_all_attrs(*def_id), AttributeKind::CfiEncoding {encoding} => encoding)
{
// Use user-defined CFI encoding for type
if let Some(value_str) = cfi_encoding.value_str() {
if !value_str.to_string().trim().is_empty() {
s.push_str(value_str.to_string().trim());
} else {
#[allow(
rustc::diagnostic_outside_of_impl,
rustc::untranslatable_diagnostic
)]
tcx.dcx()
.struct_span_err(
cfi_encoding.span(),
format!("invalid `cfi_encoding` for `{:?}`", ty.kind()),
)
.emit();
}
} else {
bug!("encode_ty: invalid `cfi_encoding` for `{:?}`", ty.kind());
}
s.push_str(encoding.as_str().trim());
} else {
let name = tcx.item_name(*def_id).to_string();
let _ = write!(s, "{}{}", name.len(), name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

use std::iter;

use rustc_hir as hir;
use rustc_hir::LangItem;
use rustc_hir::attrs::AttributeKind;
use rustc_hir::{self as hir, LangItem, find_attr};
use rustc_middle::bug;
use rustc_middle::ty::{
self, AssocContainer, ExistentialPredicateStableCmpExt as _, Instance, IntTy, List, TraitRef,
Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt, UintTy,
};
use rustc_span::DUMMY_SP;
use rustc_span::def_id::DefId;
use rustc_span::{DUMMY_SP, sym};
use rustc_trait_selection::traits;
use tracing::{debug, instrument};

Expand Down Expand Up @@ -138,7 +138,10 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for TransformTy<'tcx> {
{
// Don't transform repr(transparent) types with an user-defined CFI encoding to
// preserve the user-defined CFI encoding.
if let Some(_) = self.tcx.get_attr(adt_def.did(), sym::cfi_encoding) {
if find_attr!(
self.tcx.get_all_attrs(adt_def.did()),
AttributeKind::CfiEncoding { .. }
) {
return t;
}
let variant = adt_def.non_enum_variant();
Expand Down
12 changes: 7 additions & 5 deletions src/bootstrap/src/core/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ pub struct Finder {
path: OsString,
}

// During sanity checks, we search for target names to determine if they exist in the compiler's built-in
// target list (`rustc --print target-list`). While a target name may be present in the stage2 compiler,
// it might not yet be included in stage0. In such cases, we handle the targets missing from stage0 in this list.
//
// Targets can be removed from this list once they are present in the stage0 compiler (usually by updating the beta compiler of the bootstrap).
/// During sanity checks, we search for target tuples to determine if they exist in the compiler's
/// built-in target list (`rustc --print target-list`). While a target tuple may be present in the
/// in-tree compiler, the stage 0 compiler might not yet know about it (assuming not operating with
/// local-rebuild). In such cases, we handle the targets missing from stage 0 in this list.
///
/// Targets can be removed from this list during the usual release process bootstrap compiler bumps,
/// when the newly-bumped stage 0 compiler now knows about the formerly-missing targets.
const STAGE0_MISSING_TARGETS: &[&str] = &[
// just a dummy comment so the list doesn't get onelined
"riscv64im-unknown-none-elf",
Expand Down
8 changes: 6 additions & 2 deletions src/tools/tidy/src/target_specific_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ pub fn check(tests_path: &Path, tidy_ctx: TidyCtx) {
}
});

// Skip run-make tests as revisions are not supported.
if entry.path().strip_prefix(tests_path).is_ok_and(|rest| rest.starts_with("run-make")) {
// Skip run-make/run-make-cargo tests as revisions are not supported.
if entry
.path()
.strip_prefix(tests_path)
.is_ok_and(|rest| rest.starts_with("run-make") || rest.starts_with("run-make-cargo"))
{
return;
}

Expand Down
28 changes: 6 additions & 22 deletions tests/crashes/README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
This is serves as a collection of crashes so that accidental ICE fixes are tracked.
This was formally done at https://github.com/rust-lang/glacier but doing it inside
the rustc testsuite is more convenient.
Documentation on crash tests is at https://rustc-dev-guide.rust-lang.org/tests/compiletest#crash-tests.

It is imperative that a test in the suite causes an internal compiler error/panic
or makes rustc crash in some other way.
A test will "pass" if rustc exits with something other than 1 or 0.
Alternatively, you can build the documentation from this repository:

When adding crashes from https://github.com/rust-lang/rust/issues, the
issue number should be noted in the file name (12345.rs should suffice)
and also inside the file via `//@ known-bug #4321` if possible.
```console
mdbook serve --open src/doc/rustc-dev-guide
```

If you happen to fix one of the crashes, please move it to a fitting
subdirectory in `tests/ui` and give it a meaningful name.
Also please add a doc comment at the top of the file explaining why
this test exists. :)
Adding
Fixes #NNNNN
Fixes #MMMMM
to the description of your pull request will ensure the
corresponding tickets will be closed automatically upon merge.
The ticket ids can be found in the file name or the `known-bug` annotation
inside the testfile.

Please do not re-report any crashes that you find here!
The documentation will then be available at http://localhost:3000/tests/compiletest.html#crash-tests.
2 changes: 1 addition & 1 deletion tests/ui/attributes/malformed-attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ pub fn test3() {}
//~^ ERROR malformed
#[must_not_suspend()]
//~^ ERROR malformed
#[cfi_encoding]
#[cfi_encoding = ""]
//~^ ERROR malformed
struct Test;

Expand Down
15 changes: 9 additions & 6 deletions tests/ui/attributes/malformed-attrs.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ LL - #[must_not_suspend()]
LL + #[must_not_suspend]
|

error: malformed `cfi_encoding` attribute input
--> $DIR/malformed-attrs.rs:140:1
|
LL | #[cfi_encoding]
| ^^^^^^^^^^^^^^^ help: must be of the form: `#[cfi_encoding = "encoding"]`

error: malformed `allow` attribute input
--> $DIR/malformed-attrs.rs:184:1
|
Expand Down Expand Up @@ -530,6 +524,15 @@ LL | #[rustc_layout_scalar_valid_range_end]
| expected this to be a list
| help: must be of the form: `#[rustc_layout_scalar_valid_range_end(end)]`

error[E0539]: malformed `cfi_encoding` attribute input
--> $DIR/malformed-attrs.rs:140:1
|
LL | #[cfi_encoding = ""]
| ^^^^^^^^^^^^^^^^^--^
| | |
| | string is not allowed to be empty
| help: must be of the form: `#[cfi_encoding = "encoding"]`

error[E0565]: malformed `marker` attribute input
--> $DIR/malformed-attrs.rs:161:1
|
Expand Down
8 changes: 6 additions & 2 deletions tests/ui/sanitizer/cfi/invalid-attr-encoding.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
error: malformed `cfi_encoding` attribute input
error[E0539]: malformed `cfi_encoding` attribute input
--> $DIR/invalid-attr-encoding.rs:10:1
|
LL | #[cfi_encoding]
| ^^^^^^^^^^^^^^^ help: must be of the form: `#[cfi_encoding = "encoding"]`
| ^^^^^^^^^^^^^^^
| |
| expected this to be of the form `cfi_encoding = "..."`
| help: must be of the form: `#[cfi_encoding = "encoding"]`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0539`.
Loading