Prefer an instruction when attributing EmitError diagnostics Attribute the diagnostic to the first of V and Extra which is an instruction, so an argument at fault still reports the origin's location. Also reset LegalOr before the RHS check of floating point binary operations, and do not bake the type analysis dump into the runtime error string. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
diff --git a/enzyme/Enzyme/DiffeGradientUtils.cpp b/enzyme/Enzyme/DiffeGradientUtils.cpp index cb4697a..fcde5ba 100644 --- a/enzyme/Enzyme/DiffeGradientUtils.cpp +++ b/enzyme/Enzyme/DiffeGradientUtils.cpp
@@ -679,7 +679,7 @@ EmitNoTypeError(ss.str(), *inst, this, BuilderM); return addedSelects; } - if (!CustomErrorHandler) + if (!CustomErrorHandler && !EnzymeRuntimeError) TR.dump(ss); EmitError("CannotDeduceType", ErrorType::NoType, ss.str(), val, TR.analyzer, nullptr, &BuilderM);
diff --git a/enzyme/Enzyme/TypeAnalysis/TypeAnalysis.cpp b/enzyme/Enzyme/TypeAnalysis/TypeAnalysis.cpp index cece3f4..840196c 100644 --- a/enzyme/Enzyme/TypeAnalysis/TypeAnalysis.cpp +++ b/enzyme/Enzyme/TypeAnalysis/TypeAnalysis.cpp
@@ -3128,6 +3128,7 @@ EmitError("IllegalUpdateAnalysis", ErrorType::IllegalTypeAnalysis, ss.str(), Args[0], this, origin); } + LegalOr = true; RHS.checkedOrIn(Data, /*PointerIntSame*/ false, LegalOr); if (!LegalOr) { std::string str;
diff --git a/enzyme/Enzyme/Utils.cpp b/enzyme/Enzyme/Utils.cpp index 19a31b8..dc6ace0 100644 --- a/enzyme/Enzyme/Utils.cpp +++ b/enzyme/Enzyme/Utils.cpp
@@ -4514,10 +4514,15 @@ return nullptr; } - // Attribute the diagnostic to the value at fault, falling back to wherever - // we were generating code and finally to the secondary value. + // Attribute the diagnostic to an instruction at fault, else the value at + // fault, else wherever we were generating code, else the secondary value. DiagnosticLocation Loc; - const Function *F = getDiagnosticFunction(V, Loc); + const Function *F = nullptr; + for (auto G : {V, Extra}) + if (isa_and_nonnull<Instruction>(G) && (F = getDiagnosticFunction(G, Loc))) + break; + if (!F) + F = getDiagnosticFunction(V, Loc); if (!F && hasIP) { F = B->GetInsertBlock()->getParent(); if (B->getCurrentDebugLocation())
diff --git a/enzyme/Enzyme/Utils.h b/enzyme/Enzyme/Utils.h index fa4bfb8..db3a3aa 100644 --- a/enzyme/Enzyme/Utils.h +++ b/enzyme/Enzyme/Utils.h
@@ -387,9 +387,10 @@ /// * emitting a warning, for the kinds we recover from (mixed activity, /// exceeding the type depth, being unable to rewrite GC roots), or /// * emitting an EnzymeFailure for everything else. -/// The diagnostic is attributed to the first of `V`, the insertion point of -/// `B` and `Extra` from which a function can be found. Compilation is only -/// aborted if there is none. +/// The diagnostic is attributed to the first of `V` and `Extra` which is an +/// instruction, else the first of `V`, the insertion point of `B` and `Extra` +/// from which a function can be found. Compilation is only aborted if there is +/// none. /// /// As whether a failure diagnostic returns is up to the LLVMContext's /// diagnostic handler, callers must leave the IR valid after an error.