[clang] [CodeGen] Add TBAA struct path info for array members (PR #137719)
Bruno De Fraine via cfe-commits
cfe-commits at lists.llvm.org
Tue May 20 14:39:12 PDT 2025
================
@@ -4503,7 +4503,29 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E,
E->getType(), !getLangOpts().PointerOverflowDefined, SignedIndices,
E->getExprLoc(), &arrayType, E->getBase());
EltBaseInfo = ArrayLV.getBaseInfo();
- EltTBAAInfo = CGM.getTBAAInfoForSubobject(ArrayLV, E->getType());
+ if (!CGM.getCodeGenOpts().NewStructPathTBAA) {
+ // Since CodeGenTBAA::getTypeInfoHelper only handles array types for
+ // new struct path TBAA, we must a use a plain access.
+ EltTBAAInfo = CGM.getTBAAInfoForSubobject(ArrayLV, E->getType());
+ } else if (ArrayLV.getTBAAInfo().isMayAlias()) {
+ EltTBAAInfo = TBAAAccessInfo::getMayAliasInfo();
+ } else if (ArrayLV.getTBAAInfo().isIncomplete()) {
+ // The array element is complete, even if the array is not.
+ EltTBAAInfo = CGM.getTBAAAccessInfo(E->getType());
+ } else {
+ // Extend struct path from base lvalue, similar to EmitLValueForField.
+ EltTBAAInfo = ArrayLV.getTBAAInfo();
+ // If no base type has been assigned for the array access, there is no
+ // point trying to generate one, since an array is not a valid base type.
+ //
+ // The index into the array is a runtime value. We use the same struct
+ // path for all array elements (that of the element at index 0). So we
+ // set the access type and size, but do not have to adjust
+ // EltTBAAInfo.Offset.
----------------
brunodf-snps wrote:
OK, I've rewritten the code comments for this block.
https://github.com/llvm/llvm-project/pull/137719
More information about the cfe-commits
mailing list