@@ -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 ;
@@ -1136,6 +1138,14 @@ fn codegen_enzyme_autodiff<'ll, 'tcx>(
11361138 args : & [ OperandRef < ' tcx , & ' ll Value > ] ,
11371139 result : PlaceRef < ' tcx , & ' ll Value > ,
11381140) {
1141+ if !tcx. sess . opts . unstable_opts . autodiff . contains ( & rustc_session:: config:: AutoDiff :: Enable ) {
1142+ let _ = tcx. dcx ( ) . emit_almost_fatal ( AutoDiffWithoutEnable ) ;
1143+ }
1144+
1145+ if tcx. sess . lto ( ) != Lto :: Fat {
1146+ let _ = tcx. dcx ( ) . emit_almost_fatal ( AutoDiffWithoutLTO ) ;
1147+ }
1148+
11391149 let fn_args = instance. args ;
11401150 let callee_ty = instance. ty ( tcx, bx. typing_env ( ) ) ;
11411151
0 commit comments