Skip to content

Commit d43655b

Browse files
committed
Emit erros when invalid config
1 parent 9c9aac0 commit d43655b

File tree

6 files changed

+63
-4
lines changed

6 files changed

+63
-4
lines changed

compiler/rustc_codegen_llvm/messages.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ codegen_llvm_lto_bitcode_from_rlib = failed to get bitcode from object file for
1818
codegen_llvm_mismatch_data_layout =
1919
data-layout for target `{$rustc_target}`, `{$rustc_layout}`, differs from LLVM target's `{$llvm_target}` default layout, `{$llvm_layout}`
2020
21+
codegen_llvm_offload_without_enable = using the offload feature requires -Z offload=Enable
22+
codegen_llvm_offload_without_fat_lto = using the offload feature requires -C lto=fat
23+
2124
codegen_llvm_parse_bitcode = failed to parse bitcode for LTO module
2225
codegen_llvm_parse_bitcode_with_llvm_err = failed to parse bitcode for LTO module: {$llvm_err}
2326

compiler/rustc_codegen_llvm/src/errors.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ pub(crate) struct AutoDiffWithoutLto;
4040
#[diag(codegen_llvm_autodiff_without_enable)]
4141
pub(crate) struct AutoDiffWithoutEnable;
4242

43+
#[derive(Diagnostic)]
44+
#[diag(codegen_llvm_offload_without_enable)]
45+
pub(crate) struct OffloadWithoutEnable;
46+
47+
#[derive(Diagnostic)]
48+
#[diag(codegen_llvm_offload_without_fat_lto)]
49+
pub(crate) struct OffloadWithoutFatLTO;
50+
4351
#[derive(Diagnostic)]
4452
#[diag(codegen_llvm_lto_bitcode_from_rlib)]
4553
pub(crate) struct LtoBitcodeFromRlib {

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ use crate::builder::Builder;
2727
use crate::builder::autodiff::{adjust_activity_to_abi, generate_enzyme_call};
2828
use crate::builder::gpu_offload::TgtOffloadEntry;
2929
use crate::context::CodegenCx;
30-
use crate::errors::{AutoDiffWithoutEnable, AutoDiffWithoutLto};
30+
use crate::errors::{
31+
AutoDiffWithoutEnable, AutoDiffWithoutLto, OffloadWithoutEnable, OffloadWithoutFatLTO,
32+
};
3133
use crate::llvm::{self, Metadata, Type, Value};
3234
use crate::type_of::LayoutLlvmExt;
3335
use crate::va_arg::emit_va_arg;
@@ -199,7 +201,20 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
199201
return Ok(());
200202
}
201203
sym::offload => {
202-
// TODO(Sa4dUs): emit error when offload is not enabled
204+
if !tcx
205+
.sess
206+
.opts
207+
.unstable_opts
208+
.offload
209+
.contains(&rustc_session::config::Offload::Enable)
210+
{
211+
let _ = tcx.dcx().emit_almost_fatal(OffloadWithoutEnable);
212+
}
213+
214+
if tcx.sess.lto() != rustc_session::config::Lto::Fat {
215+
let _ = tcx.dcx().emit_almost_fatal(OffloadWithoutFatLTO);
216+
}
217+
203218
codegen_offload(self, tcx, instance, args);
204219
return Ok(());
205220
}

compiler/rustc_middle/src/ty/offload_meta.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ fn get_payload_size<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> u64 {
7474
}
7575

7676
impl MappingFlags {
77-
fn from_ty<'tcx>(_tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Self {
77+
fn from_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Self {
7878
use rustc_ast::Mutability::*;
7979

8080
match ty.kind() {
@@ -109,7 +109,11 @@ impl MappingFlags {
109109
| ty::Bound(_, _)
110110
| ty::Placeholder(_)
111111
| ty::Infer(_)
112-
| ty::Error(_) => MappingFlags::TO, /* TODO(Sa4dUs): emit error */
112+
| ty::Error(_) => {
113+
tcx.dcx()
114+
.span_err(rustc_span::DUMMY_SP, format!("type `{ty:?}` cannot be offloaded"));
115+
MappingFlags::empty()
116+
}
113117
}
114118
}
115119
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
error: using the offload feature requires -Z offload=Enable
2+
3+
error: using the offload feature requires -C lto=fat
4+
5+
error: aborting due to 2 previous errors
6+

tests/ui/offload/check_config.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//@ revisions: pass fail
2+
//@ no-prefer-dynamic
3+
//@ needs-enzyme
4+
//@[pass] build-pass
5+
//@[fail] build-fail
6+
//@[pass] compile-flags: -Zunstable-options -Zoffload=Enable -Clto=fat --emit=metadata
7+
//@[fail] compile-flags: -Clto=thin
8+
9+
//[fail]~? ERROR: using the offload feature requires -Z offload=Enable
10+
//[fail]~? ERROR: using the offload feature requires -C lto=fat
11+
12+
#![feature(core_intrinsics)]
13+
14+
fn main() {
15+
let mut x = [3.0; 256];
16+
kernel_1(&mut x);
17+
}
18+
19+
fn kernel_1(x: &mut [f32; 256]) {
20+
core::intrinsics::offload(_kernel_1, (x,))
21+
}
22+
23+
fn _kernel_1(x: &mut [f32; 256]) {}

0 commit comments

Comments
 (0)