This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC 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: [tree-ssa] Why are bools cast to int in conditionals?


On Thu, 22 Apr 2004, Paul Koning wrote:

> The trouble with that is that promotion to int is in fact
> language-specific -- C/C++ may define things that way, but most other
> high level languages don't.  Not that modula-3 or pascal is a high
> visibility front-end, but I don't think that viewing this issue as
> language-INdependent is right.

Other languages convert bool to int yielding values other than 0 (false)  
and 1 (true), or otherwise promote them such that a comparison of promoted
/ converted values can't be narrowed to one of narrower types?  The fact
that there's an implicit promotion may be language-dependent - each front
end should build trees reflecting what the language's rules are - but the
question is whether the transformation narrowing an operation on promoted
types is also language-dependent.

By the time this reaches GIMPLE, the semantics of a bool-to-int conversion
must be well-defined, and it should still be possible to narrow it (for
the case of explicit conversions in the source, as well as the implicit
ones).  If narrowing comparisons on converted types is invalid on trees in
some languages before GIMPLE, some language hook may be needed to describe
this.

-- 
Joseph S. Myers
jsm@polyomino.org.uk


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