diff --git a/Cargo.lock b/Cargo.lock index 6c180cad52..1d3b58afae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2226,9 +2226,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.20" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dead70b0b5e03e9c814bcb6b01e03e68f7c57a80aa48c72ec92152ab3e818d49" +checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" [[package]] name = "rustc-hash" diff --git a/crates/rustc_codegen_spirv/Cargo.toml b/crates/rustc_codegen_spirv/Cargo.toml index 44628f5e09..fa9495c42f 100644 --- a/crates/rustc_codegen_spirv/Cargo.toml +++ b/crates/rustc_codegen_spirv/Cargo.toml @@ -39,7 +39,7 @@ ar = "0.9.0" bimap = "0.6" indexmap = "1.6.0" rspirv = "0.10" -rustc-demangle = "0.1.18" +rustc-demangle = "0.1.21" sanitize-filename = "0.3" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/crates/rustc_codegen_spirv/src/attr.rs b/crates/rustc_codegen_spirv/src/attr.rs index 58ca88bace..e206e37ea7 100644 --- a/crates/rustc_codegen_spirv/src/attr.rs +++ b/crates/rustc_codegen_spirv/src/attr.rs @@ -144,7 +144,7 @@ impl AggregatedSpirvAttributes { // NOTE(eddyb) `delay_span_bug` ensures that if attribute checking fails // to see an attribute error, it will cause an ICE instead. - for (_, parse_attr_result) in crate::symbols::parse_attrs_for_checking(&cx.sym, attrs) { + for parse_attr_result in crate::symbols::parse_attrs_for_checking(&cx.sym, attrs) { let (span, parsed_attr) = match parse_attr_result { Ok(span_and_parsed_attr) => span_and_parsed_attr, Err((span, msg)) => { @@ -263,11 +263,7 @@ impl CheckSpirvAttrVisitor<'_> { let parse_attrs = |attrs| crate::symbols::parse_attrs_for_checking(&self.sym, attrs); let attrs = self.tcx.hir().attrs(hir_id); - for (attr, parse_attr_result) in parse_attrs(attrs) { - // Make sure to mark the whole `#[spirv(...)]` attribute as used, - // to avoid warnings about unused attributes. - self.tcx.sess.mark_attr_used(attr); - + for parse_attr_result in parse_attrs(attrs) { let (span, parsed_attr) = match parse_attr_result { Ok(span_and_parsed_attr) => span_and_parsed_attr, Err((span, msg)) => { @@ -312,7 +308,7 @@ impl CheckSpirvAttrVisitor<'_> { let parent_hir_id = self.tcx.hir().get_parent_node(hir_id); let parent_is_entry_point = parse_attrs(self.tcx.hir().attrs(parent_hir_id)) - .filter_map(|(_, r)| r.ok()) + .filter_map(|r| r.ok()) .any(|(_, attr)| matches!(attr, SpirvAttribute::Entry(_))); if !parent_is_entry_point { self.tcx.sess.span_err( @@ -494,7 +490,7 @@ impl<'tcx> Visitor<'tcx> for CheckSpirvAttrVisitor<'tcx> { fn check_invalid_macro_level_spirv_attr(tcx: TyCtxt<'_>, sym: &Symbols, attrs: &[Attribute]) { for attr in attrs { - if tcx.sess.check_name(attr, sym.spirv) { + if attr.has_name(sym.spirv) { tcx.sess .span_err(attr.span, "#[spirv(..)] cannot be applied to a macro"); } diff --git a/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs b/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs index 42d2f30d32..b59a558583 100644 --- a/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs +++ b/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs @@ -341,14 +341,17 @@ impl<'tcx> ConstMethods<'tcx> for CodegenCx<'tcx> { } impl<'tcx> CodegenCx<'tcx> { - // This function comes from https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_middle/ty/layout.rs.html, - // and is a lambda in the `layout_raw_uncached` function in Version 1.50.0-nightly (eb4fc71dc 2020-12-17) + // This function comes from `ty::layout`'s `layout_of_uncached`, + // where it's named `scalar_unit`. pub fn primitive_to_scalar(&self, value: Primitive) -> abi::Scalar { let bits = value.size(self.data_layout()).bits(); assert!(bits <= 128); abi::Scalar { value, - valid_range: 0..=(!0 >> (128 - bits)), + valid_range: abi::WrappingRange { + start: 0, + end: (!0 >> (128 - bits)), + }, } } diff --git a/crates/rustc_codegen_spirv/src/codegen_cx/declare.rs b/crates/rustc_codegen_spirv/src/codegen_cx/declare.rs index 644e4d11b1..07cd2701d8 100644 --- a/crates/rustc_codegen_spirv/src/codegen_cx/declare.rs +++ b/crates/rustc_codegen_spirv/src/codegen_cx/declare.rs @@ -294,12 +294,17 @@ impl<'tcx> StaticMethods for CodegenCx<'tcx> { .set_global_initializer(g.def_cx(self), v.def_cx(self)); } - /// Mark the given global value as "used", to prevent a backend from potentially removing a - /// static variable that may otherwise appear unused. - /// - /// Static variables in Rust can be annotated with the `#[used]` attribute to direct the `rustc` - /// compiler to mark the variable as a "used global". + /// Mark the given global value as "used", to prevent the compiler and linker from potentially + /// removing a static variable that may otherwise appear unused. fn add_used_global(&self, _global: Self::Value) { // TODO: Ignore for now. } + + /// Same as `add_used_global`, but only prevent the compiler from potentially removing an + /// otherwise unused symbol. The linker is still permitted to drop it. + /// + /// This corresponds to the semantics of the `#[used]` attribute. + fn add_compiler_used_global(&self, _global: Self::Value) { + // TODO: Ignore for now. + } } diff --git a/crates/rustc_codegen_spirv/src/codegen_cx/mod.rs b/crates/rustc_codegen_spirv/src/codegen_cx/mod.rs index 827a93ce19..ce4aa8aae2 100644 --- a/crates/rustc_codegen_spirv/src/codegen_cx/mod.rs +++ b/crates/rustc_codegen_spirv/src/codegen_cx/mod.rs @@ -562,6 +562,10 @@ impl<'tcx> MiscMethods<'tcx> for CodegenCx<'tcx> { todo!() } + fn compiler_used_statics(&self) -> &RefCell> { + todo!() + } + fn set_frame_pointer_type(&self, _llfn: Self::Function) { todo!() } @@ -574,6 +578,10 @@ impl<'tcx> MiscMethods<'tcx> for CodegenCx<'tcx> { todo!() } + fn create_compiler_used_variable(&self) { + todo!() + } + fn declare_c_main(&self, _fn_type: Self::Type) -> Option { todo!() } diff --git a/crates/rustc_codegen_spirv/src/symbols.rs b/crates/rustc_codegen_spirv/src/symbols.rs index 35e172d498..6c25cfab00 100644 --- a/crates/rustc_codegen_spirv/src/symbols.rs +++ b/crates/rustc_codegen_spirv/src/symbols.rs @@ -1,7 +1,7 @@ use crate::attr::{Entry, ExecutionModeExtra, IntrinsicType, SpirvAttribute}; use crate::builder::libm_intrinsics; use rspirv::spirv::{BuiltIn, ExecutionMode, ExecutionModel, StorageClass}; -use rustc_ast::ast::{AttrKind, Attribute, Lit, LitIntType, LitKind, NestedMetaItem}; +use rustc_ast::ast::{Attribute, Lit, LitIntType, LitKind, NestedMetaItem}; use rustc_data_structures::fx::FxHashMap; use rustc_span::symbol::{Ident, Symbol}; use rustc_span::Span; @@ -409,22 +409,9 @@ type ParseAttrError = (Span, String); pub(crate) fn parse_attrs_for_checking<'a>( sym: &'a Symbols, attrs: &'a [Attribute], -) -> impl Iterator< - Item = ( - &'a Attribute, - Result<(Span, SpirvAttribute), ParseAttrError>, - ), -> + 'a { +) -> impl Iterator> + 'a { attrs.iter().flat_map(move |attr| { - let is_spirv = match attr.kind { - AttrKind::Normal(ref item, _) => { - // TODO: We ignore the rest of the path. Is this right? - let last = item.path.segments.last(); - last.map_or(false, |seg| seg.ident.name == sym.spirv) - } - AttrKind::DocComment(..) => false, - }; - let (whole_attr_error, args) = if !is_spirv { + let (whole_attr_error, args) = if !attr.has_name(sym.spirv) { // Use an empty vec here to return empty (None, Vec::new()) } else if let Some(args) = attr.meta_item_list() { @@ -475,7 +462,6 @@ pub(crate) fn parse_attrs_for_checking<'a>( }; Ok((span, parsed_attr)) })) - .map(move |parse_attr_result| (attr, parse_attr_result)) }) } diff --git a/crates/spirv-builder/src/lib.rs b/crates/spirv-builder/src/lib.rs index d02410877e..dff332a9a8 100644 --- a/crates/spirv-builder/src/lib.rs +++ b/crates/spirv-builder/src/lib.rs @@ -394,8 +394,7 @@ fn invoke_rustc(builder: &SpirvBuilder) -> Result { let mut rustflags = vec![ format!("-Zcodegen-backend={}", rustc_codegen_spirv.display()), - //FIXME: reintroduce v0 mangling, see issue #642 - "-Zsymbol-mangling-version=legacy".to_string(), + "-Zsymbol-mangling-version=v0".to_string(), ]; let mut llvm_args = vec![]; diff --git a/rust-toolchain b/rust-toolchain index e31efa5245..d4e1e1f757 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -5,5 +5,5 @@ # to the user in the error, instead of "error: invalid channel name '[toolchain]'". [toolchain] -channel = "nightly-2021-08-10" +channel = "nightly-2021-08-27" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] diff --git a/tests/src/main.rs b/tests/src/main.rs index 63ff4d16ff..1f32608c4c 100644 --- a/tests/src/main.rs +++ b/tests/src/main.rs @@ -292,6 +292,7 @@ struct TestDeps { } /// The RUSTFLAGS passed to all SPIR-V builds. +// FIXME(eddyb) expose most of these from `spirv-builder`. fn rust_flags(codegen_backend_path: &Path) -> String { [ &*format!("-Zcodegen-backend={}", codegen_backend_path.display()), @@ -300,6 +301,7 @@ fn rust_flags(codegen_backend_path: &Path) -> String { "-Cdebuginfo=2", "-Cembed-bitcode=no", "-Ctarget-feature=+Int8,+Int16,+Int64,+Float64", + "-Zsymbol-mangling-version=v0", ] .join(" ") } diff --git a/tests/ui/dis/generic-fn-op-name.rs b/tests/ui/dis/generic-fn-op-name.rs new file mode 100644 index 0000000000..fd79afc006 --- /dev/null +++ b/tests/ui/dis/generic-fn-op-name.rs @@ -0,0 +1,19 @@ +// Test that generic functions' `OpName` correctly include generic arguments. + +// build-pass +// compile-flags: -C llvm-args=--disassemble-globals +// normalize-stderr-test "OpCapability VulkanMemoryModel\n" -> "" +// normalize-stderr-test "OpExtension .SPV_KHR_vulkan_memory_model.\n" -> "" +// normalize-stderr-test "OpMemoryModel Logical Vulkan" -> "OpMemoryModel Logical Simple" + +#![feature(const_generics)] +#![allow(incomplete_features)] + +use spirv_std::image::Dimensionality; + +fn generic() {} + +#[spirv(fragment)] +pub fn main() { + generic::(); +} diff --git a/tests/ui/dis/generic-fn-op-name.stderr b/tests/ui/dis/generic-fn-op-name.stderr new file mode 100644 index 0000000000..7728d0ee7a --- /dev/null +++ b/tests/ui/dis/generic-fn-op-name.stderr @@ -0,0 +1,13 @@ +OpCapability Float64 +OpCapability Int16 +OpCapability Int64 +OpCapability Int8 +OpCapability Shader +OpMemoryModel Logical Simple +OpEntryPoint Fragment %1 "main" +OpExecutionMode %1 OriginUpperLeft +%2 = OpString "$OPSTRING_FILENAME/generic-fn-op-name.rs" +OpName %3 "generic_fn_op_name::generic::" +OpName %4 "generic_fn_op_name::main" +%5 = OpTypeVoid +%6 = OpTypeFunction %5 diff --git a/tests/ui/dis/ptr_copy.normal.stderr b/tests/ui/dis/ptr_copy.normal.stderr index d9cd1d5440..e86d2963c6 100644 --- a/tests/ui/dis/ptr_copy.normal.stderr +++ b/tests/ui/dis/ptr_copy.normal.stderr @@ -1,7 +1,7 @@ error: Cannot memcpy dynamically sized data - --> $CORE_SRC/intrinsics.rs:2132:14 + --> $CORE_SRC/intrinsics.rs:2138:14 | -2132 | unsafe { copy(src, dst, count) } +2138 | unsafe { copy(src, dst, count) } | ^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error