Skip to content

Commit 856b771

Browse files
committed
Require either wrapping nullary intrinsincs in const blocks or explicitly deciding not to
1 parent dbfb8c9 commit 856b771

File tree

11 files changed

+791
-387
lines changed

11 files changed

+791
-387
lines changed

compiler/rustc_codegen_ssa/messages.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ codegen_ssa_self_contained_linker_missing = the self-contained linker was reques
260260
261261
codegen_ssa_shuffle_indices_evaluation = could not evaluate shuffle_indices at compile time
262262
263+
codegen_ssa_nullary_intrinsic_codegen = nullary intrinsics must either be in a const block or explicitly opted out because they are inherently runtime intrinsics
264+
.label = `{name}` is a nullary intrinsic
265+
263266
codegen_ssa_specify_libraries_to_link = use the `-l` flag to specify native libraries to link
264267
265268
codegen_ssa_static_library_native_artifacts = Link against the following native artifacts when linking against this static library. The order and any duplication can be significant on some platforms.

compiler/rustc_codegen_ssa/src/errors.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,14 @@ pub(crate) struct ShuffleIndicesEvaluation {
761761
pub span: Span,
762762
}
763763

764+
#[derive(Diagnostic)]
765+
#[diag(codegen_ssa_nullary_intrinsic_codegen)]
766+
pub(crate) struct NullaryIntrinsicCodegen {
767+
#[primary_span]
768+
pub span: Span,
769+
pub name: Symbol,
770+
}
771+
764772
#[derive(Diagnostic)]
765773
pub enum InvalidMonomorphization<'tcx> {
766774
#[diag(codegen_ssa_invalid_monomorphization_basic_integer_type, code = E0511)]

compiler/rustc_codegen_ssa/src/mir/intrinsic.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use super::FunctionCx;
99
use super::operand::OperandRef;
1010
use super::place::PlaceRef;
1111
use crate::common::{AtomicRmwBinOp, SynchronizationScope};
12-
use crate::errors::InvalidMonomorphization;
12+
use crate::errors::{InvalidMonomorphization, NullaryIntrinsicCodegen};
1313
use crate::traits::*;
1414
use crate::{MemFlags, meth, size_of_val};
1515

@@ -98,6 +98,26 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
9898
discr.to_atomic_ordering()
9999
};
100100

101+
if args.is_empty() {
102+
match name {
103+
sym::abort
104+
| sym::unreachable
105+
| sym::cold_path
106+
| sym::breakpoint
107+
| sym::assert_zero_valid
108+
| sym::assert_mem_uninitialized_valid
109+
| sym::assert_inhabited
110+
| sym::ub_checks
111+
| sym::contract_checks
112+
| sym::atomic_fence
113+
| sym::caller_location => {}
114+
_ => {
115+
bx.tcx().dcx().emit_err(NullaryIntrinsicCodegen { span, name });
116+
return Ok(());
117+
}
118+
}
119+
}
120+
101121
let llval = match name {
102122
sym::abort => {
103123
bx.abort();

library/stdarch/crates/core_arch/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
rtm_target_feature,
3232
allow_internal_unstable,
3333
decl_macro,
34+
generic_arg_infer,
3435
asm_experimental_arch,
3536
x86_amx_intrinsics,
3637
f16,

0 commit comments

Comments
 (0)