Skip to content

Commit

Permalink
Add regression test for passing a pointer to a struct. (#988)
Browse files Browse the repository at this point in the history
Closes #351.
  • Loading branch information
schweitzpgi authored Dec 4, 2023
1 parent a76a725 commit 9d74d12
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/NVQPP/struct_arg.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*******************************************************************************
* Copyright (c) 2022 - 2023 NVIDIA Corporation & Affiliates. *
* All rights reserved. *
* *
* This source code and the accompanying materials are made available under *
* the terms of the Apache License 2.0 which accompanies this distribution. *
******************************************************************************/

// RUN: nvq++ --enable-mlir --emit-qir %s && cat struct_arg.qir.ll | \
// RUN: FileCheck %s ; rm struct_arg.qir.ll

#include <cudaq.h>
#include <iostream>

struct baz {
void operator()(cudaq::qubit &q) __qpu__ { x(q); }
};

struct foo {
template <typename CallableKernel>
void operator()(CallableKernel &&func, int n) __qpu__ {
cudaq::qreg q(n);
func(q[0]);
mz(q[0]);
}
};

// CHECK-LABEL: define void @_ZN3fooclI3bazEEvOT_i
// CHECK-SAME: (i8* nocapture readnone %{{.*}}, {}* nocapture readnone %{{.*}}, i32 %{{.*}})

int main() {
auto result = cudaq::sample(1000, foo{}, baz{}, 1);
for (auto &&[bits, counts] : result) {
std::cout << bits << " : " << counts << '\n';
}
return 0;
}

0 comments on commit 9d74d12

Please sign in to comment.