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

附件尺寸
下载 cilkfor-bug.tar.gz519 字节
3 帖子 / 0 全新
最新文章
如需更全面地了解编译器优化,请参阅优化注意事项

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

发表评论

登录添加评论。还不是成员?立即加入