I'm not sure if the code comment is adequate or even correct, but hopefully the change itself is valid.
Eli cited this section of the standard in PR35909 ( https://bugs.llvm.org/show_bug.cgi?id=35909 ):
[expr.static.cast] p11: "If the prvalue of type “pointer to cv1 B” points to a B that is actually a subobject of an object of type D, the resulting pointer points to the enclosing object of type D. Otherwise, the behavior is undefined."
In the motivating case in the bug report, LLVM can't eliminate a nullptr check because a GEP is not marked with 'inbounds':
class A { int a; }; class B { int b; public: A *getAsA(); }; class X : public A, public B { int x; }; A *B::getAsA() { if (b == 42) { auto temp = static_cast<X*>(this); //__builtin_assume(temp != nullptr); return temp; } return nullptr; } void helper(A *); void test(B *b) { auto temp = b->getAsA(); if (temp) return helper(temp); }
Not sure this comment really adds anything, unless you want to cite the standard.