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
2 changes: 2 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3798,6 +3798,7 @@ dependencies = [
"rustc-demangle",
"rustc_abi",
"rustc_ast",
"rustc_attr_ir",
"rustc_codegen_ssa",
"rustc_crate_store",
"rustc_data_structures",
Expand Down Expand Up @@ -3837,6 +3838,7 @@ dependencies = [
"rustc_abi",
"rustc_arena",
"rustc_ast",
"rustc_attr_ir",
"rustc_attr_parsing",
"rustc_crate_store",
"rustc_data_structures",
Expand Down
7 changes: 5 additions & 2 deletions compiler/rustc_attr_ir/src/data_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use rustc_ast::token::DocFragmentKind;
use rustc_ast::{AttrStyle, Path, ast};
use rustc_data_structures::fx::FxIndexMap;
use rustc_error_messages::{DiagArgValue, IntoDiagArg};
use rustc_macros::{Decodable, Encodable, PrintAttribute, StableHash};
use rustc_macros::{
Decodable, Decodable_NoContext, Encodable, Encodable_NoContext, PrintAttribute, StableHash,
};
use rustc_span::def_id::DefId;
use rustc_span::hygiene::Transparency;
use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol};
Expand Down Expand Up @@ -108,7 +110,8 @@ pub enum InstructionSetAttr {
ArmT32,
}

#[derive(Copy, Clone, PartialEq, Encodable, Decodable, Debug, Eq, StableHash, PrintAttribute)]
#[derive(Copy, Clone, Debug)]
#[derive(Encodable_NoContext, Decodable_NoContext, StableHash, PrintAttribute)]
pub enum InstrumentFnAttr {
/// `#[instrument_fn = "on"]`
On,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_llvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ object = { version = "0.39.1", default-features = false, features = ["std", "rea
rustc-demangle = "0.1.28"
rustc_abi = { path = "../rustc_abi" }
rustc_ast = { path = "../rustc_ast" }
rustc_attr_ir = { path = "../rustc_attr_ir" }
rustc_codegen_ssa = { path = "../rustc_codegen_ssa" }
rustc_crate_store = { path = "../rustc_crate_store" }
rustc_data_structures = { path = "../rustc_data_structures" }
Expand Down
20 changes: 10 additions & 10 deletions compiler/rustc_codegen_llvm/src/attributes.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! Set and unset common attributes on LLVM values.
use rustc_hir::attrs::{InlineAttr, InstructionSetAttr, OptimizeAttr, RtsanSetting};
use rustc_attr_ir::{
InlineAttr, InstructionSetAttr, InstrumentFnAttr, OptimizeAttr, RtsanSetting, find_attr,
};
use rustc_hir::def_id::DefId;
use rustc_hir::find_attr;
use rustc_middle::middle::codegen_fn_attrs::{
CodegenFnAttrFlags, CodegenFnAttrs, InstrumentFnAttr, PatchableFunctionEntry, SanitizerFnAttrs,
TargetFeature,
CodegenFnAttrFlags, CodegenFnAttrs, PatchableFunctionEntry, SanitizerFnAttrs, TargetFeature,
};
use rustc_middle::ty::{self, Instance, TyCtxt};
use rustc_session::config::{
Expand Down Expand Up @@ -236,16 +236,16 @@ fn function_return_attr<'ll>(cx: &SimpleCx<'ll>, sess: &Session) -> Option<&'ll
fn instrument_function_attr<'ll>(
cx: &SimpleCx<'ll>,
sess: &Session,
instrument_fn: InstrumentFnAttr,
instrument_fn: Option<InstrumentFnAttr>,
) -> SmallVec<[&'ll Attribute; 4]> {
let mut attrs = SmallVec::new();
if sess.opts.unstable_opts.instrument_mcount != InstrumentMcount::Disabled {
// Similar to `clang -pg` behavior. Handled by the
// `post-inline-ee-instrument` LLVM pass.

let instrument_entry = match instrument_fn {
InstrumentFnAttr::Default | InstrumentFnAttr::On => true,
InstrumentFnAttr::Off => false,
Some(InstrumentFnAttr::On) | None => true,
Some(InstrumentFnAttr::Off) => false,
};

if instrument_entry {
Expand Down Expand Up @@ -290,13 +290,13 @@ fn instrument_function_attr<'ll>(

// always and never may be overridden by the #[instrument_fn = ...] attribute.
match instrument_fn {
InstrumentFnAttr::Default => {}
InstrumentFnAttr::On => {
Some(InstrumentFnAttr::On) => {
always = true;
}
InstrumentFnAttr::Off => {
Some(InstrumentFnAttr::Off) => {
never = true;
}
None => {}
}

if never {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_ssa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ regex = "1.4"
rustc_abi = { path = "../rustc_abi" }
rustc_arena = { path = "../rustc_arena" }
rustc_ast = { path = "../rustc_ast" }
rustc_attr_ir = { path = "../rustc_attr_ir" }
rustc_attr_parsing = { path = "../rustc_attr_parsing" }
rustc_crate_store = { path = "../rustc_crate_store" }
rustc_data_structures = { path = "../rustc_data_structures" }
Expand Down
15 changes: 6 additions & 9 deletions compiler/rustc_codegen_ssa/src/codegen_attrs.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use rustc_abi::{Align, ExternAbi};
use rustc_hir::attrs::{
AttributeKind, EiiImplResolution, InlineAttr, InstrumentFnAttr as HirInstrumentFnAttr, Linkage,
OptimizeAttr, RtsanSetting, UsedBy,
use rustc_attr_ir::{
Attribute, AttributeKind, EiiImplResolution, InlineAttr, Linkage, OptimizeAttr, RtsanSetting,
UsedBy, find_attr,
};
use rustc_hir as hir;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId};
use rustc_hir::{self as hir, Attribute, find_attr};
use rustc_lint_defs::builtin::{INLINE_NO_SANITIZE, RTSAN_NONBLOCKING_ASYNC};
use rustc_macros::Diagnostic;
use rustc_middle::bug;
use rustc_middle::middle::codegen_fn_attrs::{
CodegenFnAttrFlags, CodegenFnAttrs, InstrumentFnAttr, PatchableFunctionEntry, SanitizerFnAttrs,
CodegenFnAttrFlags, CodegenFnAttrs, PatchableFunctionEntry, SanitizerFnAttrs,
};
use rustc_middle::mono::Visibility;
use rustc_middle::query::Providers;
Expand Down Expand Up @@ -305,10 +305,7 @@ fn process_builtin_attrs(
));
}
AttributeKind::InstrumentFn(instrument_fn) => {
codegen_fn_attrs.instrument_fn = match instrument_fn {
HirInstrumentFnAttr::On => InstrumentFnAttr::On,
HirInstrumentFnAttr::Off => InstrumentFnAttr::Off,
};
codegen_fn_attrs.instrument_fn = Some(*instrument_fn);
}
_ => {}
}
Expand Down
24 changes: 5 additions & 19 deletions compiler/rustc_middle/src/middle/codegen_fn_attrs.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::borrow::Cow;

use rustc_abi::Align;
use rustc_hir::attrs::{InlineAttr, InstructionSetAttr, Linkage, OptimizeAttr, RtsanSetting};
use rustc_attr_ir::{
InlineAttr, InstructionSetAttr, InstrumentFnAttr, Linkage, OptimizeAttr, RtsanSetting,
};
use rustc_hir::def_id::DefId;
use rustc_macros::{StableHash, TyDecodable, TyEncodable};
use rustc_span::Symbol;
Expand Down Expand Up @@ -121,23 +123,7 @@ pub struct CodegenFnAttrs {
/// The `#[rustc_objc_selector = "..."]` attribute.
pub objc_selector: Option<Symbol>,
/// The `#[instrument_fn]` attribute.
pub instrument_fn: InstrumentFnAttr,
}

#[derive(Copy, Clone, TyEncodable, TyDecodable, StableHash, Debug)]
pub enum InstrumentFnAttr {
/// Always instrument function
On,
/// Never instrument function
Off,
/// Instrument based on command line options, if any.
Default,
}

const impl Default for InstrumentFnAttr {
fn default() -> Self {
InstrumentFnAttr::Default
}
pub instrument_fn: Option<InstrumentFnAttr>,
}

#[derive(Copy, Clone, Debug, TyEncodable, TyDecodable, StableHash, PartialEq, Eq)]
Expand Down Expand Up @@ -274,7 +260,7 @@ impl CodegenFnAttrs {
patchable_function_entry: None,
objc_class: None,
objc_selector: None,
instrument_fn: InstrumentFnAttr::default(),
instrument_fn: None,
}
}

Expand Down
Loading