Hi Michael:

I like the codegen change for its simplicity.  We ought not to be matching on 
names anyway, so removing the cname extraction is undoubtedly better.  

In the test file, it would be good to test the negative case as well, if you 
have time -- 0x03 & 0x04, or just pass in a zero to get an occasional "false" 
in the .good file.

Thanks,
THH
________________________________________
From: Michael Ferguson [[email protected]]
Sent: Monday, March 31, 2014 8:22 AM
To: chapel-developers
Subject: [Chapel-developers] request for review: fix cast to bool

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