This is an archive of the discontinued LLVM Phabricator instance.

[CodeGen] EmitPointerWithAlignment() to generate TBAA info along with LValue base info
ClosedPublic

Authored by kosarev on Oct 11 2017, 6:02 AM.

Diff Detail

Event Timeline

kosarev created this revision.Oct 11 2017, 6:02 AM
rjmccall accepted this revision.Oct 12 2017, 3:38 PM

Yes, thank for you handling the cast case well.

This revision is now accepted and ready to land.Oct 12 2017, 3:38 PM
This revision was automatically updated to reflect the committed changes.

With this patch applied we fail on bootstrapping stages of release builds (meaning enabled TBAA).

The reason is that for some casts we do not generate TBAA info that corresponds to the target type and leave them with TBAA info for the cast's operand expression. This results in invalid TBAA access descriptors. For example, for the following store we generate a TBAA descriptor with S as the base type and unsigned as the access type while the expected descriptor shall have V as the base type and unsigned as the access type.

struct V {
  unsigned n;
};

struct S {
  char bytes[4];
};

void foo(S *p) {
  ((V*)p->bytes)->n = 0;
}
kosarev reopened this revision.Oct 15 2017, 1:02 PM
This revision is now accepted and ready to land.Oct 15 2017, 1:02 PM
kosarev updated this revision to Diff 119089.Oct 15 2017, 1:03 PM
kosarev edited the summary of this revision. (Show Details)
  • Fixed handling of explicit casts.
  • Added a test case.
kosarev requested review of this revision.Oct 15 2017, 1:03 PM
kosarev edited edge metadata.
This revision is now accepted and ready to land.Oct 16 2017, 10:52 PM
This revision was automatically updated to reflect the committed changes.

I think probably the best solution is to track may-alias-ness explicitly in the TBAAAccessInfo instead of relying in the frontend on being able to distinguish things in the LLVM metadata.