This is an archive of the discontinued LLVM Phabricator instance.

[AST] lookup in parent DeclContext for transparent DeclContext
ClosedPublic

Authored by ChuanqiXu on Jan 6 2022, 11:14 PM.

Details

Summary

The compiler would crash if we lookup for name in transparent decl context. The tests in this revision are two examples. godbolt example is here: https://llvm.godbolt.org/z/W497zGW5T (I didn't attach module examples in godbolt since I don't know how to do).

I think this should make sense since the member declared in transparent DeclContext are semantically defined in the enclosing (non-transparent) DeclContext, this is the definition for transparent DeclContext.

Diff Detail

Event Timeline

ChuanqiXu requested review of this revision.Jan 6 2022, 11:14 PM
ChuanqiXu created this revision.

I had to do something similar for this at one point: https://github.com/llvm/llvm-project/commit/90010c2e1d60c6a9a4a0b30a113d4dae2b7214eb

I seem to remember hitting this assert, and from my end, I think I decided even calling 'lookup' with the linkage spec to be a mistake (BTW, you might consider updating that 'Encloses' for 'export' as well!).

Is there any mechanism in the parent call of 'lookup' here to make it get the right thing?

I had to do something similar for this at one point: https://github.com/llvm/llvm-project/commit/90010c2e1d60c6a9a4a0b30a113d4dae2b7214eb

I seem to remember hitting this assert, and from my end, I think I decided even calling 'lookup' with the linkage spec to be a mistake (BTW, you might consider updating that 'Encloses' for 'export' as well!).

Yeah, it is another bug for 'export'. I've tried to address it in https://reviews.llvm.org/D116911 with the same style.

Is there any mechanism in the parent call of 'lookup' here to make it get the right thing?

And 'lookup' is called in various places. For example, from the stack trace of the crash, we could find that the parent of call is DeclareImplicitDeductionGuides. And I tried to handle it in DeclareImplicitDeductionGuides, then the compiler would crash again at LookupDirect in SemaLookup.cpp. I feel it is not good to add checks for places to call lookup. I agree that it is odd to lookup in a transparent DeclContext. But I feel it is not bad to lookup in the enclosing context from the definition of transparent DeclContext. Any thoughts?

erichkeane accepted this revision.Jan 10 2022, 6:17 AM

I had to do something similar for this at one point: https://github.com/llvm/llvm-project/commit/90010c2e1d60c6a9a4a0b30a113d4dae2b7214eb

I seem to remember hitting this assert, and from my end, I think I decided even calling 'lookup' with the linkage spec to be a mistake (BTW, you might consider updating that 'Encloses' for 'export' as well!).

Yeah, it is another bug for 'export'. I've tried to address it in https://reviews.llvm.org/D116911 with the same style.

Is there any mechanism in the parent call of 'lookup' here to make it get the right thing?

And 'lookup' is called in various places. For example, from the stack trace of the crash, we could find that the parent of call is DeclareImplicitDeductionGuides. And I tried to handle it in DeclareImplicitDeductionGuides, then the compiler would crash again at LookupDirect in SemaLookup.cpp. I feel it is not good to add checks for places to call lookup. I agree that it is odd to lookup in a transparent DeclContext. But I feel it is not bad to lookup in the enclosing context from the definition of transparent DeclContext. Any thoughts?

Hmm... I didn't realize this was the root 'lookup' function, and thank you for the above analysis. It seems to make more sense to me as well to have this be tolerant of this lookup setup. So LGTM.

This revision is now accepted and ready to land.Jan 10 2022, 6:17 AM