This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by ZezhengLi on Feb 10 2022, 4:02 AM.

Details

Summary

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.

Diff Detail

Event Timeline

ZezhengLi requested review of this revision.Feb 10 2022, 4:02 AM
ZezhengLi created this revision.
ZezhengLi updated this revision to Diff 407466.Feb 10 2022, 4:06 AM

Add endline.

ZezhengLi edited the summary of this revision. (Show Details)Feb 10 2022, 4:08 AM
ZezhengLi edited the summary of this revision. (Show Details)
ZezhengLi edited the summary of this revision. (Show Details)Feb 10 2022, 4:16 AM
ChuanqiXu accepted this revision.Feb 10 2022, 5:54 PM

LGTM. It should be always good to avoid crash.

This revision is now accepted and ready to land.Feb 10 2022, 5:54 PM
ChuanqiXu closed this revision.Feb 10 2022, 7:29 PM