This is an archive of the discontinued LLVM Phabricator instance.

[AST] [Modules] Introduce Decl::getNonTransparentDeclContext to handle exported friends
ClosedPublic

Authored by ChuanqiXu on Aug 10 2022, 11:18 PM.

Details

Summary

Closing https://github.com/llvm/llvm-project/issues/56826.

The root cause for pr56826 is: when we collect the template args for the friend, we need to judge if the friend lives in file context. However, if the friend lives in ExportDecl lexically, the judgement here is invalid.

The solution is easy. We should judge the non transparent context and the ExportDecl is transparent context. So the solution should be good.

A main concern may be the patch doesn't handle all the places of the same defect. I think it might not be bad since the patch itself should be innocent.

Another alternative may let the Decl::getContext() return non transparent context but I feel it changes too drastically.

Diff Detail

Event Timeline

ChuanqiXu created this revision.Aug 10 2022, 11:18 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 10 2022, 11:18 PM
ChuanqiXu requested review of this revision.Aug 10 2022, 11:18 PM
ChuanqiXu added inline comments.Aug 10 2022, 11:20 PM
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
6152

I'm pretty sure we should use getNonTransparentDeclContext here. But I don't want to do a NFC change without being covered by a test. So I left a FIXME here. And we could change it after we find the test case. The decision may be a little painful but I think it is more stable.

ChuanqiXu added inline comments.Aug 10 2022, 11:22 PM
clang/include/clang/AST/DeclBase.h
2020

Export declaration has already been the transparent declaration for a long time. But we just forget to edit the comment.

I think this is fine. I vaguely remember doing something like this in the past, but I can't seem to figure out what it was...

clang/lib/AST/DeclBase.cpp
1037

so why are we calling this on our DeclContext here, which is the 'parent' of the current Decl? Shouldn't this be casting itself to DeclContext and calling this function on it, so we don't end up 'skipping' the first parent?

erichkeane accepted this revision.Aug 11 2022, 6:24 AM

LGTM, thanks!

clang/lib/AST/DeclBase.cpp
1037

Ah, I see... getNonTransparentContext works differently from the other getDeclContext type functions in that it does NOT get the 1st parent, it will return the 'current' DeclContext if necessary. So casting it would be incorrect here. Strange that this works opposite of the rest, but looks like you're right :)

This revision is now accepted and ready to land.Aug 11 2022, 6:24 AM