[clang] [Clang] Generate the GEP instead of adding AST nodes (PR #73730)
Nick Desaulniers via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 7 09:00:53 PST 2023
================
@@ -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
More information about the cfe-commits
mailing list