Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gen/semantic-dcompute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ struct DComputeSemanticAnalyser : public StoppableVisitor {
return true;
if (currentFunction == nullptr)
return false;
if (f->isInstantiated())
return true;
TemplateInstance *inst = currentFunction->isInstantiated();
if (!inst)
return false;
Expand Down
29 changes: 29 additions & 0 deletions tests/semantic/dcompute_template.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// RUN: %ldc -o- -mdcompute-targets=cuda-350 %s -I%S
// REQUIRES: target_NVPTX
@compute(CompileFor.deviceOnly) module tests.semantic.dcompute_template;
import ldc.dcompute;
import inputs.notatcompute : identity, A, B;

@kernel void test()()
{
auto x = identity(42);
}
alias realtest = test!();

@kernel void test2()
{
auto x = identity(42);
}

@kernel void test3()
{
A a;
a.foo();
}

@kernel void test4()
{
B!() b;
b.foo();
}

11 changes: 11 additions & 0 deletions tests/semantic/dcompute_template_fail.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// RUN: not %ldc -o- -mdcompute-targets=cuda-350 -I%S %s 2>&1 | FileCheck %s
// REQUIRES: target_NVPTX
@compute(CompileFor.deviceOnly) module tests.semantic.dcompute_template_fail;
import ldc.dcompute;
import inputs.notatcompute : callsSomeFunc;

//CHECK: inputs/notatcompute.d(9): Error: can only call functions from other `@compute` modules in `@compute` code
@kernel void test()
{
callsSomeFunc();
}
17 changes: 17 additions & 0 deletions tests/semantic/inputs/notatcompute.d
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
module tests.semantic.inputs.notatcompute;

void somefunc() {}

auto identity()(uint x1) => x1;

void callsSomeFunc()()
{
somefunc();
}

struct A
{
int foo()() { return 0; }
}

struct B()
{
int foo() { return 0; }
}