This is the mail archive of the gdb-patches@sourceware.org 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] Vector to scalar casting and widening


Andrew Burgess wrote:

> In addressing the two problems you pointed out above, I first created a
> new function opencl_value_cast, which I use throughout opencl-lang.c,
> however, a quick grep of the codebase shows other places that call
> value_cast, for example, within the varobj.c code.  I suspect that
> creating an opencl_value_cast function will mean that I am introducing
> bugs when, for example, we create varobj objects for opencl code.
>
> The first issue you pointed out above "vector <binop> scalar" seems even
> harder to fix.  The current problem with my patch is that I call
> value_vector_widen from value_binop, which will error if the scalar
> value is truncated when casting to the vector type.  For OpenCL this is
> the wrong thing to do.  I don't want to add an "if (language == opencl)"
> switch to value_binop, and value_binop is called extensively throughout
> the codebase.  This would suggest then that it is value_vector_widen
> that should change, however, this feels very much like the original
> patch to which you objected.
> 
> So, to summarise the problem as I see it, your suggested solution was to
> filter the different behaviours within opencl-lang.c, however, the
> problem behaviours live within value_cast and value_binop, both of which
> I believe are called from core gdb code, not just from opencl-lang.c, I
> therefore believe there's no reliable way to intercept all calls to
> these functions.

I don't actually think you need (or even *should*) intercept all such
calls.  Taking a step back, the underlying problem is that GDB supports
operating on expressions in various different languages that all have
their own special rules on how to perform certain operations, but maps
them all to a single GDB "value" type, with a single set of operations
on them.

My understanding of how this is supposed to work out is that GDB
"value" operations *do not* actually implement the precise semantics
of any of the languages GDB supports; rather, they implement a GDB
private semantics of "GDB value" objects.  Now, as those are private
to GDB, we are free to implement them however we wish; for pragmatic
and historical reasons, they do mostly (but not completely!) match
C semantics.

When evaluating language expressions, the eval* routines are free
to use value_* operations directly **when their semantics match the
language semantics**, but must use a different implementation when
the language requires special semantics.  (Note how e.g. the particular
C type promotions rules for binary operations are *not* implemented
in value_binop, but are handled specially in the C expression
evaluation code.)

[ For historical reasons, some of the value_* operations currently
change aspects of their behaviour depending on current_language.
This is really a bug, and we ought to (and slowly do) move away
from this.  For example, in a program employing multiple languages
simultaneously, GDB value objects might have been created from
values in a different language than the "current" one. ]

Now, as you point out, value_* operations are also used throughout
the rest of GDB (not part of expression evaluation).  This is fine,
as long as those parts **do not assume they follow any particular
language semantics, but rather the generic GDB value semantics**.

In general, I think this is in fact the case.  For example, the
value_cast uses in varobj.c you mention appear to only rely on
common properties of the GDB value semantics (casting C++ objects
between base and derived types).  If there are indeed instances
of value_ operations that assume specific C (or OpenCL) semantics,
those would have to be fixed.  [ In particular for OpenCL, I'm
quite sure that no-one outside of opencl-lang.c relies on any
particular OpenCL semantics of the value_ operations. ]

> I'd like to put two other possible solutions on the table (they are
> really just variations on the same theme), these would be (1) go back to
> my original flag on the language structure, handle all the different
> variations within value_cast or value_vector_widen, or (2) have a set of
> "vector_ops" function pointers on the language structure, currently
> there would be just two, "scalar_to_vector_widen" and
> "scalar_to_vector_cast".  The defaults would be standard gcc C behaviour
> implemented in (probably) valops.c, while opencl would provide its own
> within opencl-lang.c.

Both of these would go back to make value_ operations change their
behaviour depending on a language, which goes against the general
direction I've outlined above ...

Bye,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com


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