C++20 Non-modular files compiled with no dependency information when compiling with modules enabled
Edit: Reduced version of bug is at #25311 (comment 1427004)
Original Description
I have not reduced this bug, but you can see the issue by trying to compile https://github.com/davidstone/bounded-integer
To reproduce, the project can be built against clang 17 with
git submodule update --init
cmake -B build -G"Ninja" -DCMAKE_CXX_COMPILER="clang++"
cmake --build build
This project has some dependencies. Each of the non-modular source files of those dependencies are compiled once per library that is linked to the target containing that source file, rather than once total, and each of the unnecessary extra steps are compiled without proper dependency information of their own. For example, I have a file returns.cpp
that is part of the operators
library. The bounded
library target depends on the operators
library target, as does the bounded_test
executable target. When attempting to compile this project, I see output like:
[9/792] Building CXX object CMakeFiles/bounded.dir/dependencies/operators/source/operators/returns.cpp.o
FAILED: CMakeFiles/bounded.dir/dependencies/operators/source/operators/returns.cpp.o
llvm/build/bin/clang++ -Ibounded-integer/include -Ibounded-integer/dependencies/numeric-traits/include -Ibounded-integer/dependencies/std_module/include -Ibounded-integer/dependencies/operators/include -fdiagnostics-color=always -ftemplate-backtrace-limit=0 -fconstexpr-backtrace-limit=0 -ftime-trace -g -std=c++26 -Weverything -Werror -Wno-c++20-compat -Wno-c++20-extensions -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-ctad-maybe-unsupported -Wno-documentation -Wno-float-equal -Wno-for-loop-analysis -Wno-missing-braces -Wno-missing-prototypes -Wno-missing-variable-declarations -Wno-newline-eof -Wno-padded -Wno-range-loop-analysis -Wno-read-modules-implicitly -Wno-switch-enum -Wno-unneeded-member-function -Wno-unused-member-function -Wno-unused-function -Wno-unused-template -Wno-unsafe-buffer-usage -Wno-weak-vtables -Wno-zero-as-null-pointer-constant -g -fsanitize=address -fsanitize=undefined -MD -MT CMakeFiles/bounded.dir/dependencies/operators/source/operators/returns.cpp.o -MF CMakeFiles/bounded.dir/dependencies/operators/source/operators/returns.cpp.o.d -o CMakeFiles/bounded.dir/dependencies/operators/source/operators/returns.cpp.o -c bounded-integer/dependencies/operators/source/operators/returns.cpp
bounded-integer/dependencies/operators/source/operators/returns.cpp:8:8: fatal error: module 'std_module' not found
8 | import std_module;
| ~~~~~~~^~~~~~~~~~
1 error generated.
[73/792] Building CXX object CMakeFiles/bounded_test.dir/dependencies/operators/source/operators/returns.cpp.o
FAILED: CMakeFiles/bounded_test.dir/dependencies/operators/source/operators/returns.cpp.o
llvm/build/bin/clang++ -Ibounded-integer/dependencies/Catch2/src/catch2/.. -Ibounded-integer/build/debug/dependencies/Catch2/generated-includes -Ibounded-integer/include -Ibounded-integer/dependencies/numeric-traits/include -Ibounded-integer/dependencies/std_module/include -Ibounded-integer/dependencies/operators/include -fdiagnostics-color=always -ftemplate-backtrace-limit=0 -fconstexpr-backtrace-limit=0 -ftime-trace -g -std=c++26 -Weverything -Werror -Wno-c++20-compat -Wno-c++20-extensions -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-ctad-maybe-unsupported -Wno-documentation -Wno-float-equal -Wno-for-loop-analysis -Wno-missing-braces -Wno-missing-prototypes -Wno-missing-variable-declarations -Wno-newline-eof -Wno-padded -Wno-range-loop-analysis -Wno-read-modules-implicitly -Wno-switch-enum -Wno-unneeded-member-function -Wno-unused-member-function -Wno-unused-function -Wno-unused-template -Wno-unsafe-buffer-usage -Wno-weak-vtables -Wno-zero-as-null-pointer-constant -g -fsanitize=address -fsanitize=undefined -MD -MT CMakeFiles/bounded_test.dir/dependencies/operators/source/operators/returns.cpp.o -MF CMakeFiles/bounded_test.dir/dependencies/operators/source/operators/returns.cpp.o.d -o CMakeFiles/bounded_test.dir/dependencies/operators/source/operators/returns.cpp.o -c bounded-integer/dependencies/operators/source/operators/returns.cpp
bounded-integer/dependencies/operators/source/operators/returns.cpp:8:8: fatal error: module 'std_module' not found
8 | import std_module;
| ~~~~~~~^~~~~~~~~~
1 error generated.
Note the lack of a modmap
file in the command line and the multiple attempts to compile the same file.
This project builds with cmake 3.27.7, 3.27.8, and cmake main from a few weeks ago (not sure exactly which main commit I was using that was working), but fails with current main.