diff --git a/gen/semantic-dcompute.cpp b/gen/semantic-dcompute.cpp index 157656a02f..86c8f3baea 100644 --- a/gen/semantic-dcompute.cpp +++ b/gen/semantic-dcompute.cpp @@ -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; diff --git a/tests/semantic/dcompute_template.d b/tests/semantic/dcompute_template.d new file mode 100644 index 0000000000..443b163ee7 --- /dev/null +++ b/tests/semantic/dcompute_template.d @@ -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(); +} + diff --git a/tests/semantic/dcompute_template_fail.d b/tests/semantic/dcompute_template_fail.d new file mode 100644 index 0000000000..e8ea3e6b5b --- /dev/null +++ b/tests/semantic/dcompute_template_fail.d @@ -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(); +} diff --git a/tests/semantic/inputs/notatcompute.d b/tests/semantic/inputs/notatcompute.d index b204bb818c..51615b2f91 100644 --- a/tests/semantic/inputs/notatcompute.d +++ b/tests/semantic/inputs/notatcompute.d @@ -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; } +}