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: 1 addition & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3283,7 +3283,7 @@ dependencies = [
"regex",
"serde_json",
"similar",
"wasmparser 0.219.2",
"wasmparser 0.236.0",
]

[[package]]
Expand Down
17 changes: 16 additions & 1 deletion compiler/rustc_codegen_llvm/src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ use rustc_middle::bug;
use rustc_middle::ty::TyCtxt;
use rustc_session::config::{DebugInfo, OomStrategy};
use rustc_symbol_mangling::mangle_internal_symbol;
use smallvec::SmallVec;

use crate::builder::SBuilder;
use crate::declare::declare_simple_fn;
use crate::llvm::{self, False, True, Type, Value};
use crate::{SimpleCx, attributes, debuginfo};
use crate::{SimpleCx, attributes, debuginfo, llvm_util};

pub(crate) unsafe fn codegen(
tcx: TyCtxt<'_>,
Expand Down Expand Up @@ -147,6 +148,20 @@ fn create_wrapper_function(
llvm::Visibility::from_generic(tcx.sess.default_visibility()),
ty,
);

let mut attrs = SmallVec::<[_; 2]>::new();

let target_cpu = llvm_util::target_cpu(tcx.sess);
let target_cpu_attr = llvm::CreateAttrStringValue(cx.llcx, "target-cpu", target_cpu);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can move the method onto SimpleCx, it doesn't appear to use anything FullCx related

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not very familiar with the code base. What is the recommended way to do this? There is MiscCodegenMethods, but it probably has more methods.


let tune_cpu_attr = llvm_util::tune_cpu(tcx.sess)
.map(|tune_cpu| llvm::CreateAttrStringValue(cx.llcx, "tune-cpu", tune_cpu));

attrs.push(target_cpu_attr);
attrs.extend(tune_cpu_attr);

attributes::apply_to_llfn(llfn, llvm::AttributePlace::Function, &attrs);

let no_return = if no_return {
// -> ! DIFlagNoReturn
let no_return = llvm::AttributeKind::NoReturn.create_attr(cx.llcx);
Expand Down
2 changes: 1 addition & 1 deletion src/tools/run-make-support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object = "0.37"
regex = "1.11"
serde_json = "1.0"
similar = "2.7"
wasmparser = { version = "0.219", default-features = false, features = ["std"] }
wasmparser = { version = "0.236", default-features = false, features = ["std", "features", "validate"] }
# tidy-alphabetical-end

# Shared with bootstrap and compiletest
Expand Down
43 changes: 43 additions & 0 deletions tests/run-make/wasm-unexpected-features/foo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#![no_core]
#![crate_type = "cdylib"]
#![feature(no_core, lang_items, allocator_internals, rustc_attrs)]
#![needs_allocator]
#![allow(internal_features)]

#[rustc_std_internal_symbol]
unsafe fn __rust_alloc(_size: usize, _align: usize) -> *mut u8 {
0 as *mut u8
}

unsafe extern "Rust" {
#[rustc_std_internal_symbol]
fn __rust_alloc_error_handler(size: usize, align: usize) -> !;
}

#[used]
static mut BUF: [u8; 1024] = [0; 1024];

#[unsafe(no_mangle)]
extern "C" fn init() {
unsafe {
__rust_alloc_error_handler(0, 0);
}
}

mod minicore {
#[lang = "pointee_sized"]
pub trait PointeeSized {}

#[lang = "meta_sized"]
pub trait MetaSized: PointeeSized {}

#[lang = "sized"]
pub trait Sized: MetaSized {}

#[lang = "copy"]
pub trait Copy {}
impl Copy for u8 {}

#[lang = "drop_in_place"]
fn drop_in_place<T>(_: *mut T) {}
}
26 changes: 26 additions & 0 deletions tests/run-make/wasm-unexpected-features/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//@ only-wasm32-wasip1

use std::path::Path;

use run_make_support::{rfs, rustc, wasmparser};

fn main() {
rustc()
.input("foo.rs")
.target("wasm32-wasip1")
.target_cpu("mvp")
.opt_level("z")
.lto("fat")
.linker_plugin_lto("on")
.link_arg("--import-memory")
.run();
verify_features(Path::new("foo.wasm"));
}

fn verify_features(path: &Path) {
eprintln!("verify {path:?}");
let file = rfs::read(&path);

let mut validator = wasmparser::Validator::new_with_features(wasmparser::WasmFeatures::WASM1);
validator.validate_all(&file).unwrap();
}
Loading