This is an archive of the discontinued LLVM Phabricator instance.

[clang] When loading preamble from AST file, re-export modules in Sema.
ClosedPublic

Authored by adamcz on Aug 17 2020, 6:01 AM.

Details

Summary

This addresses a FIXME in ASTReader.

Modules were already re-exported for Preprocessor, but not for Sema.
The result was that, with -fmodules-local-submodule-visibility, all AST
nodes belonging to a module that was loaded in a premable where not
accesible from the main part of the file and a diagnostic recommending
importing those modules would be generated.

Diff Detail

Event Timeline

adamcz created this revision.Aug 17 2020, 6:01 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 17 2020, 6:01 AM
adamcz requested review of this revision.Aug 17 2020, 6:01 AM
sammccall added inline comments.Aug 18 2020, 5:01 AM
clang/test/PCH/preamble-modules.cpp
9

what are these ifdefs about? you never seem to define this symbol

(Possible you're copying from a test that is doing something tricky like being run in two modes or including itself? Or did you mean to give different flags for the include vs emit pch?)

15

This seems like currently it's never getting parsed as MAIN_FILE is never defined.

adamcz added inline comments.Aug 18 2020, 6:14 AM
clang/test/PCH/preamble-modules.cpp
9

Oh, I stole this trick from Kadir. You compile this file twice. First one is to generate a PCH for preamble. MAIN_FILE is not set, so it only reads the preamble section. The second one has -include-pch. That means MAIN_FILE is now set (from the preamble PCH file), so we only compile the main section.

It's a creative solution to a problem I wish I didn't have ;-)
Is there a better way to do this, without splitting the file in two? preamble_bytes seems fragile.

15

It's parsed. Without this fix, there's a warning generated here. See comment above for explanation.

sammccall accepted this revision.Aug 19 2020, 4:27 AM

Sorry, I was just not reading the test clearly. LGTM

clang/lib/Serialization/ASTReader.cpp
4990

maybe replace this with a comment pointing at UpdateSema() for the sema part

This revision is now accepted and ready to land.Aug 19 2020, 4:27 AM
adamcz updated this revision to Diff 286561.Aug 19 2020, 7:55 AM

Added comment in place of a FIXME

adamcz marked an inline comment as done.Aug 19 2020, 7:56 AM
This revision was landed with ongoing or failed builds.Aug 20 2020, 5:33 AM
This revision was automatically updated to reflect the committed changes.