This is the mail archive of the mailing list for the GDB project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: [PATCH 05/10] vla: allow side effects for sizeof argument

> -----Original Message-----
> From: Pedro Alves []
> Sent: Tuesday, November 19, 2013 06:06 PM
> To: Agovic, Sanimir
> Cc: 'Tom Tromey';
> Subject: Re: [PATCH 05/10] vla: allow side effects for sizeof argument
> On 11/18/2013 08:39 AM, Agovic, Sanimir wrote:
> >
> > It turns out this patch is not needed anymore as the bounds are resolved
> > before the sizeof function is called. So in v2 this patch will be dropped
> > from the series.
> >
> >> >     (gdb) print sizeof (array[x++])
> >> >
> >> > For an ordinary array this should not modify x.
> > Indeed, that is the behavior we have now in HEAD@vla-c99.
> Sounds like something that the testsuite should have caught.
> I guess we don't have such a test?
No yet, see below.

test: test eval routines with EVAL_AVOID_SIDE_EFFECTS flag set

Ensure that certain commands (e.g. whatis/ptype) and sizeof intrinsic
have no side effects (variables cannot be altered).

2013-11-20  Sanimir Agovic  <>

	* gdb.base/eval-avoid-side-effects.exp: New test.

diff --git a/gdb/testsuite/gdb.base/eval-avoid-side-effects.exp b/gdb/testsuite/gdb.base/eval-avoid-side-effects.exp
new file mode 100644
index 0000000..da1e36f
--- /dev/null
+++ b/gdb/testsuite/gdb.base/eval-avoid-side-effects.exp
@@ -0,0 +1,40 @@
+# Copyright 2013 Free Software Foundation, Inc.
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# GNU General Public License for more details.
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <>.
+# Tests to cover evaluate_subexp and others with EVAL_AVOID_SIDE_EFFECTS
+# flag set.
+standard_testfile int-type.c
+if { [prepare_for_testing ${testfile}.exp $testfile $srcfile] } {
+    return -1
+if ![runto_main] {
+    return -1
+set sizeof_int [get_sizeof "int" 4]
+gdb_test_no_output "set variable x=42" "set variable x=42"
+gdb_test "print sizeof ++x" "= ${sizeof_int}" "test sizeof side effects"
+gdb_test "print x" "= 42" "sizeof has no side effects"
+gdb_test "ptype ++x" "= int" "test ptype side effects"
+gdb_test "print x" "= 42" "ptype has no side effects"
+gdb_test "whatis ++x" "= int" "test whatis side effects"
+gdb_test "print x" "= 42" "whatis has no side effects"
Intel GmbH
Dornacher Strasse 1
85622 Feldkirchen/Muenchen, Deutschland
Sitz der Gesellschaft: Feldkirchen bei Muenchen
Geschaeftsfuehrer: Christian Lamprechter, Hannes Schwaderer, Douglas Lusk
Registergericht: Muenchen HRB 47456
Ust.-IdNr./VAT Registration No.: DE129385895
Citibank Frankfurt a.M. (BLZ 502 109 00) 600119052

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]