[all-commits] [llvm/llvm-project] 8a3f9a: [C++20][Modules][1/8] Track valid import state.

iains via All-commits all-commits at lists.llvm.org
Sun Feb 20 02:14:29 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 8a3f9a584ad43369cf6a034dc875ebfca76d9033
      https://github.com/llvm/llvm-project/commit/8a3f9a584ad43369cf6a034dc875ebfca76d9033
  Author: Iain Sandoe <iain at sandoe.co.uk>
  Date:   2022-02-20 (Sun, 20 Feb 2022)

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

  Log Message:
  -----------
  [C++20][Modules][1/8] Track valid import state.

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.

Differential Revision: https://reviews.llvm.org/D118893




More information about the All-commits mailing list