[all-commits] [llvm/llvm-project] d79690: [C++20] [Modules] Check if modulemap exists to avo...

Chuanqi Xu via All-commits all-commits at lists.llvm.org
Thu Feb 10 19:23:56 PST 2022

  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: d7969012e40a0906512b5bb304fc8b245386bb15
  Author: ZezhengLi <Zezheng.Li at linux.alibaba.com>
  Date:   2022-02-11 (Fri, 11 Feb 2022)

  Changed paths:
    M clang/lib/Lex/HeaderSearch.cpp
    A clang/test/Modules/implicit-module-with-missing-path.cpp

  Log Message:
  [C++20] [Modules] Check if modulemap exists to avoid crash in implicit used C++ module

An impilt used of C++ module without prebuild path may cause crash.

For example:

// ./dir1/C.cppm
export module C;
// ./dir2/B.cppm
export module B;
import C;
// ./A.cpp
import B;
import C;

When we compile A.cpp without the prebuild path of C.pcm, the compiler
will crash.

clang++ -std=c++20 --precompile -c ./dir1/C.cppm -o ./dir1/C.pcm
clang++ -std=c++20 --precompile -fprebuilt-module-path=./dir2  -c
./dir2/B.cppm -o ./dir2/B.pcm
clang++ -std=c++20 -fprebuilt-module-path=./dir2 A.cpp


The prebuilt path of module C is cached when import module B, and in the
function HeaderSearch::getCachedModuleFileName, the compiler try to get
the filename by modulemap without check if modulemap exists, and there
is no modulemap in C++ module.

Reviewed By: ChuanqiXu

Differential review: https://reviews.llvm.org/D119426

More information about the All-commits mailing list