This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFC] logic change in m2-valprint.c
> On Sun, Jul 01, 2007 at 08:54:19AM -0700, Michael Snyder wrote:
>> > It can't be backwards; this is trying to print "1" or "1, 2" but your
>> > change would make it print ", 1" and ", 12".
>> >
>> > I think it's also trying to shorten ranges to "{1..3, 6..7}". The
>> > bug's got to be in there somewhere. Why's the code dead? I'm not
>> > seeing it... element_seen can be reset by the bit clear case, and then
>> > we'll get into the test you're changing again.
>>
>> 'Cause we're not in a loop, and it's not a static variable.
>> The code is serial. At entry we set empty_set to one, and
>> then we test to see if it's zero. It can't be zero.
>
> How sure are you sure we're not in a loop? :-)
I'm sorry -- too many balls in the air. Try this:
91 int empty_set = 1;
92 int element_seen = 0;
...
123 for (i = low_bound; i <= high_bound; i++)
...
133 if (! element_seen)
134 {
135 if (! empty_set)
136 fprintf_filtered (stream, ", ");
137 print_type_scalar (target, i, stream);
138 empty_set = 0;
139 element_seen = 1;
140 previous_low = i;
141 }
So, the reasoning is as follows: line 136 is dead code, because
line 135 can never test true, because the first time we enter
the block beginning at line 133, empty_set will be true (there
is nowhere else for it to be set false), and there is no second
time -- we will never enter this block again because we will set
"element_seen" to true (and there is nowhere else for it to be
set false again).
Was that clear?
So on pass "n", we enter the block. Empty_set must be true.
We now set empty set false, and element_seen to true, and
therefore on pass "n + m" we cannot enter the block. So there
is no point at which we can execute line 136.