[PATCH] D91055: [clang-tidy] Introduce misc No Integer To Pointer Cast check

Juneyoung Lee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 27 11:42:06 PST 2020

aqjune added inline comments.

Comment at: clang-tools-extra/docs/clang-tidy/checks/misc-no-inttoptr.rst:12
+if you got that integral value via a pointer-to-integer cast originally,
+the new pointer will lack the provenance information from the original pointer.
aaron.ballman wrote:
> Does this run afoul of the C++ standard's requirements for pointer traceability: http://eel.is/c++draft/basic.stc.dynamic.safety ?
This is fine because the compiled IR is allowed to be more defined than the C++ source.

In C++, accessing a pointer that is derived from an integer is UB if it is out-of-bounds location of the object pointed by the integer.
In LLVM IR (I mean in the suggested memory model), it is relaxed to have well-defined behavior if the pointer is pointing to a different, but in-bounds location of an object.
This loses the precision of points-to analysis if inttoptr is involved, but makes more arithmetic optimizations on integers valid.

  rG LLVM Github Monorepo



More information about the llvm-commits mailing list