]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/complex-parts.exp
Prevent use-after-free of bfd filename in gdb_bfd_close_or_warn
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / complex-parts.exp
CommitLineData
1d506c26 1# Copyright 2019-2024 Free Software Foundation, Inc.
8bdc1658
AB
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 this program. If not, see <http://www.gnu.org/licenses/>.
15
16standard_testfile
17
18if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
19 return -1
20}
21
65a33d75 22if {![runto_main]} {
8bdc1658
AB
23 return 0
24}
25
b6a5604d
TV
26set marker " Break Here. "
27gdb_breakpoint [gdb_get_line_number $marker]
28gdb_continue_to_breakpoint "breakpt" ".*[string_to_regexp $marker].*"
8bdc1658 29
b6a5604d
TV
30gdb_test "p z1" [string_to_regexp " = 1.5 + 4.5i"]
31gdb_test "p z2" [string_to_regexp " = 2.5 + -5.5i"]
32gdb_test "p z3" [string_to_regexp " = 3.5 + 6.5i"]
8bdc1658 33
fbdc50d2
BL
34# The following 3 tests are broken for Clang.
35# More info at https://github.com/llvm/llvm-project/issues/52996.
36if {[test_compiler_info clang-*-*]} { setup_xfail *-*-* }
8bdc1658 37gdb_test "ptype z1" " = complex double"
fbdc50d2 38if {[test_compiler_info clang-*-*]} { setup_xfail *-*-* }
8bdc1658 39gdb_test "ptype z2" " = complex float"
fbdc50d2 40if {[test_compiler_info clang-*-*]} { setup_xfail *-*-* }
8bdc1658
AB
41gdb_test "ptype z3" " = complex long double"
42
c2b75043 43with_test_prefix "double imaginary" {
75ece951
TV
44 set expr {$_cimag (z1)}
45 gdb_test "p $expr" " = 4.5"
b6a5604d 46 gdb_test {ptype $} " = double"
75ece951 47 gdb_test "ptype $expr" " = double"
c2b75043 48}
8bdc1658 49
c2b75043 50with_test_prefix "float imaginary" {
75ece951
TV
51 set expr {$_cimag (z2)}
52 gdb_test "p $expr" " = -5.5"
b6a5604d 53 gdb_test {ptype $} " = float"
75ece951 54 gdb_test "ptype $expr" " = float"
c2b75043 55}
8bdc1658 56
c2b75043 57with_test_prefix "long double imaginary" {
75ece951
TV
58 set expr {$_cimag (z3)}
59 gdb_test "p $expr" " = 6.5"
b6a5604d 60 gdb_test {ptype $} " = long double"
75ece951 61 gdb_test "ptype $expr" " = long double"
c2b75043 62}
8bdc1658 63
c2b75043 64with_test_prefix "double real" {
75ece951
TV
65 set expr {$_creal (z1)}
66 gdb_test "p $expr" " = 1.5"
b6a5604d 67 gdb_test {ptype $} " = double"
75ece951 68 gdb_test "ptype $expr" " = double"
c2b75043 69}
8bdc1658 70
c2b75043 71with_test_prefix "float real" {
75ece951
TV
72 set expr {$_creal (z2)}
73 gdb_test "p $expr" " = 2.5"
b6a5604d 74 gdb_test {ptype $} " = float"
75ece951 75 gdb_test "ptype $expr" " = float"
c2b75043 76}
8bdc1658 77
c2b75043 78with_test_prefix "long double real" {
75ece951
TV
79 set expr {$_creal (z3)}
80 gdb_test "p $expr" " = 3.5"
b6a5604d 81 gdb_test {ptype $} " = long double"
75ece951 82 gdb_test "ptype $expr" " = long double"
c2b75043 83}
8bdc1658 84
b6a5604d
TV
85gdb_test {p $_cimag (d1)} "expected a complex number"
86gdb_test {p $_cimag (f1)} "expected a complex number"
87gdb_test {p $_cimag (i1)} "expected a complex number"
8bdc1658 88
b6a5604d
TV
89gdb_test {p $_creal (d1)} "expected a complex number"
90gdb_test {p $_creal (f1)} "expected a complex number"
91gdb_test {p $_creal (i1)} "expected a complex number"
c34e8714
TT
92
93#
94# General complex number tests.
95#
96
b6a5604d
TV
97gdb_test "print 23 + 7i" [string_to_regexp " = 23 + 7i"]
98gdb_test "print 23.125f + 7i" [string_to_regexp " = 23.125 + 7i"]
99gdb_test "print 23 + 7.25fi" [string_to_regexp " = 23 + 7.25i"]
100gdb_test "print (23 + 7i) + (17 + 10i)" [string_to_regexp " = 40 + 17i"]
101gdb_test "print 23 + -7i" [string_to_regexp " = 23 + -7i"]
102gdb_test "print 23 - 7i" [string_to_regexp " = 23 + -7i"]
c34e8714 103
b6a5604d
TV
104gdb_test "print -(23 + 7i)" [string_to_regexp " = -23 + -7i"]
105gdb_test "print +(23 + 7i)" [string_to_regexp " = 23 + 7i"]
106gdb_test "print ~(23 + 7i)" [string_to_regexp " = 23 + -7i"]
c34e8714 107
b6a5604d 108gdb_test "print (5 + 5i) * (2 + 2i)" [string_to_regexp " = 0 + 20i"]
c34e8714
TT
109
110gdb_test "print (5 + 7i) == (5 + 7i)" " = 1"
111gdb_test "print (5 + 7i) == (8 + 7i)" " = 0"
112gdb_test "print (5 + 7i) == (5 + 92i)" " = 0"
113gdb_test "print (5 + 7i) != (5 + 7i)" " = 0"
114gdb_test "print (5 + 7i) != (8 + 7i)" " = 1"
115gdb_test "print (5 + 7i) != (5 + 92i)" " = 1"
116
b6a5604d 117gdb_test "print (20 - 4i) / (3 + 2i)" [string_to_regexp " = 4 + -4i"]
3638a098 118
b6a5604d
TV
119gdb_test "print (_Complex int) 4" [string_to_regexp " = 4 + 0i"]
120gdb_test "print (_Complex float) 4.5" [string_to_regexp " = 4.5 + 0i"]
3638a098 121gdb_test "ptype __complex__ short" " = _Complex short"
b6a5604d 122gdb_test "print (_Complex int) (23.75 + 8.88i)" [string_to_regexp " = 23 + 8i"]
ae710496 123
b6a5604d
TV
124set re_reject_arg \
125 [string_to_regexp \
126 "Argument to complex arithmetic operation not supported."]
ae710496
TV
127gdb_test "print (void *)0 + 5i" $re_reject_arg
128gdb_test "print (_Decimal32)0 + 5i" $re_reject_arg
129
130# Set language to c++. Avoid warning by not having current frame.
131clean_restart
132gdb_test_no_output "set language c++"
133
134# C++ type tests.
b6a5604d 135gdb_test "print (bool)1 + 1i" [string_to_regexp "= 1 + 1i"]