Fix/issue 4268 forward declared adjoint#4306
Open
KevinSailema wants to merge 3 commits intoNVIDIA:mainfrom
Open
Fix/issue 4268 forward declared adjoint#4306KevinSailema wants to merge 3 commits intoNVIDIA:mainfrom
KevinSailema wants to merge 3 commits intoNVIDIA:mainfrom
Conversation
Collaborator
Command Bot: Processing... |
|
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
mitchdz
reviewed
Apr 16, 2026
| auto &variant = variantIter->second; | ||
|
|
||
| // We cannot synthesize an adjoint if only a declaration is available. | ||
| if ((variant.needsAdjointVariant || variant.needsAdjointControlVariant) && |
Collaborator
There was a problem hiding this comment.
Can you also add a variant.needsControlVariant to the check?
A user who writes quake.apply [%ctl] @prep %q against a forward-declared @prep will hit the same class of crash this PR is fixing, just through a different code path.
e.g.
// ctl_decl.qke
module {
func.func private @prep(!quake.ref)
func.func @kernel() {
%ctl = quake.alloca !quake.ref
%q = quake.alloca !quake.ref
quake.apply @prep [%ctl] %q : (!quake.ref, !quake.ref) -> ()
return
}
}
$ cudaq-opt --apply-op-specialization ctl_decl.qke
cudaq-opt: /opt/llvm/include/llvm/ADT/ilist_iterator.h:138: ...
Assertion `!NodePtr->isKnownSentinel()' failed.
Aborted (core dumped)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4268
This PR fixes a crash in apply-op-specialization when adjoint is requested for a forward-declared kernel whose body is not available in the current translation unit.
Instead of crashing with an internal assertion, the compiler now emits a clear diagnostic and fails gracefully.
Root Cause
During specialization, the pass attempted to generate an adjoint variant for declaration-only functions. Since no function body exists, the transformation pipeline eventually hit an invalid internal state and aborted with an assertion.
What Changed
cannot create adjoint variant for forward-declared kernel ... (kernel body is unavailable in this translation unit)
Validation
Impact