@@ -4778,23 +4778,25 @@ EmitExtVectorElementExpr(const ExtVectorElementExpr *E) {
47784778 Base.getBaseInfo (), TBAAAccessInfo ());
47794779}
47804780
4781+ bool CodeGenFunction::isUnderlyingBasePointerConstantNull (const Expr *E) {
4782+ const Expr *UnderlyingBaseExpr = E->IgnoreParens ();
4783+ while (auto *BaseMemberExpr = dyn_cast<MemberExpr>(UnderlyingBaseExpr))
4784+ UnderlyingBaseExpr = BaseMemberExpr->getBase ()->IgnoreParens ();
4785+ return getContext ().isSentinelNullExpr (UnderlyingBaseExpr);
4786+ }
4787+
47814788LValue CodeGenFunction::EmitMemberExpr (const MemberExpr *E) {
47824789 if (DeclRefExpr *DRE = tryToConvertMemberExprToDeclRefExpr (*this , E)) {
47834790 EmitIgnoredExpr (E->getBase ());
47844791 return EmitDeclRefLValue (DRE);
47854792 }
47864793
47874794 Expr *BaseExpr = E->getBase ();
4788- bool IsInBounds = !getLangOpts ().PointerOverflowDefined ;
4789- if (IsInBounds) {
4790- // Check whether the underlying base pointer is a constant null.
4791- // If so, we do not set inbounds flag for GEP to avoid breaking some
4792- // old-style offsetof idioms.
4793- Expr *UnderlyingBaseExpr = BaseExpr->IgnoreParens ();
4794- while (auto *BaseMemberExpr = dyn_cast<MemberExpr>(UnderlyingBaseExpr))
4795- UnderlyingBaseExpr = BaseMemberExpr->getBase ()->IgnoreParens ();
4796- IsInBounds = !getContext ().isSentinelNullExpr (UnderlyingBaseExpr);
4797- }
4795+ // Check whether the underlying base pointer is a constant null.
4796+ // If so, we do not set inbounds flag for GEP to avoid breaking some
4797+ // old-style offsetof idioms.
4798+ bool IsInBounds = !getLangOpts ().PointerOverflowDefined &&
4799+ !isUnderlyingBasePointerConstantNull (BaseExpr);
47984800 // If this is s.x, emit s as an lvalue. If it is s->x, emit s as a scalar.
47994801 LValue BaseLV;
48004802 if (E->isArrow ()) {
0 commit comments