9
dmonkey
1y

I ranted about it already.

```c++
if (vec.size() > 0) { // or whatever
cout << vec.size();
// ....
}
```

Its output was zero. And before you ask, it was a single thread program.

Aince it was for my thesis and I was in a hurry I didn't care too much for it.

Yet I think that it was a bug in clang. I removed that piece of code, compiled, rewritten it a bit differently and worked as expected. Never looked back.

Comments
  • 3
    that's weird...
  • 3
    I would love to believe it, but it seems impossibile, unless you didn't include something else in the condition or inside the if.
  • 4
    @JS96 I swear, I spent a whole day around it. Refactoring solved the problem.

    Probably messed up something with JIT or some sort of caching.
  • 0
    I saw a bug in gcc where it would freeze building clang forever and use full cpu while doing it
  • 0
    Maybe an use after free bug?
  • 3
    @dmonkey

    C++ doesn't JIT.

    At least not if you are not using profile-guided optimization, which is not quite JIT anyway.

    There are shenanigans that can be made to make cout do bullshit like that. Just to check, I'd do

    std::cout << vec.size() == 0;

    If that does print true, then I'd worry.

    Otherwise, something shadowed ostream& operator<<(ostream&, int&);, something defined cout locally (note you are not using std::), or there are macro shenanigans.
  • 0
    @CoreFusionX doesn't clang have some kind of jit? I recall something tbh, but if you say so I do belive you.

    At the time I was working with llvm passes. I was building one.

    It was just one single class, with one single method of interest where everything was both created and destroyed there.

    No external stuff besides the stdlib.

    (The bug was in the pass itself, not the IR)
Add Comment