================ @@ -4022,8 +4168,36 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E, ArrayLV = EmitArraySubscriptExpr(ASE, /*Accessed*/ true); else ArrayLV = EmitLValue(Array); + auto *Idx = EmitIdxAfterBase(/*Promote*/true); + if (SanOpts.has(SanitizerKind::ArrayBounds)) { + const LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel = + getLangOpts().getStrictFlexArraysLevel(); + + if (const auto *ME = dyn_cast<MemberExpr>(Array); + ME && + ME->isFlexibleArrayMemberLike(getContext(), StrictFlexArraysLevel) && + ME->getMemberDecl()->hasAttr<CountedByAttr>()) { + RecordDecl *RD = ME->getMemberDecl() + ->getDeclContext() + ->getOuterLexicalRecordContext(); + Expr *StructBase = + StructAccessBase(RD).Visit(const_cast<MemberExpr *>(ME)); + + if (StructBase && StructBase->getType()->isPointerType()) { ---------------- nickdesaulniers wrote:
`ME` is declared inside the `if` but `StructBase` is not. I don't care particularly which pattern you use, but let's use one style consistently? (either move `ME` out or `StructBase` in?) if you make the `if` with `ME` just ``` if (const auto *ME = ...) { ``` then you could sink getting the flex array level to within the `if`. https://github.com/llvm/llvm-project/pull/73730 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits