Skip to content

Commit 1af0b65

Browse files
committed
Auto merge of #150146 - JonathanBrouwer:rollup-s1jdwck, r=JonathanBrouwer
Rollup of 4 pull requests Successful merges: - #147430 (cg_llvm: More preparation for moving FFI bindings to `rustc_llvm`) - #149815 (Add regression test for #120189) - #149947 (add several older crashtests) - #150127 (Port `#[rustc_lint_untracked_query_information]` and `#[rustc_lint_diagnostics]` to using attribute parsers) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 07a5b02 + d5adb7b commit 1af0b65

File tree

22 files changed

+245
-120
lines changed

22 files changed

+245
-120
lines changed

compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,21 @@ impl<S: Stage> SingleAttributeParser<S> for RustcLegacyConstGenericsParser {
117117
}
118118
}
119119

120+
pub(crate) struct RustcLintDiagnosticsParser;
121+
122+
impl<S: Stage> NoArgsAttributeParser<S> for RustcLintDiagnosticsParser {
123+
const PATH: &[Symbol] = &[sym::rustc_lint_diagnostics];
124+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
125+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
126+
Allow(Target::Fn),
127+
Allow(Target::Method(MethodKind::Inherent)),
128+
Allow(Target::Method(MethodKind::Trait { body: false })),
129+
Allow(Target::Method(MethodKind::Trait { body: true })),
130+
Allow(Target::Method(MethodKind::TraitImpl)),
131+
]);
132+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcLintDiagnostics;
133+
}
134+
120135
pub(crate) struct RustcLintOptDenyFieldAccessParser;
121136

122137
impl<S: Stage> SingleAttributeParser<S> for RustcLintOptDenyFieldAccessParser {
@@ -165,6 +180,22 @@ impl<S: Stage> NoArgsAttributeParser<S> for RustcLintQueryInstabilityParser {
165180
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcLintQueryInstability;
166181
}
167182

183+
pub(crate) struct RustcLintUntrackedQueryInformationParser;
184+
185+
impl<S: Stage> NoArgsAttributeParser<S> for RustcLintUntrackedQueryInformationParser {
186+
const PATH: &[Symbol] = &[sym::rustc_lint_untracked_query_information];
187+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
188+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
189+
Allow(Target::Fn),
190+
Allow(Target::Method(MethodKind::Inherent)),
191+
Allow(Target::Method(MethodKind::Trait { body: false })),
192+
Allow(Target::Method(MethodKind::Trait { body: true })),
193+
Allow(Target::Method(MethodKind::TraitImpl)),
194+
]);
195+
196+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcLintUntrackedQueryInformation;
197+
}
198+
168199
pub(crate) struct RustcObjectLifetimeDefaultParser;
169200

170201
impl<S: Stage> SingleAttributeParser<S> for RustcObjectLifetimeDefaultParser {

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ use crate::attributes::prototype::CustomMirParser;
6161
use crate::attributes::repr::{AlignParser, AlignStaticParser, ReprParser};
6262
use crate::attributes::rustc_internal::{
6363
RustcLayoutScalarValidRangeEndParser, RustcLayoutScalarValidRangeStartParser,
64-
RustcLegacyConstGenericsParser, RustcLintOptDenyFieldAccessParser, RustcLintOptTyParser,
65-
RustcLintQueryInstabilityParser, RustcMainParser, RustcNeverReturnsNullPointerParser,
64+
RustcLegacyConstGenericsParser, RustcLintDiagnosticsParser, RustcLintOptDenyFieldAccessParser,
65+
RustcLintOptTyParser, RustcLintQueryInstabilityParser,
66+
RustcLintUntrackedQueryInformationParser, RustcMainParser, RustcNeverReturnsNullPointerParser,
6667
RustcNoImplicitAutorefsParser, RustcObjectLifetimeDefaultParser, RustcScalableVectorParser,
6768
RustcSimdMonomorphizeLaneLimitParser,
6869
};
@@ -257,8 +258,10 @@ attribute_parsers!(
257258
Single<WithoutArgs<ProcMacroParser>>,
258259
Single<WithoutArgs<PubTransparentParser>>,
259260
Single<WithoutArgs<RustcCoherenceIsCoreParser>>,
261+
Single<WithoutArgs<RustcLintDiagnosticsParser>>,
260262
Single<WithoutArgs<RustcLintOptTyParser>>,
261263
Single<WithoutArgs<RustcLintQueryInstabilityParser>>,
264+
Single<WithoutArgs<RustcLintUntrackedQueryInformationParser>>,
262265
Single<WithoutArgs<RustcMainParser>>,
263266
Single<WithoutArgs<RustcNeverReturnsNullPointerParser>>,
264267
Single<WithoutArgs<RustcNoImplicitAutorefsParser>>,

compiler/rustc_codegen_llvm/src/debuginfo/di_builder.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,37 @@
1+
use std::ptr;
2+
13
use libc::c_uint;
24
use rustc_abi::Align;
35

46
use crate::llvm::debuginfo::DIBuilder;
5-
use crate::llvm::{self, ToLlvmBool};
7+
use crate::llvm::{self, Module, ToLlvmBool};
8+
9+
/// Owning pointer to a `DIBuilder<'ll>` that will dispose of the builder
10+
/// when dropped. Use `.as_ref()` to get the underlying `&DIBuilder`
11+
/// needed for debuginfo FFI calls.
12+
pub(crate) struct DIBuilderBox<'ll> {
13+
raw: ptr::NonNull<DIBuilder<'ll>>,
14+
}
15+
16+
impl<'ll> DIBuilderBox<'ll> {
17+
pub(crate) fn new(llmod: &'ll Module) -> Self {
18+
let raw = unsafe { llvm::LLVMCreateDIBuilder(llmod) };
19+
let raw = ptr::NonNull::new(raw).unwrap();
20+
Self { raw }
21+
}
22+
23+
pub(crate) fn as_ref(&self) -> &DIBuilder<'ll> {
24+
// SAFETY: This is an owning pointer, so `&DIBuilder` is valid
25+
// for as long as `&self` is.
26+
unsafe { self.raw.as_ref() }
27+
}
28+
}
29+
30+
impl<'ll> Drop for DIBuilderBox<'ll> {
31+
fn drop(&mut self) {
32+
unsafe { llvm::LLVMDisposeDIBuilder(self.raw) };
33+
}
34+
}
635

736
/// Extension trait for defining safe wrappers and helper methods on
837
/// `&DIBuilder<'ll>`, without requiring it to be defined in the same crate.

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ use self::namespace::mangled_name_of_instance;
3838
use self::utils::{DIB, create_DIArray, is_node_local_to_unit};
3939
use crate::builder::Builder;
4040
use crate::common::{AsCCharPtr, CodegenCx};
41+
use crate::debuginfo::di_builder::DIBuilderBox;
4142
use crate::llvm::debuginfo::{
42-
DIArray, DIBuilderBox, DIFile, DIFlags, DILexicalBlock, DILocation, DISPFlags, DIScope,
43+
DIArray, DIFile, DIFlags, DILexicalBlock, DILocation, DISPFlags, DIScope,
4344
DITemplateTypeParameter, DIType, DIVariable,
4445
};
4546
use crate::llvm::{self, Value};

compiler/rustc_codegen_llvm/src/llvm/conversions.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Conversions from backend-independent data types to/from LLVM FFI types.
22
3-
use rustc_codegen_ssa::common::{AtomicRmwBinOp, IntPredicate, RealPredicate};
3+
use rustc_codegen_ssa::common::{AtomicRmwBinOp, IntPredicate, RealPredicate, TypeKind};
44
use rustc_middle::ty::AtomicOrdering;
55
use rustc_session::config::DebugInfo;
66
use rustc_target::spec::SymbolVisibility;
@@ -9,10 +9,22 @@ use crate::llvm;
99

1010
/// Helper trait for converting backend-independent types to LLVM-specific
1111
/// types, for FFI purposes.
12+
///
13+
/// FIXME(#147327): These trait/method names were chosen to avoid churn in
14+
/// existing code, but are not great and could probably be made clearer.
1215
pub(crate) trait FromGeneric<T> {
1316
fn from_generic(other: T) -> Self;
1417
}
1518

19+
/// Helper trait for converting LLVM-specific types to backend-independent
20+
/// types, for FFI purposes.
21+
///
22+
/// FIXME(#147327): These trait/method names were chosen to avoid churn in
23+
/// existing code, but are not great and could probably be made clearer.
24+
pub(crate) trait ToGeneric<T> {
25+
fn to_generic(&self) -> T;
26+
}
27+
1628
impl FromGeneric<SymbolVisibility> for llvm::Visibility {
1729
fn from_generic(visibility: SymbolVisibility) -> Self {
1830
match visibility {
@@ -113,3 +125,29 @@ impl FromGeneric<DebugInfo> for llvm::debuginfo::DebugEmissionKind {
113125
}
114126
}
115127
}
128+
129+
impl ToGeneric<TypeKind> for llvm::TypeKind {
130+
fn to_generic(&self) -> TypeKind {
131+
match self {
132+
Self::Void => TypeKind::Void,
133+
Self::Half => TypeKind::Half,
134+
Self::Float => TypeKind::Float,
135+
Self::Double => TypeKind::Double,
136+
Self::X86_FP80 => TypeKind::X86_FP80,
137+
Self::FP128 => TypeKind::FP128,
138+
Self::PPC_FP128 => TypeKind::PPC_FP128,
139+
Self::Label => TypeKind::Label,
140+
Self::Integer => TypeKind::Integer,
141+
Self::Function => TypeKind::Function,
142+
Self::Struct => TypeKind::Struct,
143+
Self::Array => TypeKind::Array,
144+
Self::Pointer => TypeKind::Pointer,
145+
Self::Vector => TypeKind::Vector,
146+
Self::Metadata => TypeKind::Metadata,
147+
Self::Token => TypeKind::Token,
148+
Self::ScalableVector => TypeKind::ScalableVector,
149+
Self::BFloat => TypeKind::BFloat,
150+
Self::X86_AMX => TypeKind::X86_AMX,
151+
}
152+
}
153+
}

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -363,33 +363,6 @@ pub(crate) enum TypeKind {
363363
X86_AMX = 19,
364364
}
365365

366-
impl TypeKind {
367-
pub(crate) fn to_generic(self) -> rustc_codegen_ssa::common::TypeKind {
368-
use rustc_codegen_ssa::common::TypeKind as Common;
369-
match self {
370-
Self::Void => Common::Void,
371-
Self::Half => Common::Half,
372-
Self::Float => Common::Float,
373-
Self::Double => Common::Double,
374-
Self::X86_FP80 => Common::X86_FP80,
375-
Self::FP128 => Common::FP128,
376-
Self::PPC_FP128 => Common::PPC_FP128,
377-
Self::Label => Common::Label,
378-
Self::Integer => Common::Integer,
379-
Self::Function => Common::Function,
380-
Self::Struct => Common::Struct,
381-
Self::Array => Common::Array,
382-
Self::Pointer => Common::Pointer,
383-
Self::Vector => Common::Vector,
384-
Self::Metadata => Common::Metadata,
385-
Self::Token => Common::Token,
386-
Self::ScalableVector => Common::ScalableVector,
387-
Self::BFloat => Common::BFloat,
388-
Self::X86_AMX => Common::X86_AMX,
389-
}
390-
}
391-
}
392-
393366
/// LLVMAtomicRmwBinOp
394367
#[derive(Copy, Clone)]
395368
#[repr(C)]
@@ -738,12 +711,9 @@ unsafe extern "C" {
738711
pub(crate) type DiagnosticHandlerTy = unsafe extern "C" fn(&DiagnosticInfo, *mut c_void);
739712

740713
pub(crate) mod debuginfo {
741-
use std::ptr;
742-
743714
use bitflags::bitflags;
744715

745716
use super::{InvariantOpaque, Metadata};
746-
use crate::llvm::{self, Module};
747717

748718
/// Opaque target type for references to an LLVM debuginfo builder.
749719
///
@@ -756,33 +726,6 @@ pub(crate) mod debuginfo {
756726
#[repr(C)]
757727
pub(crate) struct DIBuilder<'ll>(InvariantOpaque<'ll>);
758728

759-
/// Owning pointer to a `DIBuilder<'ll>` that will dispose of the builder
760-
/// when dropped. Use `.as_ref()` to get the underlying `&DIBuilder`
761-
/// needed for debuginfo FFI calls.
762-
pub(crate) struct DIBuilderBox<'ll> {
763-
raw: ptr::NonNull<DIBuilder<'ll>>,
764-
}
765-
766-
impl<'ll> DIBuilderBox<'ll> {
767-
pub(crate) fn new(llmod: &'ll Module) -> Self {
768-
let raw = unsafe { llvm::LLVMCreateDIBuilder(llmod) };
769-
let raw = ptr::NonNull::new(raw).unwrap();
770-
Self { raw }
771-
}
772-
773-
pub(crate) fn as_ref(&self) -> &DIBuilder<'ll> {
774-
// SAFETY: This is an owning pointer, so `&DIBuilder` is valid
775-
// for as long as `&self` is.
776-
unsafe { self.raw.as_ref() }
777-
}
778-
}
779-
780-
impl<'ll> Drop for DIBuilderBox<'ll> {
781-
fn drop(&mut self) {
782-
unsafe { llvm::LLVMDisposeDIBuilder(self.raw) };
783-
}
784-
}
785-
786729
pub(crate) type DIDescriptor = Metadata;
787730
pub(crate) type DILocation = Metadata;
788731
pub(crate) type DIScope = DIDescriptor;

compiler/rustc_codegen_llvm/src/type_.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_target::callconv::{CastTarget, FnAbi};
1515
use crate::abi::{FnAbiLlvmExt, LlvmType};
1616
use crate::common;
1717
use crate::context::{CodegenCx, GenericCx, SCx};
18-
use crate::llvm::{self, FALSE, Metadata, TRUE, ToLlvmBool, Type, Value};
18+
use crate::llvm::{self, FALSE, Metadata, TRUE, ToGeneric, ToLlvmBool, Type, Value};
1919
use crate::type_of::LayoutLlvmExt;
2020

2121
impl PartialEq for Type {

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,9 @@ pub enum AttributeKind {
931931
/// Represents `#[rustc_legacy_const_generics]`
932932
RustcLegacyConstGenerics { fn_indexes: ThinVec<(usize, Span)>, attr_span: Span },
933933

934+
/// Represents `#[rustc_lint_diagnostics]`
935+
RustcLintDiagnostics,
936+
934937
/// Represents `#[rustc_lint_opt_deny_field_access]`
935938
RustcLintOptDenyFieldAccess { lint_message: Symbol },
936939

@@ -940,6 +943,9 @@ pub enum AttributeKind {
940943
/// Represents `#[rustc_lint_query_instability]`
941944
RustcLintQueryInstability,
942945

946+
/// Represents `#[rustc_lint_untracked_query_information]`
947+
RustcLintUntrackedQueryInformation,
948+
943949
/// Represents `#[rustc_main]`.
944950
RustcMain,
945951

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,11 @@ impl AttributeKind {
9494
RustcLayoutScalarValidRangeEnd(..) => Yes,
9595
RustcLayoutScalarValidRangeStart(..) => Yes,
9696
RustcLegacyConstGenerics { .. } => Yes,
97+
RustcLintDiagnostics => Yes,
9798
RustcLintOptDenyFieldAccess { .. } => Yes,
9899
RustcLintOptTy => Yes,
99100
RustcLintQueryInstability => Yes,
101+
RustcLintUntrackedQueryInformation => Yes,
100102
RustcMain => No,
101103
RustcNeverReturnsNullPointer => Yes,
102104
RustcNoImplicitAutorefs => Yes,

compiler/rustc_lint/src/internal.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ impl<'tcx> LateLintPass<'tcx> for QueryStability {
106106
);
107107
}
108108

109-
if cx.tcx.has_attr(def_id, sym::rustc_lint_untracked_query_information) {
109+
if find_attr!(
110+
cx.tcx.get_all_attrs(def_id),
111+
AttributeKind::RustcLintUntrackedQueryInformation
112+
) {
110113
cx.emit_span_lint(
111114
UNTRACKED_QUERY_INFORMATION,
112115
span,
@@ -606,14 +609,14 @@ impl Diagnostics {
606609
else {
607610
return;
608611
};
609-
let has_attr = cx.tcx.has_attr(inst.def_id(), sym::rustc_lint_diagnostics);
610-
if !has_attr {
612+
613+
if !find_attr!(cx.tcx.get_all_attrs(inst.def_id()), AttributeKind::RustcLintDiagnostics) {
611614
return;
612615
};
613616

614617
for (hir_id, _parent) in cx.tcx.hir_parent_iter(current_id) {
615618
if let Some(owner_did) = hir_id.as_owner()
616-
&& cx.tcx.has_attr(owner_did, sym::rustc_lint_diagnostics)
619+
&& find_attr!(cx.tcx.get_all_attrs(owner_did), AttributeKind::RustcLintDiagnostics)
617620
{
618621
// The parent method is marked with `#[rustc_lint_diagnostics]`
619622
return;

0 commit comments

Comments
 (0)