This is an archive of the discontinued LLVM Phabricator instance.

[C++20][Modules][Driver][HU 4/N] Add fdirectives-only mode for preprocessing output.
ClosedPublic

Authored by iains on Mar 14 2022, 4:21 AM.

Details

Summary

When the -fdirectives-only option is used together with -E, the preprocessor
output reflects evaluation of if/then/else directives.

Thus it preserves macros that are still live after such processing.
This output can be consumed by a second compilation to produce a header unit.

We automatically invoke this (with -E) when we know that the job produces a
header unit so that the preprocessed output reflects the macros that will be
defined when the binary HU is emitted.

Diff Detail

Event Timeline

iains created this revision.Mar 14 2022, 4:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 14 2022, 4:21 AM
iains published this revision for review.Mar 14 2022, 4:34 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 14 2022, 4:34 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Oh, I found all the series of patches looks confusing to me. Maybe due to that I lack a use experience with header unit. I really couldn't judge if it is necessary or useful. Could you elaborate more end use cases? For example, I could understand the sentence:

Thus it preserves macros that are still live after such processing.
This output can be consumed by a second compilation to produce a header unit.

But where could it be useful? I think this is worth mentioning.


Note: After the 2 series of patches, I think it is necessary to edit the Release Note and the command line documents.

clang/test/Driver/cxx20-fdirectives-only.cpp
11

Maybe it's worth to add a test:

%clang++ -### -std=c++20 -fmodule-header=user foo.hh  2>&1

And check not for -fdirectives-only.

iains added a comment.Mar 16 2022, 3:48 AM

Oh, I found all the series of patches looks confusing to me. Maybe due to that I lack a use experience with header unit. I really couldn't judge if it is necessary or useful. Could you elaborate more end use cases? For example, I could understand the sentence:

Thus it preserves macros that are still live after such processing.
This output can be consumed by a second compilation to produce a header unit.

But where could it be useful? I think this is worth mentioning.

OK - I could but the uses of pre-processed output are not really novel to header units?

as I noted elsewhere:

  1. usually it is an aid to debugging / problem reporting (since the pre-processed output flattens included headers)
  2. in the case of a header unit, actually there could be a purpose in scanning the pre-processed output to determine the dependencies in force after directives have been processed.

Note: After the 2 series of patches, I think it is necessary to edit the Release Note and the command line documents.

Ah good catch, I forgot that _ will do an additional patch,

iains updated this revision to Diff 416856.Mar 21 2022, 1:42 AM

rebased.

urnathan accepted this revision.Mar 23 2022, 5:04 AM
This revision is now accepted and ready to land.Mar 23 2022, 5:04 AM
iains updated this revision to Diff 418274.Mar 25 2022, 10:51 AM

rebased, adjusted testcases to avoid using clang++.

This revision was landed with ongoing or failed builds.Apr 23 2022, 6:43 AM
This revision was automatically updated to reflect the committed changes.