archer icon indicating copy to clipboard operation
archer copied to clipboard

[BUG] to_string does not work inside omp parallel

Open planetA opened this issue 7 years ago • 7 comments

Hi,

here is a minimal example

#include <iostream>
#include <string>

int main()
{
  int a = 2222;
#pragma omp parallel for
  for (int i = 0; i < 10000; i++) {
    std::cout << a << std::endl;
    std::cout << std::to_string(a) << std::endl;
  }
}

without archer it prints 2222 all the time with archer to_string prints 4986765

Version:

clang version 3.9.1 (tags/RELEASE_391/final) Target: x86_64-unknown-linux-gnu

planetA avatar Jun 22 '17 11:06 planetA

Hi,

thanks for reporting this problem. This is actually a known problem, our static analysis pass does not work well with C++ code, especially with third-party library (such as the std lib).

As a temporary fix you can run archer without static analysis just removing this string -Xclang -load -Xclang /your/path/LLVMArcher.so from clang-archer and clang-archer++ commands.

simoatze avatar Jun 22 '17 14:06 simoatze

I replaced to_string with snprintf, so this kind of solved the problem. But I suspect that archer may miss some race conditions, because I get non-deterministic result in my program when I shouldn't. Would you advise me not to use C++ with archer at all?

planetA avatar Jun 22 '17 14:06 planetA

As I said, Archer static analysis phase has troubles with C++, if you remove the pass from the archer commands it would only apply the dynamic analysis at runtime and everything should work fine even with C++.

simoatze avatar Jun 22 '17 14:06 simoatze

OK. Thank you.

planetA avatar Jun 22 '17 14:06 planetA

@simoatze: should this limitation be documented somewhere? In particular, how do can disable the static analysis?

dongahn avatar Jun 22 '17 17:06 dongahn

@dongahn I was thinking to add an option in the archer drivers to disable the static analysis

simoatze avatar Jun 22 '17 18:06 simoatze

yeah, that be great.

dongahn avatar Jun 22 '17 18:06 dongahn