1# Tests for ms_abi to sysv_abi calls.
2# Copyright (C) 2016-2018 Free Software Foundation, Inc.
3# Contributed by Daniel Santos <daniel.santos@pobox.com>
4#
5# This file is part of GCC.
6#
7# GCC is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 3, or (at your option)
10# any later version.
11#
12# GCC is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# Under Section 7 of GPL version 3, you are granted additional
18# permissions described in the GCC Runtime Library Exception, version
19# 3.1, as published by the Free Software Foundation.
20#
21# You should have received a copy of the GNU General Public License and
22# a copy of the GCC Runtime Library Exception along with this program;
23# see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
24# <http://www.gnu.org/licenses/>.
25
26load_lib gcc-dg.exp
27
28proc host_supports_c++11 {} {
29    global HOSTCXX HOSTCXXFLAGS
30
31    set pidstr [pid]
32    set src "host_supports_c++11_$pidstr.C"
33    set asm "host_supports_c++11_$pidstr.s"
34
35    set f [open $src "w"]
36    puts $f ""
37    close $f
38
39    set cxx "$HOSTCXX $HOSTCXXFLAGS"
40
41    # Temporarily switch to the environment for the host compiler.
42    restore_ld_library_path_env_vars
43    set status [remote_exec host "$cxx -S $src -std=c++11 -o $asm"]
44    # And switch back.
45    set_ld_library_path_env_vars
46
47    file delete $src $asm
48
49    set status [lindex $status 0]
50    if { $status != 0 } {
51	return 0
52    }
53
54    return 1
55}
56
57# Exit immediately if this isn't a native x86_64 target.
58if { (![istarget x86_64-*-*] && ![istarget i?86-*-*])
59      || ![is-effective-target lp64] || ![isnative]
60      || ![host_supports_c++11] } then {
61
62    # Gate "unsupported" message return value of first runtest_file_p call.
63    if [runtest_file_p $runtests "$srcdir/$subdir/ms-sysv.c"] {
64	unsupported "$subdir"
65    }
66    return
67}
68
69proc runtest_ms_sysv { cflags generator_args } {
70    global GCC_UNDER_TEST HOSTCXX HOSTCXXFLAGS tmpdir srcdir subdir \
71	   TEST_ALWAYS_FLAGS runtests
72
73    set objdir "$tmpdir/ms-sysv"
74    set generator "$tmpdir/ms-sysv-generate.exe"
75    set generated_header "$objdir/ms-sysv-generated.h"
76    set status 0
77    set warn_flags "-Wall"
78
79    # Detect when hard frame pointers are enabled (or required) so we know not
80    # to generate bp clobbers.
81    if { [regexp "(^| )-(O0|fno-omit-frame-pointer|p|pg)( |$)" \
82		 "$TEST_ALWAYS_FLAGS $cflags" match]
83	 || [istarget *-*-solaris*] } then {
84	set generator_args "$generator_args --omit-rbp-clobbers"
85    }
86
87    # Add all other flags
88    set escaped_generator_args [regsub -all " " $generator_args "\\ "]
89    set cflags "$cflags\"-DGEN_ARGS=$escaped_generator_args\""
90
91    gcc_parallel_test_enable 1
92    if ![runtest_file_p $runtests "$srcdir/$subdir/ms-sysv.c"] then {
93	return
94    }
95
96    #verbose "runtest_ms_sysv $cflags" 0
97
98    # Make sure there's no previous header file so that we can't accidentally
99    # pass if generation fails.
100    file delete -force $generated_header
101
102    # Cleanup any previous test in objdir
103    file delete -force $objdir
104    file mkdir $objdir
105
106    # Build the generator (only needs to be done once).
107    set src "$srcdir/$subdir/gen.cc"
108    if { (![file exists "$generator"]) || ([file mtime "$generator"]
109					   < [file mtime "$src"]) } {
110	# Temporarily switch to the environment for the host compiler.
111	restore_ld_library_path_env_vars
112	set cxx "$HOSTCXX $HOSTCXXFLAGS $TEST_ALWAYS_FLAGS $warn_flags -std=c++11"
113	set status [remote_exec host "$cxx -o $generator $src"]
114	set status [lindex $status 0]
115	set_ld_library_path_env_vars
116	if { $status != 0 } then {
117	    warning "Could not build $subdir generator"
118	}
119    }
120
121    # Generate header
122    if { $status == 0 } then {
123	set status [remote_exec host "$generator $generator_args $generated_header"]
124	set status [lindex $status 0]
125	if { $status != 0 } then {
126	    warning "Could not generate $generated_header"
127	}
128    }
129
130    gcc_parallel_test_enable 0
131    dg-runtest $srcdir/$subdir/ms-sysv.c "$cflags" "-I$objdir -I$srcdir/$subdir $warn_flags"
132    gcc_parallel_test_enable 1
133}
134
135dg-init
136
137# Standard test parameters.
138set gen_pcount_opts [list "-p0" "-p1" "-p5"]
139set base_cflags_arr [list " -O2 " " -O0 -g3 "]
140
141foreach gen_opts $gen_pcount_opts {
142    foreach cflags $base_cflags_arr {
143	# Run without -mcall-ms2sysv-xlogues always
144	runtest_ms_sysv "$cflags" "$gen_opts"
145
146	# Skip unsupported -mcall-ms2sysv-xlogues on Windows
147	if { ![istarget *-*-cygwin*] && ![istarget *-*-mingw*] } {
148	    runtest_ms_sysv "-mcall-ms2sysv-xlogues$cflags" "$gen_opts"
149	}
150    }
151}
152
153dg-finish
154