public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Antoni Boucher <antoyo@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-1353] libgccjit: Fix bug where unary_op will return an integer type instead of the correct type
Date: Thu, 30 Jun 2022 00:00:08 +0000 (GMT)	[thread overview]
Message-ID: <20220630000008.2A81E38485B5@sourceware.org> (raw)

https://gcc.gnu.org/g:e3a5c77388ae3791afed4f4286ec7e41e5b9f7c3

commit r13-1353-ge3a5c77388ae3791afed4f4286ec7e41e5b9f7c3
Author: Antoni Boucher <bouanto@zoho.com>
Date:   Wed Jun 29 19:56:56 2022 -0400

    libgccjit: Fix bug where unary_op will return an integer type instead of the correct type
    
    2022-06-29  Antoni Boucher  <bouanto@zoho.com>
    
    gcc/jit/
            PR jit/105812
            * jit-playback.cc: Use the correct return type when folding in
            as_truth_value.
    
    gcc/testsuite/
            PR jit/105812
            * jit.dg/test-asm.cc: Add include missing to make the test pass.
            * jit.dg/test-pr105812-bool-operations.c: New test.

Diff:
---
 gcc/jit/jit-playback.cc                            |  3 +-
 gcc/testsuite/jit.dg/test-asm.cc                   |  1 +
 .../jit.dg/test-pr105812-bool-operations.c         | 89 ++++++++++++++++++++++
 3 files changed, 92 insertions(+), 1 deletion(-)

diff --git a/gcc/jit/jit-playback.cc b/gcc/jit/jit-playback.cc
index 79714132b91..d227d36283a 100644
--- a/gcc/jit/jit-playback.cc
+++ b/gcc/jit/jit-playback.cc
@@ -1024,8 +1024,9 @@ as_truth_value (tree expr, location *loc)
   if (loc)
     set_tree_location (typed_zero, loc);
 
+  tree type = TREE_TYPE (expr);
   expr = fold_build2_loc (UNKNOWN_LOCATION,
-    NE_EXPR, integer_type_node, expr, typed_zero);
+    NE_EXPR, type, expr, typed_zero);
   if (loc)
     set_tree_location (expr, loc);
 
diff --git a/gcc/testsuite/jit.dg/test-asm.cc b/gcc/testsuite/jit.dg/test-asm.cc
index a3b45dacf07..d436f582351 100644
--- a/gcc/testsuite/jit.dg/test-asm.cc
+++ b/gcc/testsuite/jit.dg/test-asm.cc
@@ -1,5 +1,6 @@
 /* { dg-do compile { target x86_64-*-* } } */
 
+#include <stdint.h>
 #include "libgccjit++.h"
 
 #include "harness.h"
diff --git a/gcc/testsuite/jit.dg/test-pr105812-bool-operations.c b/gcc/testsuite/jit.dg/test-pr105812-bool-operations.c
new file mode 100644
index 00000000000..1daa1c3c35a
--- /dev/null
+++ b/gcc/testsuite/jit.dg/test-pr105812-bool-operations.c
@@ -0,0 +1,89 @@
+#include "libgccjit.h"
+
+#include "harness.h"
+
+void
+create_code (gcc_jit_context *ctxt, void *user_data)
+{
+  gcc_jit_type* bool_type =
+    gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_BOOL);
+  gcc_jit_type* bool_ptr_type =
+    gcc_jit_type_get_pointer (gcc_jit_type_get_aligned (bool_type, 1));
+
+  /* Function 1 */
+
+  gcc_jit_param* param1 = gcc_jit_context_new_param (ctxt, NULL, bool_type,
+						     "param1");
+  gcc_jit_function* function1 =
+    gcc_jit_context_new_function (ctxt, NULL,
+				  GCC_JIT_FUNCTION_EXPORTED, bool_type,
+				  "function1", 1, &param1, 0);
+  gcc_jit_block* block1 = gcc_jit_function_new_block (function1, "start1");
+
+  gcc_jit_lvalue* var1 =
+    gcc_jit_function_new_local (function1, NULL, bool_type, "var1");
+  gcc_jit_rvalue* addr1 =
+    gcc_jit_lvalue_get_address (var1, NULL);
+  gcc_jit_rvalue* ptr1 =
+    gcc_jit_context_new_cast (ctxt, NULL, addr1, bool_ptr_type);
+  gcc_jit_lvalue* deref1 =
+    gcc_jit_rvalue_dereference (ptr1, NULL);
+  gcc_jit_rvalue* param1_rvalue =
+    gcc_jit_param_as_rvalue (param1);
+  gcc_jit_block_add_assignment (block1, NULL, deref1, param1_rvalue);
+
+  gcc_jit_rvalue* one = gcc_jit_context_one (ctxt, bool_type);
+  gcc_jit_block_end_with_return (block1, NULL, one);
+
+  /* Function 2 */
+
+  gcc_jit_param* param2 = gcc_jit_context_new_param (ctxt, NULL, bool_type,
+						     "param2");
+  gcc_jit_function* function2 =
+    gcc_jit_context_new_function (ctxt, NULL,
+				  GCC_JIT_FUNCTION_EXPORTED, bool_type,
+				  "function2", 1, &param2, 0);
+  gcc_jit_block* block2 = gcc_jit_function_new_block (function2, "start2");
+
+  gcc_jit_lvalue* var2 =
+    gcc_jit_function_new_local (function2, NULL, bool_type, "var2");
+  gcc_jit_rvalue* addr2 =
+    gcc_jit_lvalue_get_address (var2, NULL);
+  gcc_jit_rvalue* ptr2 =
+    gcc_jit_context_new_cast (ctxt, NULL, addr2, bool_ptr_type);
+  gcc_jit_lvalue* deref2 =
+    gcc_jit_rvalue_dereference (ptr2, NULL);
+  gcc_jit_rvalue* param2_rvalue =
+    gcc_jit_param_as_rvalue (param2);
+  gcc_jit_block_add_assignment (block2, NULL, deref2, param2_rvalue);
+
+  gcc_jit_lvalue* return_value =
+    gcc_jit_function_new_local (function2, NULL, bool_type, "return_value");
+  gcc_jit_rvalue* call =
+    gcc_jit_context_new_call (ctxt, NULL, function1, 1, &param2_rvalue);
+  gcc_jit_block_add_assignment (block2, NULL, return_value, call);
+
+  gcc_jit_block* block2_1 =
+    gcc_jit_function_new_block (function2, "end2");
+  gcc_jit_block_end_with_jump (block2, NULL, block2_1);
+
+  gcc_jit_rvalue* value =
+    gcc_jit_context_new_unary_op (ctxt, NULL,
+				  GCC_JIT_UNARY_OP_LOGICAL_NEGATE, bool_type,
+				  param2_rvalue);
+  gcc_jit_rvalue* return_rvalue =
+    gcc_jit_lvalue_as_rvalue (return_value);
+  gcc_jit_rvalue* and =
+    gcc_jit_context_new_binary_op (ctxt, NULL,
+				   GCC_JIT_BINARY_OP_BITWISE_AND, bool_type,
+				   return_rvalue, value);
+
+  gcc_jit_block_end_with_return (block2_1, NULL, and);
+}
+
+extern void
+verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
+{
+  /* Verify that no errors were emitted.  */
+  CHECK_NON_NULL (result);
+}


                 reply	other threads:[~2022-06-30  0:00 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220630000008.2A81E38485B5@sourceware.org \
    --to=antoyo@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).