]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++, libstdc++: add "modules" std to testsuite
authorJason Merrill <jason@redhat.com>
Thu, 11 Dec 2025 16:31:18 +0000 (23:31 +0700)
committerJason Merrill <jason@redhat.com>
Thu, 11 Dec 2025 16:31:18 +0000 (23:31 +0700)
Since modules aren't enabled by default at any -std= yet, let's add a
pseudo-std for them, like we already have for -fimplicit-constexpr.  And
also add to target-supports so dg lines can check { target modules }.

To run library tests with modules we need to compile them; this patch makes
us build a header unit for bits/stdc++.h and module interface units for std
and std.compat, if v3_std_list includes "modules".  So this doesn't happen
by default without a further change.

libstdc++-v3/ChangeLog:

* testsuite/Makefile.am (CLEANFILES): Add gcm.cache.
* testsuite/Makefile.in: Regenerate.
* testsuite/lib/dg-options.exp (add_options_for_no_pch): Also add
-fno-modules.
* testsuite/lib/libstdc++.exp (v3_std_list): Handle "modules" std.
(v3_modules_std): New global.
(v3-build_support): Build gcms for bits/stdc++.h, std, and
std.compat.

gcc/testsuite/ChangeLog:

* lib/g++-dg.exp: Handle "modules" std.
* lib/target-supports.exp (check_effective_target_modules): New.

gcc/testsuite/lib/g++-dg.exp
gcc/testsuite/lib/target-supports.exp
libstdc++-v3/testsuite/Makefile.am
libstdc++-v3/testsuite/Makefile.in
libstdc++-v3/testsuite/lib/dg-options.exp
libstdc++-v3/testsuite/lib/libstdc++.exp

index abecd8877c308615c5e668b09be2c1b08123c00d..f1e79fa27f0d7130fb1c5708dee2961a9ab3ff94 100644 (file)
@@ -92,6 +92,7 @@ proc g++-std-flags { test } {
        set option_list { }
        foreach x $std_list {
            if { $x eq "impcx" } then { set x "26 -fimplicit-constexpr" }
+           if { $x eq "modules" } then { set x "26 -fmodules -flang-info-include-translate" }
            lappend option_list "${std_prefix}$x"
        }
     } else {
index 6251f4e58f86fdceeca920f88034b0f6410c0dba..d3752e3ca07260e8923da6bc2b843b4071ab7a78 100644 (file)
@@ -12348,6 +12348,10 @@ proc check_effective_target_implicit_constexpr { } {
     return [check-flags { "" { } { -fimplicit-constexpr } }]
 }
 
+proc check_effective_target_modules { } {
+    return [check-flags { "" { } { -fmodules } }]
+}
+
 # Return 1 if expensive testcases should be run.
 
 proc check_effective_target_run_expensive_tests { } {
index 7754ab60003d0212838d33c554043d8768eec971..47014564196eb63958dc3d9741dcf6968f81a431 100644 (file)
@@ -247,7 +247,7 @@ check-performance-parallel: testsuite_files_performance ${performance_script}
 # By adding these files here, automake will remove them for 'make clean'
 CLEANFILES = *.txt *.tst *.exe core* filebuf_* tmp* ostream_* *.log *.sum \
             testsuite_* site.exp abi_check baseline_symbols *TEST* *.dat \
-            *.ii *.s *.o *.cc *.x *.a *.so *.xml *.raw *.out *.gdb
+            *.ii *.s *.o *.cc *.x *.a *.so *.xml *.raw *.out *.gdb gcm.cache
 
 # To remove directories.
 clean-local:
index c3693b6a56c957267742fc6c135dda5a8a6edf7e..65ec4e7fb146296bc180e64c0394605d380b9728 100644 (file)
@@ -435,7 +435,7 @@ parallel_flags = "unix/-D_GLIBCXX_PARALLEL/-fopenmp"
 # By adding these files here, automake will remove them for 'make clean'
 CLEANFILES = *.txt *.tst *.exe core* filebuf_* tmp* ostream_* *.log *.sum \
             testsuite_* site.exp abi_check baseline_symbols *TEST* *.dat \
-            *.ii *.s *.o *.cc *.x *.a *.so *.xml *.raw *.out *.gdb
+            *.ii *.s *.o *.cc *.x *.a *.so *.xml *.raw *.out *.gdb gcm.cache
 
 all: all-am
 
index 937a8224756e845bde51405239287f795b360e92..337f3502629fc7d5a5c614c8eb6ee4f039431f0e 100644 (file)
@@ -290,7 +290,7 @@ proc add_options_for_no_pch { flags } {
     # Remove any inclusion of bits/stdc++.h from the options.
     regsub -all -- "-include bits/stdc...h" $flags "" flags
     # This forces any generated and possibly included PCH to be invalid.
-    return "$flags -D__GLIBCXX__=99999999"
+    return "$flags -fno-modules -D__GLIBCXX__=99999999"
 }
 
 # Add to FLAGS all the target-specific flags needed for networking.
index 9f2dd8a1724856af94bc79eaf74217f9d0e8f9a4..b1593e42f94199e65306ac431acaef8cfeafbc5c 100644 (file)
@@ -496,10 +496,16 @@ if [info exists env(GLIBCXX_TESTSUITE_STDS)] {
     set v3_std_list [split $env(GLIBCXX_TESTSUITE_STDS) ","]
 }
 
+# Allow adjusting which -std we test with -fmodules.
+if ![info exists v3_modules_std] {
+    set v3_modules_std "26"
+}
+
 # Modified dg-runtest that runs tests in multiple standard modes,
 # unless they specifically specify one standard.
 proc v3-dg-runtest { testcases flags default-extra-flags } {
     global runtests
+    global v3_modules_std
 
     foreach test $testcases {
        # If we're only testing specific files and this isn't one of them, skip it.
@@ -546,6 +552,7 @@ proc v3-dg-runtest { testcases flags default-extra-flags } {
            set option_list { }
            foreach x $std_list {
                if { $x eq "impcx" } then { set x "26 -fimplicit-constexpr" }
+               if { $x eq "modules" } then { set x "$v3_modules_std -fmodules -flang-info-include-translate" }
                lappend option_list "${std_prefix}$x"
            }
        } else {
@@ -739,6 +746,7 @@ proc v3_target_compile_as_c { source dest type options } {
 proc v3-build_support { } {
     global env
     global srcdir
+    global blddir
     global v3-wchar_t
     global v3-threads
     global v3-symver
@@ -748,6 +756,7 @@ proc v3-build_support { } {
     set v3-wchar_t 0
     set v3-threads 0
     set v3-symver 0
+    set v3-modules 0
     set libtest_objs ""
 
     set config_src "config.cc"
@@ -787,6 +796,37 @@ proc v3-build_support { } {
        }
     }
 
+    global v3_std_list
+    global v3_modules_std
+    if { "modules" in $v3_std_list } {
+       verbose -log "modules testing requested"
+       set v3-modules 1
+    }
+
+    # If we're doing modules testing, compile module std, std.compat, and the
+    # bits/stdc++.h header unit.
+    if { ${v3-modules} == 1 } {
+       set std_file "$blddir/include/bits/std.cc"
+       set std_compat_file "$blddir/include/bits/std.compat.cc"
+
+       if { ([v3_target_compile bits/stdc++.h /dev/null object \
+                  [list "additional_flags=-std=gnu++$v3_modules_std -fmodules -g -w -fsearch-include-path"]]
+             != "") } {
+           error "could not compile bits/stdc++.h"
+       }
+       if { ([v3_target_compile $std_file std.o object \
+                  [list "additional_flags=-std=gnu++$v3_modules_std -fmodules -g -w"]]
+             != "") } {
+           error "could not compile std.cc"
+       }
+       if { ([v3_target_compile $std_compat_file std.compat.o object \
+                  [list "additional_flags=-std=gnu++$v3_modules_std -fmodules -g -w"]]
+             != "") } {
+           error "could not compile std.compat.cc"
+       }
+       append libtest_objs "std.o std.compat.o "
+    }
+
     # Build the support objects.
     set source_files [list testsuite_abi.cc testsuite_allocator.cc \
                          testsuite_character.cc testsuite_hooks.cc \