* [PATCH] libgccjit: Allow sending a const pointer as argument
@ 2023-12-21 16:59 Antoni Boucher
2024-01-19 20:59 ` Antoni Boucher
2024-11-20 15:54 ` David Malcolm
0 siblings, 2 replies; 5+ messages in thread
From: Antoni Boucher @ 2023-12-21 16:59 UTC (permalink / raw)
To: jit, gcc-patches; +Cc: David Malcolm
[-- Attachment #1: Type: text/plain, Size: 108 bytes --]
Hi.
This patch adds the ability to send const pointer as argument to a
function.
Thanks for the review.
[-- Attachment #2: 0001-libgccjit-Allow-sending-a-const-pointer-as-argument.patch --]
[-- Type: text/x-patch, Size: 4695 bytes --]
From f53c4600d8103a5612e7de6cb8205cad37421074 Mon Sep 17 00:00:00 2001
From: Antoni Boucher <bouanto@zoho.com>
Date: Tue, 24 May 2022 17:44:53 -0400
Subject: [PATCH] libgccjit: Allow sending a const pointer as argument
gcc/jit/ChangeLog:
* jit-recording.h: Remove memento_of_get_const::accepts_writes_from.
gcc/testsuite/ChangeLog:
* jit.dg/all-non-failing-tests.h: Add test-const-pointer-argument.c.
* jit.dg/test-const-pointer-argument.c: New test.
---
gcc/jit/jit-recording.h | 6 --
gcc/testsuite/jit.dg/all-non-failing-tests.h | 10 +++
.../jit.dg/test-const-pointer-argument.c | 76 +++++++++++++++++++
3 files changed, 86 insertions(+), 6 deletions(-)
create mode 100644 gcc/testsuite/jit.dg/test-const-pointer-argument.c
diff --git a/gcc/jit/jit-recording.h b/gcc/jit/jit-recording.h
index 4a8082991fb..21aeb7d0bbd 100644
--- a/gcc/jit/jit-recording.h
+++ b/gcc/jit/jit-recording.h
@@ -720,12 +720,6 @@ public:
memento_of_get_const (type *other_type)
: decorated_type (other_type) {}
- bool accepts_writes_from (type */*rtype*/) final override
- {
- /* Can't write to a "const". */
- return false;
- }
-
/* Strip off the "const", giving the underlying type. */
type *unqualified () final override { return m_other_type; }
diff --git a/gcc/testsuite/jit.dg/all-non-failing-tests.h b/gcc/testsuite/jit.dg/all-non-failing-tests.h
index e762563f9bd..6ac9173ea7d 100644
--- a/gcc/testsuite/jit.dg/all-non-failing-tests.h
+++ b/gcc/testsuite/jit.dg/all-non-failing-tests.h
@@ -126,6 +126,13 @@
#undef create_code
#undef verify_code
+/* test-const-pointer-argument.c */
+#define create_code create_code_const_pointer_argument
+#define verify_code verify_code_const_pointer_argument
+#include "test-const-pointer-argument.c"
+#undef create_code
+#undef verify_code
+
/* test-debug-strings.c */
#define create_code create_code_debug_strings
#define verify_code verify_code_debug_strings
@@ -437,6 +444,9 @@ const struct testcase testcases[] = {
{"constants",
create_code_constants,
verify_code_constants},
+ {"const_pointer_argument",
+ create_code_const_pointer_argument,
+ verify_code_const_pointer_argument},
{"debug_strings",
create_code_debug_strings,
verify_code_debug_strings},
diff --git a/gcc/testsuite/jit.dg/test-const-pointer-argument.c b/gcc/testsuite/jit.dg/test-const-pointer-argument.c
new file mode 100644
index 00000000000..836634f1dd0
--- /dev/null
+++ b/gcc/testsuite/jit.dg/test-const-pointer-argument.c
@@ -0,0 +1,76 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+
+#include "libgccjit.h"
+
+#include "harness.h"
+
+void
+create_code (gcc_jit_context *ctxt, void *user_data)
+{
+ /* Let's try to inject the equivalent of:
+
+ int test_ptr(const int* value)
+ {
+ return *foo;
+ }
+
+ int main (void)
+ {
+ int value = 10;
+ const int *ptr = &value;
+ int res = test_ptr (ptr);
+ return res;
+ }
+ */
+ gcc_jit_type *int_type =
+ gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
+ gcc_jit_type *int_ptr_type =
+ gcc_jit_type_get_pointer (int_type);
+ gcc_jit_type *const_ptr_type =
+ gcc_jit_type_get_const (int_ptr_type);
+
+ /* Build the test_ptr. */
+ gcc_jit_param *param =
+ gcc_jit_context_new_param (ctxt, NULL, const_ptr_type, "value");
+ gcc_jit_function *test_ptr =
+ gcc_jit_context_new_function (ctxt, NULL,
+ GCC_JIT_FUNCTION_EXPORTED,
+ int_type,
+ "test_ptr",
+ 1, ¶m,
+ 0);
+ gcc_jit_block *block = gcc_jit_function_new_block (test_ptr, NULL);
+ gcc_jit_block_end_with_return (block,
+ NULL,
+ gcc_jit_lvalue_as_rvalue (
+ gcc_jit_rvalue_dereference (gcc_jit_param_as_rvalue (param), NULL)));
+
+ /* Build main. */
+ gcc_jit_function *main =
+ gcc_jit_context_new_function (ctxt, NULL,
+ GCC_JIT_FUNCTION_EXPORTED,
+ int_type,
+ "main",
+ 0, NULL,
+ 0);
+ gcc_jit_block *main_block = gcc_jit_function_new_block (main, NULL);
+ gcc_jit_lvalue *variable =
+ gcc_jit_function_new_local (main, NULL, int_type, "value");
+ gcc_jit_lvalue *pointer =
+ gcc_jit_function_new_local (main, NULL, const_ptr_type, "ptr");
+ gcc_jit_block_add_assignment (main_block, NULL, pointer,
+ gcc_jit_lvalue_get_address (variable, NULL));
+ gcc_jit_rvalue *ptr_rvalue = gcc_jit_lvalue_as_rvalue (pointer);
+ gcc_jit_rvalue *res =
+ gcc_jit_context_new_call (ctxt, NULL, test_ptr, 1, &ptr_rvalue);
+ gcc_jit_block_end_with_return (main_block, NULL, res);
+}
+
+void
+verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
+{
+ CHECK_NON_NULL (result);
+}
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] libgccjit: Allow sending a const pointer as argument
2023-12-21 16:59 [PATCH] libgccjit: Allow sending a const pointer as argument Antoni Boucher
@ 2024-01-19 20:59 ` Antoni Boucher
2024-02-17 16:55 ` Antoni Boucher
2024-11-20 15:54 ` David Malcolm
1 sibling, 1 reply; 5+ messages in thread
From: Antoni Boucher @ 2024-01-19 20:59 UTC (permalink / raw)
To: jit, gcc-patches; +Cc: David Malcolm
David: Ping.
On Thu, 2023-12-21 at 11:59 -0500, Antoni Boucher wrote:
> Hi.
> This patch adds the ability to send const pointer as argument to a
> function.
> Thanks for the review.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] libgccjit: Allow sending a const pointer as argument
2024-01-19 20:59 ` Antoni Boucher
@ 2024-02-17 16:55 ` Antoni Boucher
2024-10-15 17:09 ` Antoni Boucher
0 siblings, 1 reply; 5+ messages in thread
From: Antoni Boucher @ 2024-02-17 16:55 UTC (permalink / raw)
To: jit, gcc-patches; +Cc: David Malcolm
David: Ping.
On Fri, 2024-01-19 at 15:59 -0500, Antoni Boucher wrote:
> David: Ping.
>
> On Thu, 2023-12-21 at 11:59 -0500, Antoni Boucher wrote:
> > Hi.
> > This patch adds the ability to send const pointer as argument to a
> > function.
> > Thanks for the review.
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] libgccjit: Allow sending a const pointer as argument
2024-02-17 16:55 ` Antoni Boucher
@ 2024-10-15 17:09 ` Antoni Boucher
0 siblings, 0 replies; 5+ messages in thread
From: Antoni Boucher @ 2024-10-15 17:09 UTC (permalink / raw)
To: jit, gcc-patches; +Cc: David Malcolm
David: Ping.
Le 2024-02-17 à 11 h 55, Antoni Boucher a écrit :
> David: Ping.
>
> On Fri, 2024-01-19 at 15:59 -0500, Antoni Boucher wrote:
>> David: Ping.
>>
>> On Thu, 2023-12-21 at 11:59 -0500, Antoni Boucher wrote:
>>> Hi.
>>> This patch adds the ability to send const pointer as argument to a
>>> function.
>>> Thanks for the review.
>>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] libgccjit: Allow sending a const pointer as argument
2023-12-21 16:59 [PATCH] libgccjit: Allow sending a const pointer as argument Antoni Boucher
2024-01-19 20:59 ` Antoni Boucher
@ 2024-11-20 15:54 ` David Malcolm
1 sibling, 0 replies; 5+ messages in thread
From: David Malcolm @ 2024-11-20 15:54 UTC (permalink / raw)
To: Antoni Boucher, jit, gcc-patches
On Thu, 2023-12-21 at 11:59 -0500, Antoni Boucher wrote:
> Hi.
> This patch adds the ability to send const pointer as argument to a
> function.
> Thanks for the review.
Sorry for the long delay in responding to this.
I'm a bit worried that this might break some type-safety within
libgccjit, or that you might have a bug in your client code.
In the testcase you have:
gcc_jit_type *int_type =
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
gcc_jit_type *int_ptr_type =
gcc_jit_type_get_pointer (int_type);
gcc_jit_type *const_ptr_type =
gcc_jit_type_get_const (int_ptr_type);
/* Build the test_ptr. */
gcc_jit_param *param =
gcc_jit_context_new_param (ctxt, NULL, const_ptr_type, "value");
which is creating the equivalent of
int *const value
i.e. a const pointer to a non-const int
whereas in the comment you have:
/* Let's try to inject the equivalent of:
int test_ptr(const int* value)
where "const int *" is a non-const pointer to a const int.
So is the get_const and the get_pointer the wrong way round somewhere
in your code? Or am I missing something here?
Dave
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-11-20 15:54 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-21 16:59 [PATCH] libgccjit: Allow sending a const pointer as argument Antoni Boucher
2024-01-19 20:59 ` Antoni Boucher
2024-02-17 16:55 ` Antoni Boucher
2024-10-15 17:09 ` Antoni Boucher
2024-11-20 15:54 ` David Malcolm
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).