Skip to content

Commit ce4beeb

Browse files
committed
Auto merge of #146683 - clarfonthey:safe-intrinsics, r=RalfJung,Amanieu
Mark float intrinsics with no preconditions as safe Note: for ease of reviewing, the list of safe intrinsics is sorted in the first commit, and then safe intrinsics are added in the second commit. All *recently added* float intrinsics have been correctly marked as safe to call due to the fact that they have no preconditions. This adds the remaining float intrinsics which are safe to call to the safe intrinsic list, and removes the unsafe blocks around their calls. --- Side note: this may want a try run before being added to the queue, since I'm not sure if there's any tier-2 code that uses these intrinsics that might not be tested on the usual PR flow. We've already uncovered a few places in subtrees that do this, and it's worth double-checking before clogging up the queue.
2 parents 29005cb + 055e05a commit ce4beeb

File tree

19 files changed

+284
-246
lines changed

19 files changed

+284
-246
lines changed

compiler/rustc_hir_analysis/src/check/intrinsic.rs

Lines changed: 126 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -64,83 +64,151 @@ fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -> hi
6464
// it's usually worth updating that intrinsic's documentation
6565
// to note that it's safe to call, since
6666
// safe extern fns are otherwise unprecedented.
67-
sym::abort
67+
68+
// tidy-alphabetical-start
69+
| sym::abort
70+
| sym::add_with_overflow
71+
| sym::aggregate_raw_ptr
72+
| sym::align_of
6873
| sym::assert_inhabited
69-
| sym::assert_zero_valid
7074
| sym::assert_mem_uninitialized_valid
75+
| sym::assert_zero_valid
76+
| sym::autodiff
77+
| sym::bitreverse
78+
| sym::black_box
7179
| sym::box_new
7280
| sym::breakpoint
73-
| sym::size_of
74-
| sym::align_of
75-
| sym::needs_drop
81+
| sym::bswap
7682
| sym::caller_location
77-
| sym::add_with_overflow
78-
| sym::sub_with_overflow
79-
| sym::mul_with_overflow
8083
| sym::carrying_mul_add
81-
| sym::wrapping_add
82-
| sym::wrapping_sub
83-
| sym::wrapping_mul
84-
| sym::saturating_add
85-
| sym::saturating_sub
86-
| sym::rotate_left
87-
| sym::rotate_right
88-
| sym::ctpop
84+
| sym::ceilf16
85+
| sym::ceilf32
86+
| sym::ceilf64
87+
| sym::ceilf128
88+
| sym::cold_path
89+
| sym::const_eval_select
90+
| sym::contract_check_ensures
91+
| sym::contract_check_requires
92+
| sym::contract_checks
93+
| sym::cosf16
94+
| sym::cosf32
95+
| sym::cosf64
96+
| sym::cosf128
8997
| sym::ctlz
98+
| sym::ctpop
9099
| sym::cttz
91-
| sym::bswap
92-
| sym::bitreverse
93-
| sym::three_way_compare
94100
| sym::discriminant_value
95-
| sym::type_id
96-
| sym::type_id_eq
97-
| sym::select_unpredictable
98-
| sym::cold_path
99-
| sym::ptr_guaranteed_cmp
100-
| sym::minnumf16
101-
| sym::minnumf32
102-
| sym::minnumf64
103-
| sym::minnumf128
104-
| sym::minimumf16
105-
| sym::minimumf32
106-
| sym::minimumf64
107-
| sym::minimumf128
108-
| sym::maxnumf16
109-
| sym::maxnumf32
110-
| sym::maxnumf64
111-
| sym::maxnumf128
101+
| sym::exp2f16
102+
| sym::exp2f32
103+
| sym::exp2f64
104+
| sym::exp2f128
105+
| sym::expf16
106+
| sym::expf32
107+
| sym::expf64
108+
| sym::expf128
109+
| sym::fadd_algebraic
110+
| sym::fdiv_algebraic
111+
| sym::floorf16
112+
| sym::floorf32
113+
| sym::floorf64
114+
| sym::floorf128
115+
| sym::fmaf16
116+
| sym::fmaf32
117+
| sym::fmaf64
118+
| sym::fmaf128
119+
| sym::fmul_algebraic
120+
| sym::fmuladdf16
121+
| sym::fmuladdf32
122+
| sym::fmuladdf64
123+
| sym::fmuladdf128
124+
| sym::forget
125+
| sym::frem_algebraic
126+
| sym::fsub_algebraic
127+
| sym::is_val_statically_known
128+
| sym::log2f16
129+
| sym::log2f32
130+
| sym::log2f64
131+
| sym::log2f128
132+
| sym::log10f16
133+
| sym::log10f32
134+
| sym::log10f64
135+
| sym::log10f128
136+
| sym::logf16
137+
| sym::logf32
138+
| sym::logf64
139+
| sym::logf128
112140
| sym::maximumf16
113141
| sym::maximumf32
114142
| sym::maximumf64
115143
| sym::maximumf128
116-
| sym::rustc_peek
117-
| sym::type_name
118-
| sym::forget
119-
| sym::black_box
120-
| sym::variant_count
121-
| sym::is_val_statically_known
144+
| sym::maxnumf16
145+
| sym::maxnumf32
146+
| sym::maxnumf64
147+
| sym::maxnumf128
148+
| sym::minimumf16
149+
| sym::minimumf32
150+
| sym::minimumf64
151+
| sym::minimumf128
152+
| sym::minnumf16
153+
| sym::minnumf32
154+
| sym::minnumf64
155+
| sym::minnumf128
156+
| sym::mul_with_overflow
157+
| sym::needs_drop
158+
| sym::powf16
159+
| sym::powf32
160+
| sym::powf64
161+
| sym::powf128
162+
| sym::powif16
163+
| sym::powif32
164+
| sym::powif64
165+
| sym::powif128
166+
| sym::prefetch_read_data
167+
| sym::prefetch_read_instruction
168+
| sym::prefetch_write_data
169+
| sym::prefetch_write_instruction
170+
| sym::ptr_guaranteed_cmp
122171
| sym::ptr_mask
123-
| sym::aggregate_raw_ptr
124172
| sym::ptr_metadata
125-
| sym::ub_checks
126-
| sym::contract_checks
127-
| sym::contract_check_requires
128-
| sym::contract_check_ensures
129-
| sym::fadd_algebraic
130-
| sym::fsub_algebraic
131-
| sym::fmul_algebraic
132-
| sym::fdiv_algebraic
133-
| sym::frem_algebraic
173+
| sym::rotate_left
174+
| sym::rotate_right
134175
| sym::round_ties_even_f16
135176
| sym::round_ties_even_f32
136177
| sym::round_ties_even_f64
137178
| sym::round_ties_even_f128
138-
| sym::autodiff
139-
| sym::prefetch_read_data
140-
| sym::prefetch_write_data
141-
| sym::prefetch_read_instruction
142-
| sym::prefetch_write_instruction
143-
| sym::const_eval_select => hir::Safety::Safe,
179+
| sym::roundf16
180+
| sym::roundf32
181+
| sym::roundf64
182+
| sym::roundf128
183+
| sym::rustc_peek
184+
| sym::saturating_add
185+
| sym::saturating_sub
186+
| sym::select_unpredictable
187+
| sym::sinf16
188+
| sym::sinf32
189+
| sym::sinf64
190+
| sym::sinf128
191+
| sym::size_of
192+
| sym::sqrtf16
193+
| sym::sqrtf32
194+
| sym::sqrtf64
195+
| sym::sqrtf128
196+
| sym::sub_with_overflow
197+
| sym::three_way_compare
198+
| sym::truncf16
199+
| sym::truncf32
200+
| sym::truncf64
201+
| sym::truncf128
202+
| sym::type_id
203+
| sym::type_id_eq
204+
| sym::type_name
205+
| sym::ub_checks
206+
| sym::variant_count
207+
| sym::wrapping_add
208+
| sym::wrapping_mul
209+
| sym::wrapping_sub
210+
// tidy-alphabetical-end
211+
=> hir::Safety::Safe,
144212
_ => hir::Safety::Unsafe,
145213
};
146214

library/compiler-builtins/libm/src/math/support/float_traits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ macro_rules! float_impl {
289289
cfg_if! {
290290
// fma is not yet available in `core`
291291
if #[cfg(intrinsics_enabled)] {
292-
unsafe{ core::intrinsics::$fma_intrinsic(self, y, z) }
292+
core::intrinsics::$fma_intrinsic(self, y, z)
293293
} else {
294294
super::super::$fma_fn(self, y, z)
295295
}

0 commit comments

Comments
 (0)