I'm wondering if the fix would be similarly correct and more 
straightforward/less fiddly at codegen time if you were to add the 
following to ChapelBase.chpl:

   inline proc _cast(type t, x: integral) where _isBooleanType(t)
     return (x != 0);

Generally, I'd like to see us converting more of these primitive casts 
into something that doesn't require special codegen logic, whether Chapel 
code like the above, or calls to a static inline C function in the runtime 
in more primitive cases.

-Brad


On Mon, 31 Mar 2014, Michael Ferguson wrote:

> Normalize behavior of cast to Boolean types
>
> Before this patch, casting int/uint to a Boolean type would sometimes give a
> true value if the int/uint was nonzero, but sometimes truncate the int/uint
> to the size of the Boolean.
>
> The included test case demonstrates this problem (and should always print out
> 'true').  Code using default-width Bools worked OK because of the C99 _Bool
> rules, but any cast to non-default width Boolean type or any cast to a 
> Boolean
> type with the LLVM backend did not work properly.
>
> The simple fix in expr.cpp was to:
> 1) modify a call to codegenCast to pass the Chapel type instead of
>    type->symbol->cname, so that we can call is_bool_type on it.
> 2) modify the codegenCast that takes in a Chapel type to handle Boolean
>    types specially.
>
>
> Verified with CHPL_LLVM=none make check and checked that the new test works
> with and without --llvm. (and started a full local/C test-suite run; so
> far so good).
>
> Future Work: update the spec to describe the behavior of casts to Bool.
>

------------------------------------------------------------------------------
_______________________________________________
Chapel-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-developers

Reply via email to