1 # Copyright 1998-2024 Free Software Foundation, Inc.
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.
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.
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/>.
16 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
17 # Rewritten to use gdb_test by Michael Chastain (chastain@redhat.com)
19 # This file is part of the gdb testsuite
21 # tests for correctness of arithmetic operators, associativity and precedence
22 # with integer type variables
26 # test running programs
29 standard_testfile int-type.c
31 if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug nowarnings}]} {
37 # set it up at a breakpoint so we can play with the variable values
45 # test expressions with "int" types
48 gdb_test_no_output "set variable x=14"
49 gdb_test_no_output "set variable y=2"
50 gdb_test_no_output "set variable z=2"
51 gdb_test_no_output "set variable w=3"
53 gdb_test "print x" "14"
54 gdb_test "print y" "2"
55 gdb_test "print z" "2"
56 gdb_test "print w" "3"
58 gdb_test "print x+y" "16"
59 gdb_test "print x-y" "12"
60 gdb_test "print x*y" "28"
61 gdb_test "print x/y" "7"
62 gdb_test "print x%y" "0"
67 # Test associativity of +, -, *, % ,/
69 gdb_test "print x+y+z" "18"
70 gdb_test "print x-y-z" "10"
71 gdb_test "print x*y*z" "56"
72 gdb_test "print x/y/z" "3"
73 gdb_test "print x%y%z" "0"
75 # test precedence rules on pairs of arithmetic operators
77 gdb_test_no_output "set variable x=10"
78 gdb_test_no_output "set variable y=4"
83 gdb_test "print x+y-z" "12"
84 gdb_test "print x+y*z" "18"
85 gdb_test "print x+y%w" "11"
86 gdb_test "print x+y/w" "11"
87 gdb_test "print x-y*z" "2"
88 gdb_test "print x-y%z" "10"
89 gdb_test "print x-y/z" "8"
90 gdb_test "print x*y/z" "20"
91 gdb_test "print x*y%w" "1"
92 gdb_test "print x/y%w" "2"
94 # test use of parentheses to enforce different order of evaluation
96 gdb_test "print x-(y+w)" "3"
97 gdb_test "print x/(y*w)" "0"
98 gdb_test "print x-(y/w)" "9"
99 gdb_test "print (x+y)*w" "42"
101 gdb_test "p /x -(-0x7fffffffffffffff - 1)" " = 0x8000000000000000"