Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
1696f53
fix: rust-lang/rust#47446
sassman Oct 9, 2024
529aae6
wasi/fs: Improve stopping condition for <ReadDir as Iterator>::next
osiewicz Nov 18, 2024
ec5f41a
Run TLS destructors for wasm32-wasip1-threads
surban Nov 23, 2024
692c19a
Refactor ReadDir into a state machine
osiewicz Nov 26, 2024
f4ab982
chore: Improve doc comments
osiewicz Nov 26, 2024
9142cae
add `LinkageInfo` to keep track of how we figured out the linkage
folkertdev Aug 8, 2024
bdf64e1
squashed changes to inlining and const eval
folkertdev Jul 19, 2024
d67a5c0
test the new global asm output of naked functions
folkertdev Jul 19, 2024
a93192c
add `InstructionSetAttr::as_str` and make the type `Copy`
folkertdev Jul 20, 2024
49a297a
squashed changes to tests
folkertdev Jul 20, 2024
589ebb8
make naked functions always have external linkage *in LLVM*. If we do…
folkertdev Jul 26, 2024
2e24cdb
squashed changes:
folkertdev Aug 11, 2024
64420b6
skip `predefine_fn` for naked functions
folkertdev Nov 30, 2024
cf738f6
Revert "add `LinkageInfo` to keep track of how we figured out the lin…
folkertdev Nov 30, 2024
868668e
Run `cargo update` and update licenses
clubby789 Nov 25, 2024
4fe15b0
Use UNIX thread_local implementation for WASI.
surban Dec 3, 2024
30847eb
use vendor sources by default on dist tarballs
onur-ozkan Dec 4, 2024
a6aaef1
update `build.vendor` documentation
onur-ozkan Dec 4, 2024
9ca9b41
add a change entry for new default on `build.vendor`
onur-ozkan Dec 4, 2024
e4092bd
Fix compilation for wasm32-wasip1 (without threads).
surban Dec 5, 2024
4f16640
Add libc funcitons only for wasm32-wasip1-threads.
surban Dec 5, 2024
ac815ff
coverage: Prefer to visit nodes whose predecessors have been visited
Zalathar Dec 5, 2024
f3f7c20
coverage: Move `CoverageIdsInfo` into `mir::coverage`
Zalathar Dec 6, 2024
2022ef7
coverage: Use a query to find counters/expressions that must be zero
Zalathar Dec 6, 2024
4d2bfec
coverage: Remove FunctionCoverageCollector
Zalathar Dec 6, 2024
3a35fb6
coverage: Unused functions don't need to store `CoverageIdsInfo`
Zalathar Dec 8, 2024
9eb35a0
fix the `naked-asan` test
folkertdev Dec 1, 2024
2d8a871
Downgrade cc
clubby789 Dec 8, 2024
4f14890
Configure renovatebot
Kobzol Dec 9, 2024
ed8ee39
fix ICE on type error in promoted
RalfJung Dec 7, 2024
a9fc2e2
Add feature gate, not working yet
compiler-errors Nov 16, 2024
7951d19
Apply suggestions from code review
sassman Dec 9, 2024
3511a46
Implement projection and shim for AFIDT
compiler-errors Nov 16, 2024
b02fcc5
Rollup merge of #128004 - folkertdev:naked-fn-asm, r=Amanieu
fmease Dec 9, 2024
35fc15b
Rollup merge of #131558 - sassman:feat/warnin-for-no-mangle-together-…
fmease Dec 9, 2024
d0f329a
Rollup merge of #133122 - compiler-errors:afidt, r=oli-obk
fmease Dec 9, 2024
00a7584
Rollup merge of #133184 - osiewicz:wasm-fix-infinite-loop-in-remove-d…
fmease Dec 9, 2024
18419d0
Rollup merge of #133456 - clubby789:cargo-update, r=ChrisDenton
fmease Dec 9, 2024
2b252ba
Rollup merge of #133472 - rust-wasi-web:master, r=joboet
fmease Dec 9, 2024
0c87c3c
Rollup merge of #133853 - onur-ozkan:use-vendor-directory-on-dist-bui…
fmease Dec 9, 2024
69889fa
Rollup merge of #133946 - Zalathar:ready-first, r=oli-obk
fmease Dec 9, 2024
65e8897
Rollup merge of #134010 - RalfJung:promoted-type-error-ice, r=oli-obk
fmease Dec 9, 2024
ce27319
Rollup merge of #134029 - Zalathar:zero, r=oli-obk
fmease Dec 9, 2024
d5b0698
Rollup merge of #134071 - Kobzol:ci-renovatebot, r=MarcoIeni
fmease Dec 9, 2024
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: #47446
- Add test for issue 47446 - Implement the new lint lint_builtin_mixed_export_name_and_no_mangle - Add suggestion how to fix it
  • Loading branch information
sassman committed Nov 15, 2024
commit 1696f534abe0655ee43ed57972a62d1cce42c233
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3453,6 +3453,7 @@ dependencies = [
"rustc_abi",
"rustc_arena",
"rustc_ast",
"rustc_ast_pretty",
"rustc_attr",
"rustc_data_structures",
"rustc_errors",
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 @@ -17,6 +17,7 @@ regex = "1.4"
rustc_abi = { path = "../rustc_abi" }
rustc_arena = { path = "../rustc_arena" }
rustc_ast = { path = "../rustc_ast" }
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
rustc_attr = { path = "../rustc_attr" }
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_errors = { path = "../rustc_errors" }
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_codegen_ssa/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ codegen_ssa_missing_memory_ordering = Atomic intrinsic missing memory ordering
codegen_ssa_missing_query_depgraph =
found CGU-reuse attribute but `-Zquery-dep-graph` was not specified

codegen_ssa_mixed_export_name_and_no_mangle = `{$no_mangle_attr}` attribute may not be used in combination with `#[export_name]`
.label = `{$no_mangle_attr}` is ignored
.note = `#[export_name]` takes precedence
.suggestion = remove the `{$no_mangle_attr}` attribute

codegen_ssa_msvc_missing_linker = the msvc targets depend on the msvc linker but `link.exe` was not found

codegen_ssa_multiple_external_func_decl = multiple declarations of external function `{$function}` from library `{$library_name}` have different calling conventions
Expand Down
57 changes: 54 additions & 3 deletions compiler/rustc_codegen_ssa/src/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ use rustc_attr::{InlineAttr, InstructionSetAttr, OptimizeAttr, list_contains_nam
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::codes::*;
use rustc_errors::{DiagMessage, SubdiagMessage, struct_span_code_err};
use rustc_hir as hir;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId};
use rustc_hir::weak_lang_items::WEAK_LANG_ITEMS;
use rustc_hir::{LangItem, lang_items};
use rustc_hir::{self as hir, HirId, LangItem, lang_items};
use rustc_middle::middle::codegen_fn_attrs::{
CodegenFnAttrFlags, CodegenFnAttrs, PatchableFunctionEntry,
};
Expand Down Expand Up @@ -78,6 +77,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
let mut inline_span = None;
let mut link_ordinal_span = None;
let mut no_sanitize_span = None;
let mut mixed_export_name_no_mangle_lint_state = MixedExportNameAndNoMangleState::default();

for attr in attrs.iter() {
// In some cases, attribute are only valid on functions, but it's the `check_attr`
Expand Down Expand Up @@ -116,7 +116,12 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
sym::naked => codegen_fn_attrs.flags |= CodegenFnAttrFlags::NAKED,
sym::no_mangle => {
if tcx.opt_item_name(did.to_def_id()).is_some() {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_MANGLE
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_MANGLE;
mixed_export_name_no_mangle_lint_state.track_no_mangle(
attr.span,
tcx.local_def_id_to_hir_id(did),
rustc_ast_pretty::pprust::attribute_to_string(attr),
);
} else {
tcx.dcx()
.struct_span_err(
Expand Down Expand Up @@ -240,6 +245,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
.emit();
}
codegen_fn_attrs.export_name = Some(s);
mixed_export_name_no_mangle_lint_state.track_export_name(attr.span);
}
}
sym::target_feature => {
Expand Down Expand Up @@ -513,6 +519,8 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
}
}

mixed_export_name_no_mangle_lint_state.lint_if_mixed(tcx);

codegen_fn_attrs.inline = attrs.iter().fold(InlineAttr::None, |ia, attr| {
if !attr.has_name(sym::inline) {
return ia;
Expand Down Expand Up @@ -779,6 +787,49 @@ fn check_link_name_xor_ordinal(
}
}

#[derive(Default)]
struct MixedExportNameAndNoMangleState {
export_name: Option<Span>,
hir_id: Option<HirId>,
no_mangle: Option<Span>,
no_mangle_attr_name: Option<String>,
}

impl MixedExportNameAndNoMangleState {
fn track_export_name(&mut self, span: Span) {
self.export_name = Some(span);
}

fn track_no_mangle(&mut self, span: Span, hir_id: HirId, attr_name: String) {
self.no_mangle = Some(span);
self.hir_id = Some(hir_id);
self.no_mangle_attr_name = Some(attr_name);
}

/// Emit diagnostics if the lint condition is met.
fn lint_if_mixed(self, tcx: TyCtxt<'_>) {
if let Self {
export_name: Some(export_name),
no_mangle: Some(no_mangle),
hir_id: Some(hir_id),
no_mangle_attr_name: Some(no_mangle_attr_name),
} = self
{
tcx.emit_node_span_lint(
lint::builtin::UNUSED_ATTRIBUTES,
hir_id,
no_mangle,
errors::MixedExportNameAndNoMangle {
no_mangle,
no_mangle_attr: no_mangle_attr_name,
export_name,
removal_span: no_mangle,
},
);
}
}
}

pub(crate) fn provide(providers: &mut Providers) {
*providers = Providers { codegen_fn_attrs, should_inherit_track_caller, ..*providers };
}
14 changes: 13 additions & 1 deletion compiler/rustc_codegen_ssa/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rustc_errors::codes::*;
use rustc_errors::{
Diag, DiagArgValue, DiagCtxtHandle, Diagnostic, EmissionGuarantee, IntoDiagArg, Level,
};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_middle::ty::Ty;
use rustc_middle::ty::layout::LayoutError;
use rustc_span::{Span, Symbol};
Expand Down Expand Up @@ -1114,3 +1114,15 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for TargetFeatureDisableOrEnable<'_
#[derive(Diagnostic)]
#[diag(codegen_ssa_aix_strip_not_used)]
pub(crate) struct AixStripNotUsed;

#[derive(LintDiagnostic)]
#[diag(codegen_ssa_mixed_export_name_and_no_mangle)]
pub(crate) struct MixedExportNameAndNoMangle {
#[label]
pub no_mangle: Span,
pub no_mangle_attr: String,
#[note]
pub export_name: Span,
#[suggestion(style = "verbose", code = "", applicability = "machine-applicable")]
pub removal_span: Span,
}
1 change: 0 additions & 1 deletion tests/ui/asm/naked-functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ pub unsafe extern "C" fn compatible_must_use_attributes() -> u64 {

#[export_name = "exported_function_name"]
#[link_section = ".custom_section"]
#[no_mangle]
#[naked]
pub unsafe extern "C" fn compatible_ffi_attributes_1() {
naked_asm!("", options(raw));
Expand Down
14 changes: 14 additions & 0 deletions tests/ui/attributes/mixed_export_name_and_no_mangle.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// issue: rust-lang/rust#47446
//@ run-rustfix
//@ check-pass

#![warn(unused_attributes)]
//~^ WARN `#[no_mangle]` attribute may not be used in combination with `#[export_name]` [unused_attributes]
#[export_name = "foo"]
pub fn bar() {}

//~^ WARN `#[unsafe(no_mangle)]` attribute may not be used in combination with `#[export_name]` [unused_attributes]
#[export_name = "baz"]
pub fn bak() {}

fn main() {}
16 changes: 16 additions & 0 deletions tests/ui/attributes/mixed_export_name_and_no_mangle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// issue: rust-lang/rust#47446
//@ run-rustfix
//@ check-pass

#![warn(unused_attributes)]
#[no_mangle]
//~^ WARN `#[no_mangle]` attribute may not be used in combination with `#[export_name]` [unused_attributes]
#[export_name = "foo"]
pub fn bar() {}

#[unsafe(no_mangle)]
//~^ WARN `#[unsafe(no_mangle)]` attribute may not be used in combination with `#[export_name]` [unused_attributes]
#[export_name = "baz"]
pub fn bak() {}

fn main() {}
39 changes: 39 additions & 0 deletions tests/ui/attributes/mixed_export_name_and_no_mangle.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
warning: `#[no_mangle]` attribute may not be used in combination with `#[export_name]`
--> $DIR/mixed_export_name_and_no_mangle.rs:6:1
|
LL | #[no_mangle]
| ^^^^^^^^^^^^ `#[no_mangle]` is ignored
|
note: `#[export_name]` takes precedence
--> $DIR/mixed_export_name_and_no_mangle.rs:8:1
|
LL | #[export_name = "foo"]
| ^^^^^^^^^^^^^^^^^^^^^^
note: the lint level is defined here
--> $DIR/mixed_export_name_and_no_mangle.rs:5:9
|
LL | #![warn(unused_attributes)]
| ^^^^^^^^^^^^^^^^^
help: remove the `#[no_mangle]` attribute
|
LL - #[no_mangle]
|

warning: `#[unsafe(no_mangle)]` attribute may not be used in combination with `#[export_name]`
--> $DIR/mixed_export_name_and_no_mangle.rs:11:1
|
LL | #[unsafe(no_mangle)]
| ^^^^^^^^^^^^^^^^^^^^ `#[unsafe(no_mangle)]` is ignored
|
note: `#[export_name]` takes precedence
--> $DIR/mixed_export_name_and_no_mangle.rs:13:1
|
LL | #[export_name = "baz"]
| ^^^^^^^^^^^^^^^^^^^^^^
help: remove the `#[unsafe(no_mangle)]` attribute
|
LL - #[unsafe(no_mangle)]
|

warning: 2 warnings emitted

Loading