diff options
18 files changed, 133 insertions, 152 deletions
diff --git a/compiler/rustc_codegen_llvm/src/asm.rs b/compiler/rustc_codegen_llvm/src/asm.rs index e481b99afcc..9e3893d5314 100644 --- a/compiler/rustc_codegen_llvm/src/asm.rs +++ b/compiler/rustc_codegen_llvm/src/asm.rs @@ -14,7 +14,7 @@ use smallvec::SmallVec; use tracing::debug; use crate::builder::Builder; -use crate::common::{AsCCharPtr, Funclet}; +use crate::common::Funclet; use crate::context::CodegenCx; use crate::type_::Type; use crate::type_of::LayoutLlvmExt; @@ -435,13 +435,7 @@ impl<'tcx> AsmCodegenMethods<'tcx> for CodegenCx<'_, 'tcx> { template_str.push_str("\n.att_syntax\n"); } - unsafe { - llvm::LLVMAppendModuleInlineAsm( - self.llmod, - template_str.as_c_char_ptr(), - template_str.len(), - ); - } + llvm::append_module_inline_asm(self.llmod, template_str.as_bytes()); } fn mangled_name(&self, instance: Instance<'tcx>) -> String { @@ -482,67 +476,67 @@ pub(crate) fn inline_asm_call<'ll>( debug!("Asm Output Type: {:?}", output); let fty = bx.cx.type_func(&argtys, output); + // Ask LLVM to verify that the constraints are well-formed. - let constraints_ok = - unsafe { llvm::LLVMRustInlineAsmVerify(fty, cons.as_c_char_ptr(), cons.len()) }; + let constraints_ok = unsafe { llvm::LLVMRustInlineAsmVerify(fty, cons.as_ptr(), cons.len()) }; debug!("constraint verification result: {:?}", constraints_ok); - if constraints_ok { - let v = unsafe { - llvm::LLVMRustInlineAsm( - fty, - asm.as_c_char_ptr(), - asm.len(), - cons.as_c_char_ptr(), - cons.len(), - volatile, - alignstack, - dia, - can_throw, - ) - }; + if !constraints_ok { + // LLVM has detected an issue with our constraints, so bail out. + return None; + } - let call = if !labels.is_empty() { - assert!(catch_funclet.is_none()); - bx.callbr(fty, None, None, v, inputs, dest.unwrap(), labels, None, None) - } else if let Some((catch, funclet)) = catch_funclet { - bx.invoke(fty, None, None, v, inputs, dest.unwrap(), catch, funclet, None) - } else { - bx.call(fty, None, None, v, inputs, None, None) - }; + let v = unsafe { + llvm::LLVMGetInlineAsm( + fty, + asm.as_ptr(), + asm.len(), + cons.as_ptr(), + cons.len(), + volatile, + alignstack, + dia, + can_throw, + ) + }; - // Store mark in a metadata node so we can map LLVM errors - // back to source locations. See #17552. - let key = "srcloc"; - let kind = bx.get_md_kind_id(key); + let call = if !labels.is_empty() { + assert!(catch_funclet.is_none()); + bx.callbr(fty, None, None, v, inputs, dest.unwrap(), labels, None, None) + } else if let Some((catch, funclet)) = catch_funclet { + bx.invoke(fty, None, None, v, inputs, dest.unwrap(), catch, funclet, None) + } else { + bx.call(fty, None, None, v, inputs, None, None) + }; - // `srcloc` contains one 64-bit integer for each line of assembly code, - // where the lower 32 bits hold the lo byte position and the upper 32 bits - // hold the hi byte position. - let mut srcloc = vec![]; - if dia == llvm::AsmDialect::Intel && line_spans.len() > 1 { - // LLVM inserts an extra line to add the ".intel_syntax", so add - // a dummy srcloc entry for it. - // - // Don't do this if we only have 1 line span since that may be - // due to the asm template string coming from a macro. LLVM will - // default to the first srcloc for lines that don't have an - // associated srcloc. - srcloc.push(llvm::LLVMValueAsMetadata(bx.const_u64(0))); - } - srcloc.extend(line_spans.iter().map(|span| { - llvm::LLVMValueAsMetadata( - bx.const_u64(u64::from(span.lo().to_u32()) | (u64::from(span.hi().to_u32()) << 32)), - ) - })); - let md = unsafe { llvm::LLVMMDNodeInContext2(bx.llcx, srcloc.as_ptr(), srcloc.len()) }; - let md = bx.get_metadata_value(md); - llvm::LLVMSetMetadata(call, kind, md); + // Store mark in a metadata node so we can map LLVM errors + // back to source locations. See #17552. + let key = "srcloc"; + let kind = bx.get_md_kind_id(key); - Some(call) - } else { - // LLVM has detected an issue with our constraints, bail out - None + // `srcloc` contains one 64-bit integer for each line of assembly code, + // where the lower 32 bits hold the lo byte position and the upper 32 bits + // hold the hi byte position. + let mut srcloc = vec![]; + if dia == llvm::AsmDialect::Intel && line_spans.len() > 1 { + // LLVM inserts an extra line to add the ".intel_syntax", so add + // a dummy srcloc entry for it. + // + // Don't do this if we only have 1 line span since that may be + // due to the asm template string coming from a macro. LLVM will + // default to the first srcloc for lines that don't have an + // associated srcloc. + srcloc.push(llvm::LLVMValueAsMetadata(bx.const_u64(0))); } + srcloc.extend(line_spans.iter().map(|span| { + llvm::LLVMValueAsMetadata( + bx.const_u64(u64::from(span.lo().to_u32()) | (u64::from(span.hi().to_u32()) << 32)), + ) + })); + let md = unsafe { llvm::LLVMMDNodeInContext2(bx.llcx, srcloc.as_ptr(), srcloc.len()) }; + let md = bx.get_metadata_value(md); + llvm::LLVMSetMetadata(call, kind, md); + + Some(call) } /// If the register is an xmm/ymm/zmm register then return its index. diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs index 4ac77c8f7f1..20721c74608 100644 --- a/compiler/rustc_codegen_llvm/src/back/write.rs +++ b/compiler/rustc_codegen_llvm/src/back/write.rs @@ -1148,9 +1148,9 @@ unsafe fn embed_bitcode( // We need custom section flags, so emit module-level inline assembly. let section_flags = if cgcx.is_pe_coff { "n" } else { "e" }; let asm = create_section_with_flags_asm(".llvmbc", section_flags, bitcode); - llvm::LLVMAppendModuleInlineAsm(llmod, asm.as_c_char_ptr(), asm.len()); + llvm::append_module_inline_asm(llmod, &asm); let asm = create_section_with_flags_asm(".llvmcmd", section_flags, cmdline.as_bytes()); - llvm::LLVMAppendModuleInlineAsm(llmod, asm.as_c_char_ptr(), asm.len()); + llvm::append_module_inline_asm(llmod, &asm); } } } diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index a249cb86ed4..67a66e6ec79 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -1,7 +1,7 @@ //! Bindings to the LLVM-C API (`LLVM*`), and to our own `extern "C"` wrapper //! functions around the unstable LLVM C++ API (`LLVMRust*`). //! -//! ## Passing pointer/length strings as `*const c_uchar` +//! ## Passing pointer/length strings as `*const c_uchar` (PTR_LEN_STR) //! //! Normally it's a good idea for Rust-side bindings to match the corresponding //! C-side function declarations as closely as possible. But when passing `&str` @@ -471,7 +471,7 @@ pub(crate) enum MetadataType { MD_kcfi_type = 36, } -/// LLVMRustAsmDialect +/// Must match the layout of `LLVMInlineAsmDialect`. #[derive(Copy, Clone, PartialEq)] #[repr(C)] pub(crate) enum AsmDialect { @@ -1014,8 +1014,25 @@ unsafe extern "C" { pub(crate) fn LLVMGetDataLayoutStr(M: &Module) -> *const c_char; pub(crate) fn LLVMSetDataLayout(M: &Module, Triple: *const c_char); - /// See Module::setModuleInlineAsm. - pub(crate) fn LLVMAppendModuleInlineAsm(M: &Module, Asm: *const c_char, Len: size_t); + /// Append inline assembly to a module. See `Module::appendModuleInlineAsm`. + pub(crate) fn LLVMAppendModuleInlineAsm( + M: &Module, + Asm: *const c_uchar, // See "PTR_LEN_STR". + Len: size_t, + ); + + /// Create the specified uniqued inline asm string. See `InlineAsm::get()`. + pub(crate) fn LLVMGetInlineAsm<'ll>( + Ty: &'ll Type, + AsmString: *const c_uchar, // See "PTR_LEN_STR". + AsmStringSize: size_t, + Constraints: *const c_uchar, // See "PTR_LEN_STR". + ConstraintsSize: size_t, + HasSideEffects: llvm::Bool, + IsAlignStack: llvm::Bool, + Dialect: AsmDialect, + CanThrow: llvm::Bool, + ) -> &'ll Value; // Operations on integer types pub(crate) fn LLVMInt1TypeInContext(C: &Context) -> &Type; @@ -1766,7 +1783,7 @@ unsafe extern "C" { pub(crate) fn LLVMDIBuilderCreateNameSpace<'ll>( Builder: &DIBuilder<'ll>, ParentScope: Option<&'ll Metadata>, - Name: *const c_uchar, + Name: *const c_uchar, // See "PTR_LEN_STR". NameLen: size_t, ExportSymbols: llvm::Bool, ) -> &'ll Metadata; @@ -1994,21 +2011,9 @@ unsafe extern "C" { /// Prints the statistics collected by `-Zprint-codegen-stats`. pub(crate) fn LLVMRustPrintStatistics(OutStr: &RustString); - /// Prepares inline assembly. - pub(crate) fn LLVMRustInlineAsm( - Ty: &Type, - AsmString: *const c_char, - AsmStringLen: size_t, - Constraints: *const c_char, - ConstraintsLen: size_t, - SideEffects: Bool, - AlignStack: Bool, - Dialect: AsmDialect, - CanThrow: Bool, - ) -> &Value; pub(crate) fn LLVMRustInlineAsmVerify( Ty: &Type, - Constraints: *const c_char, + Constraints: *const c_uchar, // See "PTR_LEN_STR". ConstraintsLen: size_t, ) -> bool; diff --git a/compiler/rustc_codegen_llvm/src/llvm/mod.rs b/compiler/rustc_codegen_llvm/src/llvm/mod.rs index 606d97619a0..ed23f911930 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/mod.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/mod.rs @@ -441,3 +441,11 @@ pub(crate) fn set_dso_local<'ll>(v: &'ll Value) { LLVMRustSetDSOLocal(v, true); } } + +/// Safe wrapper for `LLVMAppendModuleInlineAsm`, which delegates to +/// `Module::appendModuleInlineAsm`. +pub(crate) fn append_module_inline_asm<'ll>(llmod: &'ll Module, asm: &[u8]) { + unsafe { + LLVMAppendModuleInlineAsm(llmod, asm.as_ptr(), asm.len()); + } +} diff --git a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp index 72369ab7b69..90aa9188c83 100644 --- a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp @@ -622,37 +622,10 @@ extern "C" LLVMValueRef LLVMRustBuildAtomicStore(LLVMBuilderRef B, return wrap(SI); } -enum class LLVMRustAsmDialect { - Att, - Intel, -}; - -static InlineAsm::AsmDialect fromRust(LLVMRustAsmDialect Dialect) { - switch (Dialect) { - case LLVMRustAsmDialect::Att: - return InlineAsm::AD_ATT; - case LLVMRustAsmDialect::Intel: - return InlineAsm::AD_Intel; - default: - report_fatal_error("bad AsmDialect."); - } -} - extern "C" uint64_t LLVMRustGetArrayNumElements(LLVMTypeRef Ty) { return unwrap(Ty)->getArrayNumElements(); } -extern "C" LLVMValueRef -LLVMRustInlineAsm(LLVMTypeRef Ty, char *AsmString, size_t AsmStringLen, - char *Constraints, size_t ConstraintsLen, - LLVMBool HasSideEffects, LLVMBool IsAlignStack, - LLVMRustAsmDialect Dialect, LLVMBool CanThrow) { - return wrap(InlineAsm::get( - unwrap<FunctionType>(Ty), StringRef(AsmString, AsmStringLen), - StringRef(Constraints, ConstraintsLen), HasSideEffects, IsAlignStack, - fromRust(Dialect), CanThrow)); -} - extern "C" bool LLVMRustInlineAsmVerify(LLVMTypeRef Ty, char *Constraints, size_t ConstraintsLen) { // llvm::Error converts to true if it is an error. diff --git a/src/bootstrap/defaults/bootstrap.compiler.toml b/src/bootstrap/defaults/bootstrap.compiler.toml index 269b90106e3..9dcb20ed483 100644 --- a/src/bootstrap/defaults/bootstrap.compiler.toml +++ b/src/bootstrap/defaults/bootstrap.compiler.toml @@ -30,8 +30,6 @@ download-rustc = false # Having this set to true disrupts compiler development workflows for people who use `llvm.download-ci-llvm = true` # because we don't provide ci-llvm on the `rustc-alt-builds` server. Therefore, it is kept off by default. assertions = false -# Enable warnings during the LLVM compilation (when LLVM is changed, causing a compilation) -enable-warnings = true # Will download LLVM from CI if available on your platform. # If you intend to modify `src/llvm-project`, use `"if-unchanged"` or `false` instead. download-ci-llvm = true diff --git a/src/tools/tidy/src/issues.txt b/src/tools/tidy/src/issues.txt index 2f0158609e0..2c20e21f451 100644 --- a/src/tools/tidy/src/issues.txt +++ b/src/tools/tidy/src/issues.txt @@ -2212,7 +2212,6 @@ ui/issues/issue-41479.rs ui/issues/issue-41498.rs ui/issues/issue-41549.rs ui/issues/issue-41604.rs -ui/issues/issue-41628.rs ui/issues/issue-41652/auxiliary/issue-41652-b.rs ui/issues/issue-41652/issue-41652.rs ui/issues/issue-41677.rs diff --git a/src/tools/tidy/src/ui_tests.rs b/src/tools/tidy/src/ui_tests.rs index 44dd1e50f5b..8f9b07c49ac 100644 --- a/src/tools/tidy/src/ui_tests.rs +++ b/src/tools/tidy/src/ui_tests.rs @@ -17,7 +17,7 @@ use ignore::Walk; const ENTRY_LIMIT: u32 = 901; // FIXME: The following limits should be reduced eventually. -const ISSUES_ENTRY_LIMIT: u32 = 1624; +const ISSUES_ENTRY_LIMIT: u32 = 1623; const EXPECTED_TEST_FILE_EXTENSIONS: &[&str] = &[ "rs", // test source files diff --git a/tests/ui/async-await/async-drop/async-drop-initial.rs b/tests/ui/async-await/async-drop/async-drop-initial.rs index 80b34840c8b..263b70699f5 100644 --- a/tests/ui/async-await/async-drop/async-drop-initial.rs +++ b/tests/ui/async-await/async-drop/async-drop-initial.rs @@ -60,7 +60,10 @@ fn main() { let j = 42; test_async_drop(&i, 16).await; test_async_drop(&j, 16).await; - test_async_drop(AsyncStruct { b: AsyncInt(8), a: AsyncInt(7), i: 6 }, 168).await; + test_async_drop( + AsyncStruct { b: AsyncInt(8), a: AsyncInt(7), i: 6 }, + if cfg!(panic = "unwind") { 168 } else { 136 }, + ).await; test_async_drop(ManuallyDrop::new(AsyncInt(9)), 16).await; let foo = AsyncInt(10); diff --git a/tests/ui/used.rs b/tests/ui/attributes/positions/used.rs index f008724f428..7950fa773a1 100644 --- a/tests/ui/used.rs +++ b/tests/ui/attributes/positions/used.rs @@ -1,3 +1,6 @@ +//! Checks that `#[used]` cannot be used on invalid positions. +#![crate_type = "lib"] + #[used] static FOO: u32 = 0; // OK @@ -13,4 +16,8 @@ trait Bar {} #[used] //~ ERROR attribute must be applied to a `static` variable impl Bar for Foo {} -fn main() {} +// Regression test for <https://github.com/rust-lang/rust/issues/126789>. +extern "C" { + #[used] //~ ERROR attribute must be applied to a `static` variable + static BAR: i32; +} diff --git a/tests/ui/used.stderr b/tests/ui/attributes/positions/used.stderr index c586dc72293..96dd43a3a93 100644 --- a/tests/ui/used.stderr +++ b/tests/ui/attributes/positions/used.stderr @@ -1,5 +1,5 @@ error: attribute must be applied to a `static` variable - --> $DIR/used.rs:4:1 + --> $DIR/used.rs:7:1 | LL | #[used] | ^^^^^^^ @@ -7,7 +7,7 @@ LL | fn foo() {} | ----------- but this is a function error: attribute must be applied to a `static` variable - --> $DIR/used.rs:7:1 + --> $DIR/used.rs:10:1 | LL | #[used] | ^^^^^^^ @@ -15,7 +15,7 @@ LL | struct Foo {} | ------------- but this is a struct error: attribute must be applied to a `static` variable - --> $DIR/used.rs:10:1 + --> $DIR/used.rs:13:1 | LL | #[used] | ^^^^^^^ @@ -23,12 +23,20 @@ LL | trait Bar {} | ------------ but this is a trait error: attribute must be applied to a `static` variable - --> $DIR/used.rs:13:1 + --> $DIR/used.rs:16:1 | LL | #[used] | ^^^^^^^ LL | impl Bar for Foo {} | ------------------- but this is a implementation block -error: aborting due to 4 previous errors +error: attribute must be applied to a `static` variable + --> $DIR/used.rs:21:5 + | +LL | #[used] + | ^^^^^^^ +LL | static BAR: i32; + | ---------------- but this is a foreign static item + +error: aborting due to 5 previous errors diff --git a/tests/ui/attributes/used-issue-126789.rs b/tests/ui/attributes/used-issue-126789.rs deleted file mode 100644 index 90a1aa8d5cc..00000000000 --- a/tests/ui/attributes/used-issue-126789.rs +++ /dev/null @@ -1,6 +0,0 @@ -extern "C" { - #[used] //~ ERROR attribute must be applied to a `static` variable - static FOO: i32; -} - -fn main() {} diff --git a/tests/ui/attributes/used-issue-126789.stderr b/tests/ui/attributes/used-issue-126789.stderr deleted file mode 100644 index 6014f7af95c..00000000000 --- a/tests/ui/attributes/used-issue-126789.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: attribute must be applied to a `static` variable - --> $DIR/used-issue-126789.rs:2:5 - | -LL | #[used] - | ^^^^^^^ -LL | static FOO: i32; - | ---------------- but this is a foreign static item - -error: aborting due to 1 previous error - diff --git a/tests/ui/attributes/used/used-not-dead-code-lint.rs b/tests/ui/attributes/used/used-not-dead-code-lint.rs new file mode 100644 index 00000000000..ece40ed219d --- /dev/null +++ b/tests/ui/attributes/used/used-not-dead-code-lint.rs @@ -0,0 +1,10 @@ +//! Checks that the `dead_code` lint does not consider `#[used]` items unused. +//! Regression test for <https://github.com/rust-lang/rust/issues/41628>. + +//@ check-pass +#![deny(dead_code)] + +#[used] +static FOO: u32 = 0; + +fn main() {} diff --git a/tests/ui/utf8-bom.rs b/tests/ui/codemap_tests/utf8-bom.rs index eb82f6652cb..eb82f6652cb 100644 --- a/tests/ui/utf8-bom.rs +++ b/tests/ui/codemap_tests/utf8-bom.rs diff --git a/tests/ui/issues/issue-41628.rs b/tests/ui/issues/issue-41628.rs deleted file mode 100644 index 255e4243e01..00000000000 --- a/tests/ui/issues/issue-41628.rs +++ /dev/null @@ -1,7 +0,0 @@ -//@ check-pass -#![deny(dead_code)] - -#[used] -static FOO: u32 = 0; - -fn main() {} diff --git a/tests/ui/utf8_idents.rs b/tests/ui/rfcs/rfc-2457-non-ascii-idents/utf8_idents.rs index 0c34529d2de..3997e27bc9f 100644 --- a/tests/ui/utf8_idents.rs +++ b/tests/ui/rfcs/rfc-2457-non-ascii-idents/utf8_idents.rs @@ -1,14 +1,13 @@ +//! Check that non-ascii-idents are allowed. + //@ check-pass // #![allow(mixed_script_confusables, non_camel_case_types)] -fn foo< - 'β, - γ ->() {} +fn foo<'β, γ>() {} struct X { - δ: usize + δ: usize, } pub fn main() { diff --git a/triagebot.toml b/triagebot.toml index 6f3ca493335..9dcdbcecbec 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -611,7 +611,7 @@ message_on_remove = "Issue #{number}'s prioritization request has been removed." message_on_close = "Issue #{number} has been closed while requested for prioritization." message_on_reopen = "Issue #{number} has been reopened." -[notify-zulip."beta-nominated"] +[notify-zulip."beta-nominated".rustdoc] required_labels = ["T-rustdoc"] zulip_stream = 266220 # #t-rustdoc topic = "beta-nominated: #{number}" @@ -632,7 +632,7 @@ message_on_remove = "PR #{number}'s beta-nomination has been removed." message_on_close = "PR #{number} has been closed. Thanks for participating!" message_on_reopen = "PR #{number} has been reopened. Pinging @*T-rustdoc*." -[notify-zulip."beta-accepted"] +[notify-zulip."beta-accepted".rustdoc] required_labels = ["T-rustdoc"] zulip_stream = 266220 # #t-rustdoc # Put it in the same thread as beta-nominated. @@ -642,7 +642,7 @@ message_on_remove = "PR #{number}'s beta-acceptance has been **removed**." message_on_close = "PR #{number} has been closed. Thanks for participating!" message_on_reopen = "PR #{number} has been reopened. Pinging @*T-rustdoc*." -[notify-zulip."stable-nominated"] +[notify-zulip."stable-nominated".rustdoc] required_labels = ["T-rustdoc"] zulip_stream = 266220 # #t-rustdoc topic = "stable-nominated: #{number}" @@ -664,7 +664,7 @@ message_on_remove = "PR #{number}'s stable-nomination has been removed." message_on_close = "PR #{number} has been closed. Thanks for participating!" message_on_reopen = "PR #{number} has been reopened. Pinging @*T-rustdoc*." -[notify-zulip."stable-accepted"] +[notify-zulip."stable-accepted".rustdoc] required_labels = ["T-rustdoc"] zulip_stream = 266220 # #t-rustdoc # Put it in the same thread as stable-nominated. |
