@@ -4513,15 +4513,21 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E,
45134513 // The array element is complete, even if the array is not.
45144514 EltTBAAInfo = CGM.getTBAAAccessInfo (E->getType ());
45154515 } else {
4516- // Extend struct path from base lvalue, similar to EmitLValueForField.
4516+ // The TBAA access info from the array (base) lvalue is ordinary. We will
4517+ // adapt it to create access info for the element.
45174518 EltTBAAInfo = ArrayLV.getTBAAInfo ();
4518- // If no base type has been assigned for the array access, there is no
4519- // point trying to generate one, since an array is not a valid base type.
4520- //
4521- // The index into the array is a runtime value. We use the same struct
4522- // path for all array elements (that of the element at index 0). So we
4523- // set the access type and size, but do not have to adjust
4524- // EltTBAAInfo.Offset.
4519+
4520+ // We retain the TBAA struct path (BaseType and Offset members) from the
4521+ // array. In the TBAA representation, we map any array access to the
4522+ // element at index 0, as the index is generally a runtime value. This
4523+ // element has the same offset in the base type as the array itself.
4524+ // If the array lvalue had no base type, there is no point trying to
4525+ // generate one, since an array itself is not a valid base type.
4526+
4527+ // The access size must be updated to the size of an individual element.
4528+ // We also reset the access type using the original element type: in case
4529+ // of type decoration on the element type they may have been lost when
4530+ // the array type was canonicalized.
45254531 EltTBAAInfo.AccessType = CGM.getTBAATypeInfo (E->getType ());
45264532 EltTBAAInfo.Size =
45274533 getContext ().getTypeSizeInChars (E->getType ()).getQuantity ();
0 commit comments