From: Andrea Corallo <andrea.corallo@arm.com>
To: Alex Coplan <Alex.Coplan@arm.com>
Cc: "jit@gcc.gnu.org" <jit@gcc.gnu.org>, nd <nd@arm.com>,
David Malcolm <dmalcolm@redhat.com>,
gcc-patches@gcc.gnu.org
Subject: [PATCH] libgccjit: Improve doc and comments regarding type casts (Was: Clarifying the permitted type conversions)
Date: Wed, 22 Jul 2020 10:45:20 +0200 [thread overview]
Message-ID: <gkr365kym3j.fsf@arm.com> (raw)
In-Reply-To: <VI1PR08MB402951506212A2CFD8641B04EA640@VI1PR08MB4029.eurprd08.prod.outlook.com> (Alex Coplan's message of "Thu, 9 Jul 2020 14:15:14 +0000")
[-- Attachment #1: Type: text/plain, Size: 1854 bytes --]
Alex Coplan <Alex.Coplan@arm.com> writes:
> Secondly, I wanted to clarify the situation with respect to explicit
> casts; that is, those conversions allowed by gcc_jit_context_new_cast().
> The docs [0] say:
>
> Currently only a limited set of conversions are possible:
> - int <-> float
> - int <-> bool
> - P* <-> Q*, for pointer types P and Q
>
> However, empirically (at least on aarch64), libgccjit appears to allow
> me to compile casts between any pair of types in the following set
> without any complaint:
>
> {
> SIGNED_CHAR,
> UNSIGNED_CHAR,
> SHORT,
> UNSIGNED_SHORT,
> INT,
> UNSIGNED_INT,
> LONG,
> UNSIGNED_LONG,
> LONG_LONG,
> UNSIGNED_LONG_LONG
> }
Hi Alex,
Looking at the code I believe all these casts are meant to be supported
(read your intuition was correct).
Also IMO source of confusion is that the doc is mentioning 'int' and
'float' but I believe would be better to have like 'integral' and
'floating-point' to clearly disambiguates with respect to the C
types.
AFAIU the set of supported casts should be like:
integral <-> integral
floating-point <-> floating-point
integral <-> floating-point
integral <-> bool
P* <-> Q* for pointer types P and Q.
I'd propose to install the following patch to make doc and comments
homogeneous at documenting what do we accept, and I guess we should just
consider bugs if some of these conversions is not handled correctly or
leads to ICE.
Bests
Andrea
gcc/jit/ChangeLog
2020-07-21 Andrea Corallo <andrea.corallo@arm.com>
* docs/_build/texinfo/libgccjit.texi (Type-coercion): Improve doc
on allowed type casting.
* docs/topics/expressions.rst (gccjit::context::new_cast)
(gcc_jit_context_new_cast): Likewise.
* libgccjit.c: Improve comment on allowed type casting.
* libgccjit.h: Likewise
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-libgccjit-improve-documentation-on-type-conversions.patch --]
[-- Type: text/x-diff, Size: 3931 bytes --]
From 914b9e86808c947d4bb2b06c6960fd8031125f67 Mon Sep 17 00:00:00 2001
From: Andrea Corallo <andrea.corallo@arm.com>
Date: Tue, 21 Jul 2020 20:12:23 +0200
Subject: [PATCH] libgccjit: improve documentation on type conversions
gcc/jit/ChangeLog
2020-07-21 Andrea Corallo <andrea.corallo@arm.com>
* docs/_build/texinfo/libgccjit.texi (Type-coercion): Improve doc
on allowed type casting.
* docs/topics/expressions.rst (gccjit::context::new_cast)
(gcc_jit_context_new_cast): Likewise.
* libgccjit.c: Improve comment on allowed type casting.
* libgccjit.h: Likewise
---
gcc/jit/docs/_build/texinfo/libgccjit.texi | 30 +++++++++++++++-------
gcc/jit/docs/topics/expressions.rst | 8 +++---
gcc/jit/libgccjit.c | 8 +++---
gcc/jit/libgccjit.h | 7 +++--
4 files changed, 36 insertions(+), 17 deletions(-)
diff --git a/gcc/jit/docs/_build/texinfo/libgccjit.texi b/gcc/jit/docs/_build/texinfo/libgccjit.texi
index 1e14be010426..b170f24d1bb1 100644
--- a/gcc/jit/docs/_build/texinfo/libgccjit.texi
+++ b/gcc/jit/docs/_build/texinfo/libgccjit.texi
@@ -6685,13 +6685,19 @@ Currently only a limited set of conversions are possible:
@itemize *
@item
-int <-> float
+integral <-> integral
@item
-int <-> bool
+floating-point <-> floating-point
@item
-P* <-> Q*, for pointer types P and Q
+integral <-> floating-point
+
+@item
+integral <-> bool
+
+@item
+P* <-> Q* for pointer types P and Q
@end itemize
@end quotation
@end deffn
@@ -12964,14 +12970,20 @@ Currently only a limited set of conversions are possible:
@itemize *
-@item
-int <-> float
+@item
+integral <-> integral
-@item
-int <-> bool
+@item
+floating-point <-> floating-point
-@item
-P* <-> Q*, for pointer types P and Q
+@item
+integral <-> floating-point
+
+@item
+integral <-> bool
+
+@item
+P* <-> Q*, for pointer types P and Q
@end itemize
@end quotation
@end deffn
diff --git a/gcc/jit/docs/topics/expressions.rst b/gcc/jit/docs/topics/expressions.rst
index d783ceea51a8..051cee5db211 100644
--- a/gcc/jit/docs/topics/expressions.rst
+++ b/gcc/jit/docs/topics/expressions.rst
@@ -504,9 +504,11 @@ Type-coercion
Currently only a limited set of conversions are possible:
- * int <-> float
- * int <-> bool
- * P* <-> Q*, for pointer types P and Q
+ * integral <-> integral
+ * floating-point <-> floating-point
+ * integral <-> floating-point
+ * integral <-> bool
+ * P* <-> Q* for pointer types P and Q
Lvalues
-------
diff --git a/gcc/jit/libgccjit.c b/gcc/jit/libgccjit.c
index 3d04f6db3aff..403233d5577a 100644
--- a/gcc/jit/libgccjit.c
+++ b/gcc/jit/libgccjit.c
@@ -1629,9 +1629,11 @@ gcc_jit_context_new_call_through_ptr (gcc_jit_context *ctxt,
We only permit these kinds of cast:
- int <-> float
- int <-> bool
- P* <-> Q* for pointer types P and Q. */
+ integral <-> integral
+ floating-point <-> floating-point
+ integral <-> floating-point
+ integral <-> bool
+ P* <-> Q* for pointer types P and Q. */
static bool
is_valid_cast (gcc::jit::recording::type *src_type,
diff --git a/gcc/jit/libgccjit.h b/gcc/jit/libgccjit.h
index 1c5a12e9c015..228befa896d7 100644
--- a/gcc/jit/libgccjit.h
+++ b/gcc/jit/libgccjit.h
@@ -996,8 +996,11 @@ gcc_jit_context_new_call_through_ptr (gcc_jit_context *ctxt,
/* Type-coercion.
Currently only a limited set of conversions are possible:
- int <-> float
- int <-> bool */
+ integral <-> integral
+ floating-point <-> floating-point
+ integral <-> floating-point
+ integral <-> bool
+ P* <-> Q* for pointer types P and Q. */
extern gcc_jit_rvalue *
gcc_jit_context_new_cast (gcc_jit_context *ctxt,
gcc_jit_location *loc,
--
2.17.1
next prev parent reply other threads:[~2020-07-22 8:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-09 14:15 libgccjit: Clarifying the permitted type conversions Alex Coplan
2020-07-21 8:27 ` Alex Coplan
2020-07-22 8:45 ` Andrea Corallo [this message]
2020-08-06 7:40 ` [PATCH] libgccjit: Improve doc and comments regarding type casts Andrea Corallo
2020-09-09 7:56 ` Andrea Corallo
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=gkr365kym3j.fsf@arm.com \
--to=andrea.corallo@arm.com \
--cc=Alex.Coplan@arm.com \
--cc=dmalcolm@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jit@gcc.gnu.org \
--cc=nd@arm.com \
/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).