1# Copyright (C) 2002-2018 Free Software Foundation, Inc.
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with GCC; see the file COPYING3.  If not see
15# <http://www.gnu.org/licenses/>.
16
17# Please email any bugs, comments, and/or additions to this file to:
18# gcc-patches@gcc.gnu.org
19
20# Globals.
21
22global compat_use_alt
23global compat_same_alt
24global compat_have_dfp
25global compat_skip_list
26
27# This file defines procs for determining features supported by both C
28# compilers for compatibility tests.
29
30load_lib target-supports.exp
31load_lib target-libpath.exp
32
33#
34# compat-use-alt-compiler -- make the alternate compiler the default
35#
36proc compat-use-alt-compiler { } {
37    global GCC_UNDER_TEST ALT_CC_UNDER_TEST
38    global compat_same_alt compat_alt_caret compat_alt_color
39    global TEST_ALWAYS_FLAGS
40
41    # We don't need to do this if the alternate compiler is actually
42    # the same as the compiler under test.
43    if { $compat_same_alt == 0 } then {
44	set GCC_UNDER_TEST $ALT_CC_UNDER_TEST
45	if { $compat_alt_caret == 0 } then {
46	    regsub -- "-fno-diagnostics-show-caret" $TEST_ALWAYS_FLAGS "" TEST_ALWAYS_FLAGS
47	}
48	if { $compat_alt_color == 0 } then {
49	    regsub -- "-fdiagnostics-color=never" $TEST_ALWAYS_FLAGS "" TEST_ALWAYS_FLAGS
50	}
51	restore_gcc_exec_prefix_env_var
52    }
53}
54
55#
56# compat-use-tst-compiler -- make compiler under test the default
57#
58proc compat-use-tst-compiler { } {
59    global GCC_UNDER_TEST compat_save_gcc_under_test
60    global compat_same_alt
61    global TEST_ALWAYS_FLAGS compat_save_TEST_ALWAYS_FLAGS
62
63    # We don't need to do this if the alternate compiler is actually
64    # the same as the compiler under test.
65
66    if { $compat_same_alt == 0 } then {
67	set GCC_UNDER_TEST $compat_save_gcc_under_test
68	set TEST_ALWAYS_FLAGS $compat_save_TEST_ALWAYS_FLAGS
69	set_gcc_exec_prefix_env_var
70    }
71}
72
73# Find out whether both compilers support decimal float types.
74proc compat_setup_dfp { } {
75    global compat_use_alt
76    global compat_same_alt
77    global compat_have_dfp
78    global compat_alt_caret
79    global compat_alt_color
80    global TEST_ALWAYS_FLAGS compat_save_TEST_ALWAYS_FLAGS
81
82    set compat_alt_caret 0
83    set compat_alt_color 0
84    set compat_save_TEST_ALWAYS_FLAGS $TEST_ALWAYS_FLAGS
85
86    verbose "compat_setup_dfp: $compat_use_alt $compat_same_alt" 2
87
88    # Does the compiler under test support decimal float types?
89    compat-use-tst-compiler
90    set compat_have_dfp [check_effective_target_dfprt_nocache]
91    verbose "compat_have_dfp for tst compiler: $compat_have_dfp" 2
92
93    if { $compat_use_alt == 1 && $compat_same_alt == 0 } {
94	compat-use-alt-compiler
95	if { [check_no_compiler_messages_nocache compat_alt_has_caret object {
96		int dummy; } "-fno-diagnostics-show-caret"] != 0 } {
97	    set compat_alt_caret 1
98	}
99	if { [check_no_compiler_messages_nocache compat_alt_has_color object {
100		int dummy; } "-fdiagnostics-color=never"] != 0 } {
101	    set compat_alt_color 1
102	}
103	compat-use-tst-compiler
104    }
105
106    # If there is an alternate compiler, does it support decimal float types?
107    if { $compat_have_dfp == 1 && $compat_use_alt == 1 && $compat_same_alt == 0 } {
108	compat-use-alt-compiler
109	set compat_have_dfp [check_effective_target_dfprt_nocache]
110	compat-use-tst-compiler
111	verbose "compat_have_dfp for alt compiler: $compat_have_dfp" 2
112    }
113
114    # If decimal float is not supported, add it to the skip list, which
115    # affects code in the header files.
116    if { $compat_have_dfp == 0 } {
117	global compat_skip_list
118	lappend compat_skip_list "DECIMAL_FLOAT"
119    }
120}
121
122# If either compiler does not support decimal float types, skip this test.
123
124proc dg-require-compat-dfp { args } {
125    global compat_have_dfp
126    if { $compat_have_dfp == 0 } {
127	upvar dg-do-what dg-do-what
128	set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
129    }
130}
131