This is an archive of the discontinued LLVM Phabricator instance.

Actually delay processing DelayedDllExportClasses until the outermost class is finished (PR40006)
ClosedPublic

Authored by hans on Dec 2 2019, 7:55 AM.

Details

Summary

This was already the intention of DelayedDllExportClasses, but this test case would break it:

template<typename> struct Tmpl {};
struct Outer {
    struct Inner {
        __declspec(dllexport) Inner() = default;
        unsigned int x = 0;
    };
    Tmpl<Inner> y;
};

ActOnFinishCXXNonNestedClass() would get called when the instantiation of Templ<Inner> is finished, even though the compiler is still not finished with Outer, causing the compile fail.

This hooks into Sema::{Push,Pop}ParsingClass() to avoid calling ActOnFinishCXXNonNestedClass() for template instantiations while a class is being parsed.

This was the cleanest solution I could come up with :-)

Diff Detail

Event Timeline

hans created this revision.Dec 2 2019, 7:55 AM
rnk added a comment.Dec 3 2019, 2:56 PM

It occurs to me that this will cause some strange ordering in some cases. Consider:

namespace pr40006 {
// Delay emitting the method also past the instantiation of Tmpl<Inner>, i.e.
// until the top-level class Outer is completely finished.
template<typename> struct Tmpl {};
struct Outer {
    struct Inner {
        __declspec(dllexport) Inner() = default;
        unsigned int x = 0;
    };
    // not instantiated
};

struct Other {
    Tmpl<Outer::Inner> y;
};
// M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc %"struct.InClassInits::pr40006::Outer::Inner"* @"??0Inner@Outer@pr40006@InClassInits@@QAE@XZ"
}

When we'd process y before, we would immediately emit delayed dllexported things. Now we will wait until Other is done parsing, which is fine, but not as eager as we could be. That's fine, but it's a slight behavior change.

clang/lib/Sema/SemaTemplateInstantiate.cpp
2232

This function doesn't use its argument. Can you remove it so that is clear that we don't need to track this somewhere else?

rnk accepted this revision.Dec 3 2019, 2:57 PM

I'll add, looks good with suggested fix.

This revision is now accepted and ready to land.Dec 3 2019, 2:57 PM
hans marked 2 inline comments as done.Dec 4 2019, 4:18 AM

Thanks for the review!

clang/lib/Sema/SemaTemplateInstantiate.cpp
2232

Done.

This revision was automatically updated to reflect the committed changes.
hans marked an inline comment as done.
Herald added a project: Restricted Project. · View Herald TranscriptDec 4 2019, 4:25 AM