[PATCH] D118893: [C++20][Modules] Track valid import state.

Iain Sandoe via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 15 08:26:53 PST 2022


iains created this revision.
iains updated this revision to Diff 408755.
iains added a comment.
iains added reviewers: rsmith, urnathan, ChuanqiXu.
iains updated this revision to Diff 408803.
iains published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Rebased onto other modules work.


iains added a comment.

repushing the rebase with clang-format available.


iains added a comment.

This is the first in a series of 8 patches to implement basic C++20 module partition support in clang.   This is an enabler, particularly in forming diagnostics.


In C++20 modules imports must be together and at the start of the module.
Rather than growing more ad-hoc flags to test state, this keeps track of the
phase of of a valid module TU (first decl, global module frag, module,
private module frag).  If the phasing is broken (with some diagnostic) the
pattern does not conform to a valid C++20 module, and we set the state
accordingly.

We can thus issue diagnostics when imports appear in the wrong places and
decouple the C++20 modules state from other module variants (modules-ts and
clang modules).  Additionally, we attempt to diagnose wrong imports before
trying to find the module where possible (the latter will generally emit an
unhelpful diagnostic about the module not being available).

Although this generally simplifies the handling of C++20 module import
diagnostics, the motivation was that, in particular, it allows detecting
invalid imports like:

import module A;

int some_decl();

import module B;

where being in a module purview is insufficient to identify them.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118893

Files:
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Parse/ParseAST.cpp
  clang/lib/Parse/ParseObjc.cpp
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/SemaModule.cpp
  clang/test/Modules/cxx20-import-diagnostics-a.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118893.408803.patch
Type: text/x-patch
Size: 20834 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220215/00ae8e5d/attachment-0001.bin>


More information about the cfe-commits mailing list