[PATCH] D124677: [ConstantFold] Don't convert getelementptr to ptrtoint+inttoptr
Juneyoung Lee via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 30 03:36:24 PDT 2022
aqjune added a comment.
I agree that introducing ptrtoint + inttoptr here doesn't sound like a good idea because both it is bad for alias analysis and its correctness is not clear.
> For the case where V == ptrtoint Ptr, this folds to inttoptr 0, which further folds to null. In that case provenance becomes incorrect. This has been observed as a real-world miscompile with rustc.
If LLVM is using the definition of null pointer in C, inttoptr 0 must be `null`, implying that folding `gep p, -(ptrtoint p)` to `null` must be the problematic one.
C17, 6.3.2.3.p3. An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D124677/new/
https://reviews.llvm.org/D124677
More information about the llvm-commits
mailing list