]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: clean up gcms from compile-std1.C
authorJason Merrill <jason@redhat.com>
Wed, 10 Dec 2025 09:32:59 +0000 (17:32 +0800)
committerJason Merrill <jason@redhat.com>
Wed, 10 Dec 2025 14:27:28 +0000 (22:27 +0800)
I noticed that the .gcms from compile-std1.C were sticking around and
confusing other tests; this patch enhances dg-module-cmi to understand
<header> and adds the appropriate directives to the test.

gcc/testsuite/ChangeLog:

* g++.dg/modules/compile-std1.C: Add dg-module-cmi lines.
* g++.dg/modules/modules.exp (host_header_path): New.
(munge_cmi): Factor out...
(dg-module-cmi): ...from here.

gcc/testsuite/g++.dg/modules/compile-std1.C
gcc/testsuite/g++.dg/modules/modules.exp

index a7972be33c1b516dca3d5d15f906add36d072ee6..a03a87569a89012b9d27dccaab5b7ac634f349b5 100644 (file)
@@ -1,5 +1,8 @@
 // { dg-additional-options "-fmodules --compile-std-module -g -O" }
 // { dg-do compile { target c++20 } }
+// { dg-module-cmi std }
+// { dg-module-cmi std.compat }
+// { dg-module-cmi <bits/stdc++.h> }
 
 import <bits/stdc++.h>;
 import std;
index 3f2b8f2d57647339ef87e1a32c8875bb3e984c1e..695bbe62aa25486e9294afe0da9653443c0f6741 100644 (file)
@@ -54,6 +54,43 @@ global module_cmis
 
 set DEFAULT_REPO "gcm.cache"
 
+# Return the pathname for <HNAME>.
+# On failure this will return garbage that results in the understandable
+# FAIL: g++.dg/modules/compile-std1.C module-cmi <bits/stdcx++.h> (gcm.cache/,/ader_path1095619.C:1:10: fatal error: bits/stdcx++.h: No such file or directory.gcm)
+# ??? it would be nice to have a simple --print-include-name flag.
+proc host_header_path {hname} {
+    global tool
+    set src header_path[pid].C
+    set f [open $src "w"]
+    puts $f "#include <$hname>"
+    close $f
+    set opts [list "additional_flags=-H" "additional_flags=-fdirectives-only"]
+    set lines [${tool}_target_compile $src /dev/null preprocess $opts]
+    file delete $f
+    # The first line of the -H output is ". /path/to/hname"
+    set newline_idx [expr {[string first "\n" $lines] - 1}]
+    set path [string range $lines 2 $newline_idx]
+    verbose "header_path: $path" 1
+    return $path
+}
+
+# Return the pathname CMI munged like the compiler.
+proc munge_cmi {cmi} {
+    if { [string index $cmi 0] == "/" } {
+       set cmi [string range $cmi 1 end]
+    } else {
+       set cmi ",/$cmi"
+    }
+    set path [file split $cmi]
+    # subst /../ -> /,,/
+    # sadly tcl 8.5 does not have lmap
+    set rplac {}
+    foreach elt $path {lappend rplac [expr {$elt == ".." ? ",," : $elt}]}
+    set cmi [file join {*}$rplac]
+    verbose "munge_cmi: $cmi" 1
+    return $cmi
+}
+
 # Register the module name this produces.
 # dg-module-cmi !?=?NAME WHEN?
 # dg-module-cmi !?{} - header unit
@@ -83,18 +120,11 @@ proc dg-module-cmi { args } {
        if { $name == "" } {
            # get the source file name.  ick!
            upvar prog srcname
-           set cmi "$srcname.gcm"
-           if { [string index $cmi 0] == "/" } {
-               set cmi [string range $cmi 1 end]
-           } else {
-               set cmi ",/$cmi"
-           }
-           set path [file split $cmi]
-           # subst /../ -> /,,/
-           # sadly tcl 8.5 does not have lmap
-           set rplac {}
-           foreach elt $path {lappend rplac [expr {$elt == ".." ? ",," : $elt}]}
-           set cmi [file join {*}$rplac]
+           set cmi [munge_cmi "$srcname.gcm"]
+       } elseif { [string index $name 0] == "<"
+                  && [string index $name end] == ">" } {
+           set header "[regsub {<(.*)>} $name {\1}]"
+           set cmi [munge_cmi "[host_header_path $header].gcm"]
        } else {
            set cmi "[regsub : $name -].gcm"
        }