https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126577
Bug ID: 126577
Summary: [16 Regression][modules] Corrupt CMI with
-fmodule-mapper, re-exported partition, chrono alias
and unique_ptr
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: Nico at martin dot li
Target Milestone: ---
Created attachment 65206
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=65206&action=edit
Minimal reproducible testcase
A freshly generated primary module CMI becomes unreadable with the attached
testcase.
The testcase contains:
* a module exporting an alias for `std::chrono::nanoseconds`;
* an interface partition importing that module and exporting a type containing
`std::unique_ptr`;
* a primary interface re-exporting the partition;
* a consumer importing the primary interface and constructing the exported
type.
This appears to be a GCC 16 regression. The testcase succeeds with GCC 16.1.0
but fails with GCC 16.1.1 revision `171d15ac6959`.
# Compiler information
Using built-in specs.
COLLECT_GCC=/usr/bin/g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/16/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure
--enable-languages=ada,c,c++,d,fortran,go,lto,m2,objc,obj-c++,rust,cobol
--enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib
--mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://gitlab.archlinux.org/archlinux/packaging/packages/gcc/-/issues
--with-build-config=bootstrap-lto --with-gcc-major-version-only
--with-linker-hash-style=gnu --with-system-zlib --enable-cet=auto
--enable-checking=release --enable-clocale=gnu --enable-default-pie
--enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object
--enable-libstdcxx-backtrace --enable-link-serialization=1
--enable-linker-build-id --enable-lto --enable-multilib --enable-plugin
--enable-shared --enable-threads=posix --disable-fixincludes --disable-libssp
--disable-libstdcxx-pch --disable-werror
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 16.1.1 20260728 (GCC)
The matching GCC and libstdc++ packages are:
gcc 16.1.1+r595+g171d15ac6959-1
libstdc++ 16.1.1+r595+g171d15ac6959-1
# Reproduction
Extract the attached testcase and run:
cmake -S . -B build -G Ninja \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_COMPILER=/usr/bin/g++
cmake --build build --verbose -j1
The three module interface units compile and fresh CMIs are generated.
Compilation of `main.cpp` then fails:
In module imported at main.cpp:1:1:
arc.chrono.consumer: In function ‘int main()’:
arc.chrono.consumer: error: failed to read compiled module cluster 1237: Bad
file data
arc.chrono.consumer: note: compiled module file is
‘CMakeFiles/chrono_cmi.dir/arc.chrono.consumer.gcm’
arc.chrono.consumer: error: failed to read compiled module cluster 1391: Bad
file data
arc.chrono.consumer: error: failed to read compiled module cluster 1393: Bad
file data
main.cpp: In destructor ‘virtual
__gnu_cxx::__concurrence_unlock_error::~__concurrence_unlock_error()’:
main.cpp:5:5: fatal error: failed to load pendings for
‘__gnu_cxx::__concurrence_unlock_error’
5 | ArcOwner owner;
| ^~~~~~~~
compilation terminated.
# Expected result
All translation units should compile and link successfully.
# Additional results
The testcase is compiled with `-Wall -Wextra -Wpedantic -Werror`. No source
warnings are emitted before the CMI read failure.
The failure is unchanged with:
-D_GLIBCXX_ASSERTIONS
-fno-strict-aliasing -fwrapv -fno-aggressive-loop-optimizations
The testcase succeeds with `-D_GLIBCXX_DEBUG`.
The same project succeeds with GCC 16.1.0. GCC 16.1.1 continues to fail when
using a different CMake and Ninja installation, while GCC 16.1.0 succeeds with
the CMake and Ninja versions used by the failing build.
Compiling the same source files directly with GCC's default gcm.cache mapping
succeeds too. The failure occurs when GCC uses the explicit module mapper and
CMI
paths generated by CMake.
Possibly related: PR125635 and PR125144, which produce similar `Bad file data`
and `failed to load pendings` diagnostics but have different reduced testcases.
CMakeLists.txt
cmake_minimum_required(VERSION 4.0)
project(chrono_cmi_repro LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
add_library(chrono_cmi STATIC)
target_sources(
chrono_cmi
PUBLIC
FILE_SET CXX_MODULES
FILES
core.cppm
owner.cppm
primary.cppm
)
target_compile_options(
chrono_cmi
PRIVATE
-Wall
-Wextra
-Wpedantic
-Werror
)
add_executable(consumer main.cpp)
target_link_libraries(consumer PRIVATE chrono_cmi)
target_compile_options(
consumer
PRIVATE
-Wall
-Wextra
-Wpedantic
-Werror
)
core.cppm
module;
#include <chrono>
export module arc.chrono.consumer.core;
export using ArcDuration = std::chrono::nanoseconds;
owner.cppm
module;
#include <memory>
export module arc.chrono.consumer:owner;
import arc.chrono.consumer.core;
export struct ArcOwner {
std::unique_ptr<int> value{};
};
primary.cppm
export module arc.chrono.consumer;
export import :owner;
main.cpp
import arc.chrono.consumer;
int main()
{
ArcOwner owner;
return owner.value ? 1 : 0;
}