Skip to content

Commit a273d17

Browse files
committed
[OpenMP][FIX] Do not add implicit argument to device Ctors and Dtors
Constructors and destructors on the device do not take any arguments, also not the implicit dyn_ptr argument other kernels automatically take.
1 parent 3c97c8b commit a273d17

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,9 @@ void *GenericKernelTy::prepareArgs(
511511
uint32_t &NumArgs, llvm::SmallVectorImpl<void *> &Args,
512512
llvm::SmallVectorImpl<void *> &Ptrs,
513513
KernelLaunchEnvironmentTy *KernelLaunchEnvironment) const {
514+
if (isCtorOrDtor())
515+
return nullptr;
516+
514517
NumArgs += 1;
515518

516519
Args.resize(NumArgs);

openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,12 @@ struct GenericKernelTy {
284284
/// Get the kernel name.
285285
const char *getName() const { return Name; }
286286

287+
/// Return true if this kernel is a constructor or destructor.
288+
bool isCtorOrDtor() const {
289+
// TODO: This is not a great solution and should be revisited.
290+
return StringRef(Name).endswith("tor");
291+
}
292+
287293
/// Get the kernel image.
288294
DeviceImageTy &getImage() const {
289295
assert(ImagePtr && "Kernel is not initialized!");
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %libomptarget-compilexx-run-and-check-generic
2+
// RUN: %libomptarget-compileoptxx-run-and-check-generic
3+
//
4+
#include <cstdio>
5+
struct S {
6+
S() : i(7) {}
7+
~S() { foo(); }
8+
int foo() { return i; }
9+
10+
private:
11+
int i;
12+
};
13+
14+
S s;
15+
#pragma omp declare target(s)
16+
17+
int main() {
18+
int r;
19+
#pragma omp target map(from : r)
20+
r = s.foo();
21+
22+
// CHECK: 7
23+
printf("%i\n", r);
24+
}

0 commit comments

Comments
 (0)