This is an archive of the discontinued LLVM Phabricator instance.

[C++20][Modules][HU 3/5] Emit module macros for header units.
ClosedPublic

Authored by iains on Mar 7 2022, 2:26 AM.

Details

Summary

For header units we build the top level module directly from the header
that it represents and macros defined in this TU need to be emitted (when
such a definition is live at the end of the TU).

Diff Detail

Event Timeline

iains created this revision.Mar 7 2022, 2:26 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 7 2022, 2:26 AM
iains published this revision for review.Mar 7 2022, 4:39 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 7 2022, 4:39 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
iains updated this revision to Diff 413913.Mar 8 2022, 12:42 PM

updated to remove a single-use variable.

Having some difficulty in reproducing the CI fails outside the harness, however the
code setting the removed variable could have faulted if there was no macro data for
the identifier. Set the IsHeaderUnit variable explicitly.

iains updated this revision to Diff 414890.Mar 12 2022, 3:20 PM

rebased.

Maybe it's worth to add a test from: http://eel.is/c++draft/cpp.import#8

clang/include/clang/Serialization/ASTWriter.h
128–129

I think the member is redundant. I thought we could use WritingModule->isHeaderUnit() to replace it.

clang/lib/Serialization/ASTWriter.cpp
2286–2287

We could replace the use of Mod with WritingModule too. (If I don't misread the code)

2356–2376

Is it possible to merge the implementation with the following for PCH? It looks like there are some redundancies.

2358–2360

How about to add comments to show the different logic of emitting macros for header unit and PCH? I guess other readers might be confusing too.

iains updated this revision to Diff 416194.Mar 17 2022, 8:50 AM
iains marked 4 inline comments as done.

address review comments, match windows path separators in tests.

iains added inline comments.Mar 17 2022, 8:50 AM
clang/include/clang/Serialization/ASTWriter.h
128–129

yeah we can do this - I added a "isHeaderUnit()" method to Module.h to do this.

clang/lib/Serialization/ASTWriter.cpp
2356–2376

Well, that was what I had originally, I actually split it out as it is now because the difference in the logic around which macros are written out was making the code pretty confusing to read. If there's a strong feeling about this, perhaps we can see if there's some way to factor it (perhaps with some place-holder vars).

I feel good if we could add the test from: http://eel.is/c++draft/cpp.import#8.

clang/include/clang/Serialization/ASTWriter.h
21

This is redundant too.

clang/lib/Serialization/ASTWriter.cpp
2356–2376

I agree with you. I tried to refactor it myself and find things didn't get better.

iains added a comment.Mar 18 2022, 2:27 AM

I feel good if we could add the test from: http://eel.is/c++draft/cpp.import#8.

I agree we should have tests based on all the relevant examples in the standard.

However, that specific example is not connected with building header units, but instead is connected with consuming various preprocessor directives etc. when building a regular module. We actually already have some of the tests in diagnosing bad imports.

So I think that (after this series is in) we should be in a position to add some more of the examples in the standard - as a follow-on patch, does that make sense?

ChuanqiXu accepted this revision.Mar 20 2022, 7:56 PM

I feel good if we could add the test from: http://eel.is/c++draft/cpp.import#8.

I agree we should have tests based on all the relevant examples in the standard.

However, that specific example is not connected with building header units, but instead is connected with consuming various preprocessor directives etc. when building a regular module. We actually already have some of the tests in diagnosing bad imports.

So I think that (after this series is in) we should be in a position to add some more of the examples in the standard - as a follow-on patch, does that make sense?

Yeah, it makes sense. This one LGTM.

This revision is now accepted and ready to land.Mar 20 2022, 7:56 PM
iains updated this revision to Diff 416845.Mar 21 2022, 1:33 AM

rebased.

iains updated this revision to Diff 418081.Mar 24 2022, 4:41 PM

rebased

hvdijk added a subscriber: hvdijk.Apr 1 2022, 4:00 AM
hvdijk added inline comments.
clang/test/Modules/cxx20-hu-04.cpp
22

On Windows, when the path starts with C:\Users\..., I am seeing

error: 'warning' diagnostics seen but not expected: 

  Line 1: \U used with no following hex digits; treating as '\' followed by identifier

1 error generated.

Looking at this test, TDIR is only used as a FileCheck variable, can it just be removed from this line?

iains added inline comments.Apr 1 2022, 4:17 AM
clang/test/Modules/cxx20-hu-04.cpp
22

Sorry about that, Yes, I think that change should be fine - I will take care of it,

iains added a comment.Apr 3 2022, 6:36 AM

applied [C++20][Modules] Fix a testcase warning on Windows [NFC].
https://github.com/llvm/llvm-project/commit/1f0b8ba47ab0f1dc678099d4830d0cc0d10850b6
should be fixed now.