@@ -15,6 +15,7 @@ use rustc_middle::mir::BinOp;
1515use rustc_middle:: ty:: layout:: { FnAbiOf , HasTyCtxt , HasTypingEnv , LayoutOf } ;
1616use rustc_middle:: ty:: { self , GenericArgsRef , Instance , Ty , TyCtxt , TypingEnv } ;
1717use rustc_middle:: { bug, span_bug} ;
18+ use rustc_session:: config:: Lto ;
1819use rustc_span:: { Span , Symbol , sym} ;
1920use rustc_symbol_mangling:: { mangle_internal_symbol, symbol_name_for_instance_in_crate} ;
2021use rustc_target:: callconv:: PassMode ;
@@ -25,6 +26,7 @@ use crate::abi::FnAbiLlvmExt;
2526use crate :: builder:: Builder ;
2627use crate :: builder:: autodiff:: { adjust_activity_to_abi, generate_enzyme_call} ;
2728use crate :: context:: CodegenCx ;
29+ use crate :: errors:: { AutoDiffWithoutEnable , AutoDiffWithoutLTO } ;
2830use crate :: llvm:: { self , Metadata } ;
2931use crate :: type_:: Type ;
3032use crate :: type_of:: LayoutLlvmExt ;
@@ -1128,6 +1130,14 @@ fn codegen_enzyme_autodiff<'ll, 'tcx>(
11281130 args : & [ OperandRef < ' tcx , & ' ll Value > ] ,
11291131 result : PlaceRef < ' tcx , & ' ll Value > ,
11301132) {
1133+ if !tcx. sess . opts . unstable_opts . autodiff . contains ( & rustc_session:: config:: AutoDiff :: Enable ) {
1134+ let _ = tcx. dcx ( ) . emit_almost_fatal ( AutoDiffWithoutEnable ) ;
1135+ }
1136+
1137+ if tcx. sess . lto ( ) != Lto :: Fat {
1138+ let _ = tcx. dcx ( ) . emit_almost_fatal ( AutoDiffWithoutLTO ) ;
1139+ }
1140+
11311141 let fn_args = instance. args ;
11321142 let callee_ty = instance. ty ( tcx, bx. typing_env ( ) ) ;
11331143
0 commit comments