Skip to content

Commit

Permalink
Auto merge of rust-lang#129210 - tgross35:rollup-571noi5, r=tgross35
Browse files Browse the repository at this point in the history
Rollup of 6 pull requests

Successful merges:

 - rust-lang#128771 (Stabilize `unsafe_attributes`)
 - rust-lang#128982 (Re-enable more debuginfo tests on Windows)
 - rust-lang#129115 (Re-enable `dump-ice-to-disk` for Windows)
 - rust-lang#129173 (Fix `is_val_statically_known` for floats)
 - rust-lang#129185 (Port `run-make/libtest-json/validate_json.py` to Rust)
 - rust-lang#129190 (Added f16 and f128 to tests/ui/consts/const-float-bits-conv.rs)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Aug 17, 2024
2 parents feeba19 + b657787 commit 3560e3c
Show file tree
Hide file tree
Showing 55 changed files with 253 additions and 171 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 @@ -887,7 +887,7 @@ fn validate_generic_param_order(dcx: DiagCtxtHandle<'_>, generics: &[GenericPara

impl<'a> Visitor<'a> for AstValidator<'a> {
fn visit_attribute(&mut self, attr: &Attribute) {
validate_attr::check_attr(&self.features, &self.session.psess, attr);
validate_attr::check_attr(&self.session.psess, attr);
}

fn visit_ty(&mut self, ty: &'a Ty) {
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
gate_all!(mut_ref, "mutable by-reference bindings are experimental");
gate_all!(precise_capturing, "precise captures on `impl Trait` are experimental");
gate_all!(global_registration, "global registration is experimental");
gate_all!(unsafe_attributes, "`#[unsafe()]` markers for attributes are experimental");
gate_all!(return_type_notation, "return type notation is experimental");

if !visitor.features.never_patterns {
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_builtin_macros/src/cfg_accessible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ impl MultiItemModifier for Expander {
) -> ExpandResult<Vec<Annotatable>, Annotatable> {
let template = AttributeTemplate { list: Some("path"), ..Default::default() };
validate_attr::check_builtin_meta_item(
&ecx.ecfg.features,
&ecx.sess.psess,
meta_item,
ast::AttrStyle::Outer,
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_builtin_macros/src/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ impl MultiItemModifier for Expander {
let template =
AttributeTemplate { list: Some("Trait1, Trait2, ..."), ..Default::default() };
validate_attr::check_builtin_meta_item(
features,
&sess.psess,
meta_item,
ast::AttrStyle::Outer,
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_builtin_macros/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ pub(crate) fn check_builtin_macro_attribute(ecx: &ExtCtxt<'_>, meta_item: &MetaI
// All the built-in macro attributes are "words" at the moment.
let template = AttributeTemplate { word: true, ..Default::default() };
validate_attr::check_builtin_meta_item(
&ecx.ecfg.features,
&ecx.sess.psess,
meta_item,
AttrStyle::Outer,
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1000,8 +1000,10 @@ impl<'ll> CodegenCx<'ll, '_> {
ifn!("llvm.is.constant.i64", fn(t_i64) -> i1);
ifn!("llvm.is.constant.i128", fn(t_i128) -> i1);
ifn!("llvm.is.constant.isize", fn(t_isize) -> i1);
ifn!("llvm.is.constant.f16", fn(t_f16) -> i1);
ifn!("llvm.is.constant.f32", fn(t_f32) -> i1);
ifn!("llvm.is.constant.f64", fn(t_f64) -> i1);
ifn!("llvm.is.constant.f128", fn(t_f128) -> i1);
ifn!("llvm.is.constant.ptr", fn(ptr) -> i1);

ifn!("llvm.expect.i1", fn(i1, i1) -> i1);
Expand Down
22 changes: 15 additions & 7 deletions compiler/rustc_codegen_llvm/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,22 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {
}
sym::is_val_statically_known => {
let intrinsic_type = args[0].layout.immediate_llvm_type(self.cx);
match self.type_kind(intrinsic_type) {
TypeKind::Pointer | TypeKind::Integer | TypeKind::Float | TypeKind::Double => {
self.call_intrinsic(
&format!("llvm.is.constant.{:?}", intrinsic_type),
&[args[0].immediate()],
)
let kind = self.type_kind(intrinsic_type);
let intrinsic_name = match kind {
TypeKind::Pointer | TypeKind::Integer => {
Some(format!("llvm.is.constant.{intrinsic_type:?}"))
}
_ => self.const_bool(false),
// LLVM float types' intrinsic names differ from their type names.
TypeKind::Half => Some(format!("llvm.is.constant.f16")),
TypeKind::Float => Some(format!("llvm.is.constant.f32")),
TypeKind::Double => Some(format!("llvm.is.constant.f64")),
TypeKind::FP128 => Some(format!("llvm.is.constant.f128")),
_ => None,
};
if let Some(intrinsic_name) = intrinsic_name {
self.call_intrinsic(&intrinsic_name, &[args[0].immediate()])
} else {
self.const_bool(false)
}
}
sym::unlikely => self
Expand Down
13 changes: 2 additions & 11 deletions compiler/rustc_expand/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,7 @@ impl<'a> StripUnconfigured<'a> {
/// is in the original source file. Gives a compiler error if the syntax of
/// the attribute is incorrect.
pub(crate) fn expand_cfg_attr(&self, cfg_attr: &Attribute, recursive: bool) -> Vec<Attribute> {
validate_attr::check_attribute_safety(
self.features.unwrap_or(&Features::default()),
&self.sess.psess,
AttributeSafety::Normal,
&cfg_attr,
);
validate_attr::check_attribute_safety(&self.sess.psess, AttributeSafety::Normal, &cfg_attr);

let Some((cfg_predicate, expanded_attrs)) =
rustc_parse::parse_cfg_attr(cfg_attr, &self.sess.psess)
Expand Down Expand Up @@ -395,11 +390,7 @@ impl<'a> StripUnconfigured<'a> {
}
};

validate_attr::deny_builtin_meta_unsafety(
self.features.unwrap_or(&Features::default()),
&self.sess.psess,
&meta_item,
);
validate_attr::deny_builtin_meta_unsafety(&self.sess.psess, &meta_item);

(
parse_cfg(&meta_item, self.sess).map_or(true, |meta_item| {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1882,7 +1882,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
let mut span: Option<Span> = None;
while let Some(attr) = attrs.next() {
rustc_ast_passes::feature_gate::check_attribute(attr, self.cx.sess, features);
validate_attr::check_attr(features, &self.cx.sess.psess, attr);
validate_attr::check_attr(&self.cx.sess.psess, attr);

let current_span = if let Some(sp) = span { sp.to(attr.span) } else { attr.span };
span = Some(current_span);
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ declare_features! (
(accepted, universal_impl_trait, "1.26.0", Some(34511)),
/// Allows arbitrary delimited token streams in non-macro attributes.
(accepted, unrestricted_attribute_tokens, "1.34.0", Some(55208)),
/// Allows unsafe attributes.
(accepted, unsafe_attributes, "CURRENT_RUSTC_VERSION", Some(123757)),
/// The `unsafe_op_in_unsafe_fn` lint (allowed by default): no longer treat an unsafe function as an unsafe block.
(accepted, unsafe_block_in_unsafe_fn, "1.52.0", Some(71668)),
/// Allows unsafe on extern declarations and safety qualifiers over internal items.
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,8 +622,6 @@ declare_features! (
(unstable, type_changing_struct_update, "1.58.0", Some(86555)),
/// Allows unnamed fields of struct and union type
(incomplete, unnamed_fields, "1.74.0", Some(49804)),
/// Allows unsafe attributes.
(unstable, unsafe_attributes, "1.80.0", Some(123757)),
/// Allows const generic parameters to be defined with types that
/// are not `Sized`, e.g. `fn foo<const N: [u8]>() {`.
(incomplete, unsized_const_params, "CURRENT_RUSTC_VERSION", Some(95174)),
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4971,7 +4971,6 @@ declare_lint! {
/// ### Example
///
/// ```rust
/// #![feature(unsafe_attributes)]
/// #![warn(unsafe_attr_outside_unsafe)]
///
/// #[no_mangle]
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_parse/src/parser/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rustc_ast::token::{self, Delimiter};
use rustc_errors::codes::*;
use rustc_errors::{Diag, PResult};
use rustc_span::symbol::kw;
use rustc_span::{sym, BytePos, Span};
use rustc_span::{BytePos, Span};
use thin_vec::ThinVec;
use tracing::debug;

Expand Down Expand Up @@ -265,7 +265,6 @@ impl<'a> Parser<'a> {
let is_unsafe = this.eat_keyword(kw::Unsafe);
let unsafety = if is_unsafe {
let unsafe_span = this.prev_token.span;
this.psess.gated_spans.gate(sym::unsafe_attributes, unsafe_span);
this.expect(&token::OpenDelim(Delimiter::Parenthesis))?;
ast::Safety::Unsafe(unsafe_span)
} else {
Expand Down Expand Up @@ -406,7 +405,6 @@ impl<'a> Parser<'a> {
};
let unsafety = if is_unsafe {
let unsafe_span = self.prev_token.span;
self.psess.gated_spans.gate(sym::unsafe_attributes, unsafe_span);
self.expect(&token::OpenDelim(Delimiter::Parenthesis))?;

ast::Safety::Unsafe(unsafe_span)
Expand Down
40 changes: 13 additions & 27 deletions compiler/rustc_parse/src/validate_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ use rustc_ast::{
NestedMetaItem, Safety,
};
use rustc_errors::{Applicability, FatalError, PResult};
use rustc_feature::{
AttributeSafety, AttributeTemplate, BuiltinAttribute, Features, BUILTIN_ATTRIBUTE_MAP,
};
use rustc_feature::{AttributeSafety, AttributeTemplate, BuiltinAttribute, BUILTIN_ATTRIBUTE_MAP};
use rustc_session::errors::report_lit_error;
use rustc_session::lint::builtin::{ILL_FORMED_ATTRIBUTE_INPUT, UNSAFE_ATTR_OUTSIDE_UNSAFE};
use rustc_session::lint::BuiltinLintDiag;
Expand All @@ -18,7 +16,7 @@ use rustc_span::{sym, BytePos, Span, Symbol};

use crate::{errors, parse_in};

pub fn check_attr(features: &Features, psess: &ParseSess, attr: &Attribute) {
pub fn check_attr(psess: &ParseSess, attr: &Attribute) {
if attr.is_doc_comment() {
return;
}
Expand All @@ -28,17 +26,17 @@ pub fn check_attr(features: &Features, psess: &ParseSess, attr: &Attribute) {

// All non-builtin attributes are considered safe
let safety = attr_info.map(|x| x.safety).unwrap_or(AttributeSafety::Normal);
check_attribute_safety(features, psess, safety, attr);
check_attribute_safety(psess, safety, attr);

// Check input tokens for built-in and key-value attributes.
match attr_info {
// `rustc_dummy` doesn't have any restrictions specific to built-in attributes.
Some(BuiltinAttribute { name, template, .. }) if *name != sym::rustc_dummy => {
match parse_meta(psess, attr) {
// Don't check safety again, we just did that
Ok(meta) => check_builtin_meta_item(
features, psess, &meta, attr.style, *name, *template, false,
),
Ok(meta) => {
check_builtin_meta_item(psess, &meta, attr.style, *name, *template, false)
}
Err(err) => {
err.emit();
}
Expand Down Expand Up @@ -157,16 +155,7 @@ fn is_attr_template_compatible(template: &AttributeTemplate, meta: &ast::MetaIte
}
}

pub fn check_attribute_safety(
features: &Features,
psess: &ParseSess,
safety: AttributeSafety,
attr: &Attribute,
) {
if !features.unsafe_attributes {
return;
}

pub fn check_attribute_safety(psess: &ParseSess, safety: AttributeSafety, attr: &Attribute) {
let attr_item = attr.get_normal_item();

if safety == AttributeSafety::Unsafe {
Expand Down Expand Up @@ -215,21 +204,18 @@ pub fn check_attribute_safety(

// Called by `check_builtin_meta_item` and code that manually denies
// `unsafe(...)` in `cfg`
pub fn deny_builtin_meta_unsafety(features: &Features, psess: &ParseSess, meta: &MetaItem) {
pub fn deny_builtin_meta_unsafety(psess: &ParseSess, meta: &MetaItem) {
// This only supports denying unsafety right now - making builtin attributes
// support unsafety will requite us to thread the actual `Attribute` through
// for the nice diagnostics.
if features.unsafe_attributes {
if let Safety::Unsafe(unsafe_span) = meta.unsafety {
psess
.dcx()
.emit_err(errors::InvalidAttrUnsafe { span: unsafe_span, name: meta.path.clone() });
}
if let Safety::Unsafe(unsafe_span) = meta.unsafety {
psess
.dcx()
.emit_err(errors::InvalidAttrUnsafe { span: unsafe_span, name: meta.path.clone() });
}
}

pub fn check_builtin_meta_item(
features: &Features,
psess: &ParseSess,
meta: &MetaItem,
style: ast::AttrStyle,
Expand All @@ -246,7 +232,7 @@ pub fn check_builtin_meta_item(
}

if deny_unsafety {
deny_builtin_meta_unsafety(features, psess, meta);
deny_builtin_meta_unsafety(psess, meta);
}
}

Expand Down
1 change: 0 additions & 1 deletion src/tools/rustfmt/tests/target/unsafe_attributes.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(unsafe_attributes)]
// https:/rust-lang/rust/issues/123757
//
#![simple_ident]
Expand Down
81 changes: 79 additions & 2 deletions tests/codegen/is_val_statically_known.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//@ compile-flags: --crate-type=lib -Zmerge-functions=disabled -O

#![feature(core_intrinsics)]
#![feature(f16, f128)]

use std::intrinsics::is_val_statically_known;

Expand Down Expand Up @@ -49,7 +50,7 @@ pub fn _bool_false(b: bool) -> i32 {

#[inline]
pub fn _iref(a: &u8) -> i32 {
if unsafe { is_val_statically_known(a) } { 5 } else { 4 }
if is_val_statically_known(a) { 5 } else { 4 }
}

// CHECK-LABEL: @_iref_borrow(
Expand All @@ -68,7 +69,7 @@ pub fn _iref_arg(a: &u8) -> i32 {

#[inline]
pub fn _slice_ref(a: &[u8]) -> i32 {
if unsafe { is_val_statically_known(a) } { 7 } else { 6 }
if is_val_statically_known(a) { 7 } else { 6 }
}

// CHECK-LABEL: @_slice_ref_borrow(
Expand All @@ -84,3 +85,79 @@ pub fn _slice_ref_arg(a: &[u8]) -> i32 {
// CHECK: ret i32 6
_slice_ref(a)
}

#[inline]
pub fn _f16(a: f16) -> i32 {
if is_val_statically_known(a) { 1 } else { 0 }
}

// CHECK-LABEL: @_f16_true(
#[no_mangle]
pub fn _f16_true() -> i32 {
// CHECK: ret i32 1
_f16(1.0)
}

// CHECK-LABEL: @_f16_false(
#[no_mangle]
pub fn _f16_false(a: f16) -> i32 {
// CHECK: ret i32 0
_f16(a)
}

#[inline]
pub fn _f32(a: f32) -> i32 {
if is_val_statically_known(a) { 1 } else { 0 }
}

// CHECK-LABEL: @_f32_true(
#[no_mangle]
pub fn _f32_true() -> i32 {
// CHECK: ret i32 1
_f32(1.0)
}

// CHECK-LABEL: @_f32_false(
#[no_mangle]
pub fn _f32_false(a: f32) -> i32 {
// CHECK: ret i32 0
_f32(a)
}

#[inline]
pub fn _f64(a: f64) -> i32 {
if is_val_statically_known(a) { 1 } else { 0 }
}

// CHECK-LABEL: @_f64_true(
#[no_mangle]
pub fn _f64_true() -> i32 {
// CHECK: ret i32 1
_f64(1.0)
}

// CHECK-LABEL: @_f64_false(
#[no_mangle]
pub fn _f64_false(a: f64) -> i32 {
// CHECK: ret i32 0
_f64(a)
}

#[inline]
pub fn _f128(a: f128) -> i32 {
if is_val_statically_known(a) { 1 } else { 0 }
}

// CHECK-LABEL: @_f128_true(
#[no_mangle]
pub fn _f128_true() -> i32 {
// CHECK: ret i32 1
_f128(1.0)
}

// CHECK-LABEL: @_f128_false(
#[no_mangle]
pub fn _f128_false(a: f128) -> i32 {
// CHECK: ret i32 0
_f128(a)
}
1 change: 0 additions & 1 deletion tests/debuginfo/drop-locations.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//@ ignore-windows
//@ ignore-android
//@ min-lldb-version: 310
//@ ignore-test: #128971
Expand Down
2 changes: 1 addition & 1 deletion tests/debuginfo/embedded-visualizer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@ compile-flags:-g
//@ min-gdb-version: 8.1
//@ ignore-lldb
//@ ignore-windows-gnu // emit_debug_gdb_scripts is disabled on Windows
//@ ignore-windows-gnu: #128981

// === CDB TESTS ==================================================================================

Expand Down
2 changes: 1 addition & 1 deletion tests/debuginfo/empty-string.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ ignore-windows failing on win32 bot
//@ ignore-windows-gnu: #128981
//@ ignore-android: FIXME(#10381)
//@ compile-flags:-g
//@ min-gdb-version: 8.1
Expand Down
Loading

0 comments on commit 3560e3c

Please sign in to comment.