aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2014-12-19 20:34:39 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2014-12-19 20:34:39 +0000
commite8af59bc73dc39f8932a812bf1d265281b2dd7d0 (patch)
tree38f2815dfec52b775911a30f80c2bf77d568aea7
parent6db4bc6e2553169f6bf1214d7cbb95e2d0060402 (diff)
downloadgcc-e8af59bc73dc39f8932a812bf1d265281b2dd7d0.zip
gcc-e8af59bc73dc39f8932a812bf1d265281b2dd7d0.tar.gz
gcc-e8af59bc73dc39f8932a812bf1d265281b2dd7d0.tar.bz2
Fix casting non-"int" to bool.
gcc/jit/ChangeLog: * jit-playback.c (gcc::jit::playback::context::build_cast): In case BOOLEAN_TYPE, don't assume that the source expression is of type "int". gcc/testsuite/ChangeLog: * jit.dg/test-expressions.c (make_tests_of_casts): Add tests of casting between "long" and "bool". (verify_casts): Verify these new test cases. From-SVN: r218977
-rw-r--r--gcc/jit/ChangeLog6
-rw-r--r--gcc/jit/jit-playback.c3
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/jit.dg/test-expressions.c38
4 files changed, 52 insertions, 1 deletions
diff --git a/gcc/jit/ChangeLog b/gcc/jit/ChangeLog
index 8f3f412..09e5c8a 100644
--- a/gcc/jit/ChangeLog
+++ b/gcc/jit/ChangeLog
@@ -1,5 +1,11 @@
2014-12-19 David Malcolm <dmalcolm@redhat.com>
+ * jit-playback.c (gcc::jit::playback::context::build_cast): In
+ case BOOLEAN_TYPE, don't assume that the source expression is
+ of type "int".
+
+2014-12-19 David Malcolm <dmalcolm@redhat.com>
+
* jit-recording.c (gcc::jit::recording::context::context): When
copying string options from a parent context, take a copy of the
underlying buffers, rather than simply copying the pointer.
diff --git a/gcc/jit/jit-playback.c b/gcc/jit/jit-playback.c
index 57ff50e..3667d1a 100644
--- a/gcc/jit/jit-playback.c
+++ b/gcc/jit/jit-playback.c
@@ -875,7 +875,8 @@ playback::context::build_cast (playback::location *loc,
c_common_truthvalue_conversion. */
/* For now, convert to: (t_expr != 0) */
t_ret = build2 (NE_EXPR, t_dst_type,
- t_expr, integer_zero_node);
+ t_expr,
+ build_int_cst (TREE_TYPE (t_expr), 0));
goto maybe_fold;
case REAL_TYPE:
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index d00b5d7..ad7acfb 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2014-12-19 David Malcolm <dmalcolm@redhat.com>
+
+ * jit.dg/test-expressions.c (make_tests_of_casts): Add tests of
+ casting between "long" and "bool".
+ (verify_casts): Verify these new test cases.
+
2014-12-19 Matthew Fortune <matthew.fortune@imgtec.com>
* gcc.target/mips/pr37362.c: Skip for mips-img-elf.
diff --git a/gcc/testsuite/jit.dg/test-expressions.c b/gcc/testsuite/jit.dg/test-expressions.c
index eb986f3..87abb76 100644
--- a/gcc/testsuite/jit.dg/test-expressions.c
+++ b/gcc/testsuite/jit.dg/test-expressions.c
@@ -543,6 +543,8 @@ make_tests_of_casts (gcc_jit_context *ctxt)
{
gcc_jit_type *int_type =
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
+ gcc_jit_type *long_type =
+ gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_LONG);
gcc_jit_type *float_type =
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_FLOAT);
gcc_jit_type *bool_type =
@@ -582,6 +584,20 @@ make_tests_of_casts (gcc_jit_context *ctxt)
"test_cast_from_int_to_bool"),
"(bool)a");
+ /* bool/long conversions */
+ CHECK_STRING_VALUE (
+ make_test_of_cast (ctxt,
+ bool_type,
+ long_type,
+ "test_cast_from_bool_to_long"),
+ "(long)a");
+ CHECK_STRING_VALUE (
+ make_test_of_cast (ctxt,
+ long_type,
+ bool_type,
+ "test_cast_from_long_to_bool"),
+ "(bool)a");
+
/* array/ptr conversions */
{
gcc_jit_function *test_fn =
@@ -701,6 +717,28 @@ verify_casts (gcc_jit_result *result)
CHECK_VALUE (test_cast_from_int_to_bool (1), 1);
}
+ /* bool to long */
+ {
+ typedef long (*fn_type) (bool);
+ fn_type test_cast_from_bool_to_long =
+ (fn_type)gcc_jit_result_get_code (result,
+ "test_cast_from_bool_to_long");
+ CHECK_NON_NULL (test_cast_from_bool_to_long);
+ CHECK_VALUE (test_cast_from_bool_to_long (0), 0);
+ CHECK_VALUE (test_cast_from_bool_to_long (1), 1);
+ }
+
+ /* long to bool */
+ {
+ typedef bool (*fn_type) (long);
+ fn_type test_cast_from_long_to_bool =
+ (fn_type)gcc_jit_result_get_code (result,
+ "test_cast_from_long_to_bool");
+ CHECK_NON_NULL (test_cast_from_long_to_bool);
+ CHECK_VALUE (test_cast_from_long_to_bool (0), 0);
+ CHECK_VALUE (test_cast_from_long_to_bool (1), 1);
+ }
+
/* array to ptr */
{
typedef int (*fn_type) (void);