Required prerequisites
Describe the bug
cudaq-quake fails to emit a quake.discriminate to map measure result type to bool when performing range based for loop.
Steps to reproduce the bug
Build from source and run the circuit below
struct main_circuit {
uint64_t operator()() __qpu__ {
cudaq::qarray<2>reg_1190;
int64_t packed_result = 0; int bit_offset = 0;
for (bool b : mz(reg_1190)){
if (b) packed_result |= (1ULL << bit_offset);
bit_offset++;
}
return packed_result;
}
};
and get a compiler crash, stemming from cudaq-quake.
loc("test.cpp":10:2):error: 'cc.store' op failed to verify that type of value matches element type of pointer
Line 10 being for (bool b : mz(reg_1190)){
The MLIR that contains that cc.store is
%18 = "cc.alloca"() <{elementType = i1}> : () -> !cc.ptr<i1>
%19 = "cc.load"(%17) : (!cc.ptr<!cc.measure_handle>) -> !cc.measure_handle
"cc.store"(%19, %18) : (!cc.measure_handle, !cc.ptr<i1>) -> ()
The cc.store tries map something of type !cc.measure_handle to !cc.ptr<i1> which is ptr to a bool.
Running the code but with auto instead of bool works. The MLIR at the relevant section is
cc.store %9, %8 : !cc.ptr<!cc.measure_handle> loc(#loc6)
%10 = cc.load %8 : !cc.ptr<!cc.measure_handle> loc(#loc8)
%11 = quake.discriminate %10 : (!cc.measure_handle) -> i1 loc(#loc8)
quake.discriminate added here maps the measure result to the correct type.
Expected behavior
Compiler should not crash
Is this a regression? If it is, put the last known working version (or commit) here.
Not a regression
Environment
- CUDA-Q version: b04dee5
- Python version: 3.12.3
- C++ compiler: clang++-22
- Operating system: Ubuntu 24.04
Suggestions
No response
Required prerequisites
Describe the bug
cudaq-quakefails to emit aquake.discriminateto map measure result type to bool when performing range based for loop.Steps to reproduce the bug
Build from source and run the circuit below
and get a compiler crash, stemming from
cudaq-quake.loc("test.cpp":10:2):error: 'cc.store' op failed to verify that type of value matches element type of pointerLine 10 being
for (bool b : mz(reg_1190)){The MLIR that contains that
cc.storeisThe
cc.storetries map something of type!cc.measure_handleto!cc.ptr<i1>which is ptr to a bool.Running the code but with
autoinstead ofboolworks. The MLIR at the relevant section isquake.discriminateadded here maps the measure result to the correct type.Expected behavior
Compiler should not crash
Is this a regression? If it is, put the last known working version (or commit) here.
Not a regression
Environment
Suggestions
No response