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

iains via All-commits all-commits at lists.llvm.org
Mon Feb 21 01:10:02 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: ab28488efe6de6f8fa856a1dfd8c0320d41d7608
      https://github.com/llvm/llvm-project/commit/ab28488efe6de6f8fa856a1dfd8c0320d41d7608
  Author: Iain Sandoe <iain at sandoe.co.uk>
  Date:   2022-02-21 (Mon, 21 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
    M lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.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