OpenCilk / opencilk-project

Monorepo for the OpenCilk compiler. Forked from llvm/llvm-project and based on Tapir/LLVM.
Other
93 stars 29 forks source link

Reducers don't seem to work in templated functions #132

Closed wheatman closed 2 years ago

wheatman commented 2 years ago

Describe the bug

If I use a reducer in a templated function the compiler gives me an error

Expected behavior

The reducer to work

OpenCilk version

clang version 14.0.6 (https://github.com/OpenCilk/opencilk-project fc90ded2b090672f84c58d12d8d85cd999eb6c1a) Target: x86_64-unknown-linux-gnu Thread model: posix

Steps to reproduce (include relevant output)

compile the following code

#include <cilk/cilk.h>

void zero(void *v) { *(int *)v = 0; }

void plus(void *l, void *r) { *(int *)l += *(int *)r; }

template <typename T> int f() {
  int cilk_reducer(zero, plus) red;
  red += 5;
  return red;
}

int main() { return f<int>(); }

with clang++ -fopencilk -o basic test.cpp

The error is

warning: ISO C++ does not allow indirection on operand of type 'void *' [-Wvoid-ptr-dereference]
test.cpp:13:21: note: in instantiation of function template specialization 'f<int>' requested here
int main() { return f<int>(); }
                    ^
test.cpp:9:7: error: invalid operands to binary expression ('void' and 'int')
  red += 5;
      ^  ~
warning: ISO C++ does not allow indirection on operand of type 'void *' [-Wvoid-ptr-dereference]
error: cannot initialize return object of type 'int' with an lvalue of type 'void'
2 warnings and 2 errors generated.

Additional comments

If I just remove the templates it compiles and seems to work.