TBAA: `-new-struct-path-tbaa `status

-new-struct-path-tbaa is work from ~6Y ago (although I think the discussion started ~10Y ago ) authored by @kosarev with fixes from ~1Y ago by @brunodf. It creates !tbaa metadata for structs and members where it wasn’t available before - in particular improving the optimizations for strong-typedefs, making them essentially zero-cost abstractions as they are advertised to be. Godbolt toy example here.

I really hope this work can stop hiding behind the -new-struct-path-tbaa switch. I built and tested some projects with it and personally I consider it stable. Is there any planned route forward with this?

1 Like

I would propose you make a patch to turn it on. We can use @nikic’s compile time tracker to see the impact. If it works alright, we can turn it on. If we see something in the meantime, we can investigate further.

Unfortunately when enabling it by default TBAAMetadataTest fails - it expects a different !tbaa layout. I couldn’t figure out the semantics of the new !tbaa - I can just change the expected result to match. Should I?

We’d need that for sure. We should test more software and see if the new encoding itself is causing problems.

@jdoerfert I finished fixing the regular tbaa test and setting up a matching new-path-struct-tbaa test, but came across what seems like a regression, for virtual base classes. The following code is from TBAAMetadataTest.VirtualBase:

    struct Base {
      int f32;

    struct Derived : public virtual Base {
      short f16;

    void func(Base *B, Derived *D) {
      B->f32 = 14;
      D->f16 = 35;
      D->f32 = 77;

Regular tbaa includes tbaa attribute for Derived, while new-struct-path-tbaa doesn’t :

You can check interactively at this godbolt:

The final assembly for this particular code is identical AND virtual base classes are pretty rare, so I’m not sure if this is a blocking issue.
I suggest:
(1) I’ll submit a patch with just the new tests for new-struct-path-tbaa (with matching expected results, i.e without this missing Derived tbaa metadata).
(2) Maybe I’ll open an issue for this regression? Do you think it has a chance of receiving attention? (Who should I @mention here or at github for this?)