@@ -4778,23 +4778,25 @@ EmitExtVectorElementExpr(const ExtVectorElementExpr *E) {
4778
4778
Base.getBaseInfo (), TBAAAccessInfo ());
4779
4779
}
4780
4780
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
+
4781
4788
LValue CodeGenFunction::EmitMemberExpr (const MemberExpr *E) {
4782
4789
if (DeclRefExpr *DRE = tryToConvertMemberExprToDeclRefExpr (*this , E)) {
4783
4790
EmitIgnoredExpr (E->getBase ());
4784
4791
return EmitDeclRefLValue (DRE);
4785
4792
}
4786
4793
4787
4794
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);
4798
4800
// If this is s.x, emit s as an lvalue. If it is s->x, emit s as a scalar.
4799
4801
LValue BaseLV;
4800
4802
if (E->isArrow ()) {
0 commit comments