Skip to content

apply-op-specialization crashes instead of erroring when adjointing a forward-declared kernel #4268

@atgeller

Description

@atgeller

Adjointing a forward-declared __qpu__ function crashes with an assertion failure rather than emitting a diagnostic.

Reproduction

prep.cpp:

#include <cudaq.h>
__qpu__ void prep(cudaq::qubit &q) { h(q); }

main.cpp:

#include <cudaq.h>
__qpu__ void prep(cudaq::qubit &q);
__qpu__ bool kernel() {
  cudaq::qubit q;
  cudaq::adjoint(prep, q);
  return mz(q);
}
int main() {}
nvq++ -c prep.cpp -o prep.o
nvq++ -c main.cpp   # crashes

Expected: a compiler error saying the kernel body is unavailable, or a trap generated in lieu of an adjointed kernel.

Actual:

Assertion `!NodePtr->isKnownSentinel()' failed.
...
ApplySpecializationPass::createAdjointVariantOf
ApplyOpSpecialization.cpp:588

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions