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

Reducer in template function does not work (as expected) #175

Closed ppete closed 1 year ago

ppete commented 1 year ago

Describe the bug

When a reducer is used in templated code, its type seems to be void. Consequently, it is unclear how the reducer can be used (if it is even possible).

Expected behavior

Reducer in templates should behave like as if in non-templated code.

OpenCilk version

System information

Steps to reproduce (include relevant output)

  1. install from .sh

  2. Version Info

clang version 14.0.6 (https://github.com/OpenCilk/opencilk-project fc90ded2b090672f84c58d12d8d85cd999eb6c1a) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /local/bin Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12 Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12 Candidate multilib: .;@m64 Selected multilib: .;@m64

  1. Code does not compile

Working example code (simple.cc)

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

include <cilk/cilk.h>

void sum_init(void sum) { static_cast<int>(sum) = 0.0; } void sum_plus(void lhs, void rhs) { static_cast<int>(lhs) += static_cast<int*>(rhs); }

int cilk_reducer(sum_init, sum_plus) reducer(0);

void plus(int oper) { reducer += oper; }

template auto some_template_function() -> void { reducer += X; // fails // plus(X); // work-around }

int main() { some_template_function<1>(); }

Diagnostic output

warning: ISO C++ does not allow indirection on operand of type 'void *' [-Wvoid-ptr-dereference] simple.cc:24:3: note: in instantiation of function template specialization 'some_template_function<1>' requested here some_template_function<1>(); ^ simple.cc:18:11: error: invalid operands to binary expression ('void' and 'int') reducer += X; // fails ^ ~ 1 warning and 1 error generated.

VoxSciurorum commented 1 year ago

Some of the formatting got stripped out due to HTML processing, but I think I recovered your original program. This is a bug we have fixed in development sources but not in any release.

Do you know how to rebuild OpenCilk from source? The latest development code is branch dev/14.x in repository github.com/OpenCilk/opencilk-project.