From: Jason Merrill Date: Wed, 10 Dec 2025 09:32:59 +0000 (+0800) Subject: c++: clean up gcms from compile-std1.C X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=23d71494fe0a6244b870db5a4f879b528903f52c;p=thirdparty%2Fgcc.git c++: clean up gcms from compile-std1.C I noticed that the .gcms from compile-std1.C were sticking around and confusing other tests; this patch enhances dg-module-cmi to understand
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. --- diff --git a/gcc/testsuite/g++.dg/modules/compile-std1.C b/gcc/testsuite/g++.dg/modules/compile-std1.C index a7972be33c1..a03a87569a8 100644 --- a/gcc/testsuite/g++.dg/modules/compile-std1.C +++ b/gcc/testsuite/g++.dg/modules/compile-std1.C @@ -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 } import ; import std; diff --git a/gcc/testsuite/g++.dg/modules/modules.exp b/gcc/testsuite/g++.dg/modules/modules.exp index 3f2b8f2d576..695bbe62aa2 100644 --- a/gcc/testsuite/g++.dg/modules/modules.exp +++ b/gcc/testsuite/g++.dg/modules/modules.exp @@ -54,6 +54,43 @@ global module_cmis set DEFAULT_REPO "gcm.cache" +# Return the pathname for . +# On failure this will return garbage that results in the understandable +# FAIL: g++.dg/modules/compile-std1.C module-cmi (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" }