Software Archive
Read-only legacy content
17061 Discussions

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

tfk
Beginner
303 Views

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;
}

0 Kudos
2 Replies
Balaji_I_Intel
Employee
303 Views

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.

0 Kudos
tfk
Beginner
303 Views

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!)

0 Kudos
Reply