[PATCH] D124571: Avoid strict aliasing violation on type punning inside llvm::PointerIntPair

Breno Rodrigues Guimaraes via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 2 17:07:05 PDT 2022


brenoguim added a comment.

The plot thickens.

With my patch, the code below (extracted from `LLParser.cpp`) aborts with all versions of clang *except* v14. Moreover, it passes with gcc (all versions I tested).

  static llvm::PointerIntPair<double*, 3> ptr {(double*)-8};
  int main()
  {
      if (!ptr.getPointer())
          std::abort();
  }

( https://godbolt.org/z/hrTqGfM65 )

It only happens with `ptr` being static. If it's local, then it passes with all compiler versions I tested.

So we are facing either one of:

1. The code is correct and there is a bug in clang that miscompiles it, and this bug was fixed on v14.
2. The code is still violating strict aliasing somehow neither GCC, nor Clang v14 are able to exploit it. And clang up to 14 is able to exploit it.

`2` is unlikely because passing `-fno-strict-aliasing` on the versions that abort makes no difference.

Assuming then it's `1`, my options are:

1. Rework the code with a different logic that is correct and not miscompiled on clang <v14
2. Make the test expect to fail when compiling with clang <v14

Any opinions/suggestions are welcome!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124571/new/

https://reviews.llvm.org/D124571



More information about the llvm-commits mailing list