gcc compiler bug - cilk_for loops in templatized code incorrectly scope index variable.

gcc compiler bug - cilk_for loops in templatized code incorrectly scope index variable.

I think I've encountered a compiler bug that causes the index variable in cilk_for loops to be declared in their parent's scope. I've observed it for gcc 4.8 and 4.9. I've only been able to reproduce the bug when the cilk_for loops appear in templatized code. I've attached a minimal working example which you can compile to reproduce the bug. The relevant portion of code demonstrating the bug is also at the end of this post.

Cheers,

Tim

template<typename T>
void foo() {
  cilk_for(int i = 0; i < 5; i++) {
    printf("Loop iter: %d",i);
  }

  // Will get redeclaration error for 'int i'. 
  cilk_for(int i = 0; i < 5; i++) {
    printf("Loop iter: %d",i);
  }
}

void bar() {
  cilk_for(int i = 0; i < 5; i++) {
    printf("Loop iter: %d",i);
  }

  cilk_for(int i = 0; i < 5; i++) {
    printf("Loop iter: %d",i);
  }
}

int main(int argc, char **argv)
{
  bar(); // compiles.
  foo<int>(); // doesn't compile.
  return 0;
}

AttachmentSize
Download cilkfor-bug.tar.gz519 bytes
3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Hello tfk,

    Thank you for reporting this bug. I will look into this and get back to you as soon as I get a fix.

 

Thanks,

Balaji V. Iyer.

This bug still appears in the latest versions of gcc on the cilkbranch (4.9) and other (4.8). This is an annoying issue as it prevents easily porting existing cilk code that currently uses icc to gcc, as well as making it difficult to parallelize real applications using gcc with cilk (since real c++ applications tend to use templates!)

Leave a Comment

Please sign in to add a comment. Not a member? Join today