* [PATCH] c++: ICE with templated sizeof(E1) / sizeof(E2) [PR114888]
@ 2024-04-29 14:28 Patrick Palka
2024-04-29 14:52 ` Marek Polacek
0 siblings, 1 reply; 3+ messages in thread
From: Patrick Palka @ 2024-04-29 14:28 UTC (permalink / raw)
To: gcc-patches; +Cc: jason, jakub, Patrick Palka
Lightly tested on x86_64-pc-linux-gnu so far, does this look OK for
trunk/14.1 after bootstrap+regtest finishes?
-- >8 --
We're missing a dependence check for the second operand in the
sizeof / sizeof handling.
PR c++/114888
gcc/cp/ChangeLog:
* typeck.cc (cp_build_binary_op) <case *_DIV_*>: Add missing
dependence check for the second sizeof operand.
gcc/testsuite/ChangeLog:
* g++.dg/template/sizeof19.C: New test.
---
gcc/cp/typeck.cc | 1 +
gcc/testsuite/g++.dg/template/sizeof19.C | 8 ++++++++
2 files changed, 9 insertions(+)
create mode 100644 gcc/testsuite/g++.dg/template/sizeof19.C
diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
index e5a52dc2b39..a25f8622651 100644
--- a/gcc/cp/typeck.cc
+++ b/gcc/cp/typeck.cc
@@ -5501,6 +5501,7 @@ cp_build_binary_op (const op_location_t &location,
if (!TYPE_P (type1))
type1 = TREE_TYPE (type1);
if (type0
+ && type1
&& INDIRECT_TYPE_P (type0)
&& same_type_p (TREE_TYPE (type0), type1))
{
diff --git a/gcc/testsuite/g++.dg/template/sizeof19.C b/gcc/testsuite/g++.dg/template/sizeof19.C
new file mode 100644
index 00000000000..a1467995a9b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/sizeof19.C
@@ -0,0 +1,8 @@
+// PR c++/114888
+
+template<class>
+struct A {
+ struct B {} *b;
+ static const int c = sizeof (b) / sizeof (b[0]);
+};
+const int d = A<int>::c;
--
2.45.0.rc1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] c++: ICE with templated sizeof(E1) / sizeof(E2) [PR114888]
2024-04-29 14:28 [PATCH] c++: ICE with templated sizeof(E1) / sizeof(E2) [PR114888] Patrick Palka
@ 2024-04-29 14:52 ` Marek Polacek
2024-04-29 22:19 ` Jason Merrill
0 siblings, 1 reply; 3+ messages in thread
From: Marek Polacek @ 2024-04-29 14:52 UTC (permalink / raw)
To: Patrick Palka; +Cc: gcc-patches, jason, jakub
On Mon, Apr 29, 2024 at 10:28:19AM -0400, Patrick Palka wrote:
> Lightly tested on x86_64-pc-linux-gnu so far, does this look OK for
> trunk/14.1 after bootstrap+regtest finishes?
LGTM.
> -- >8 --
>
> We're missing a dependence check for the second operand in the
> sizeof / sizeof handling.
>
> PR c++/114888
>
> gcc/cp/ChangeLog:
>
> * typeck.cc (cp_build_binary_op) <case *_DIV_*>: Add missing
> dependence check for the second sizeof operand.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/template/sizeof19.C: New test.
> ---
> gcc/cp/typeck.cc | 1 +
> gcc/testsuite/g++.dg/template/sizeof19.C | 8 ++++++++
> 2 files changed, 9 insertions(+)
> create mode 100644 gcc/testsuite/g++.dg/template/sizeof19.C
>
> diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
> index e5a52dc2b39..a25f8622651 100644
> --- a/gcc/cp/typeck.cc
> +++ b/gcc/cp/typeck.cc
> @@ -5501,6 +5501,7 @@ cp_build_binary_op (const op_location_t &location,
> if (!TYPE_P (type1))
> type1 = TREE_TYPE (type1);
> if (type0
> + && type1
> && INDIRECT_TYPE_P (type0)
> && same_type_p (TREE_TYPE (type0), type1))
> {
> diff --git a/gcc/testsuite/g++.dg/template/sizeof19.C b/gcc/testsuite/g++.dg/template/sizeof19.C
> new file mode 100644
> index 00000000000..a1467995a9b
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/template/sizeof19.C
> @@ -0,0 +1,8 @@
> +// PR c++/114888
> +
> +template<class>
> +struct A {
> + struct B {} *b;
> + static const int c = sizeof (b) / sizeof (b[0]);
> +};
> +const int d = A<int>::c;
> --
> 2.45.0.rc1
>
Marek
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] c++: ICE with templated sizeof(E1) / sizeof(E2) [PR114888]
2024-04-29 14:52 ` Marek Polacek
@ 2024-04-29 22:19 ` Jason Merrill
0 siblings, 0 replies; 3+ messages in thread
From: Jason Merrill @ 2024-04-29 22:19 UTC (permalink / raw)
To: Marek Polacek, Patrick Palka; +Cc: gcc-patches, jakub
On 4/29/24 07:52, Marek Polacek wrote:
> On Mon, Apr 29, 2024 at 10:28:19AM -0400, Patrick Palka wrote:
>> Lightly tested on x86_64-pc-linux-gnu so far, does this look OK for
>> trunk/14.1 after bootstrap+regtest finishes?
>
> LGTM.
Yes, OK.
>> -- >8 --
>>
>> We're missing a dependence check for the second operand in the
>> sizeof / sizeof handling.
>>
>> PR c++/114888
>>
>> gcc/cp/ChangeLog:
>>
>> * typeck.cc (cp_build_binary_op) <case *_DIV_*>: Add missing
>> dependence check for the second sizeof operand.
>>
>> gcc/testsuite/ChangeLog:
>>
>> * g++.dg/template/sizeof19.C: New test.
>> ---
>> gcc/cp/typeck.cc | 1 +
>> gcc/testsuite/g++.dg/template/sizeof19.C | 8 ++++++++
>> 2 files changed, 9 insertions(+)
>> create mode 100644 gcc/testsuite/g++.dg/template/sizeof19.C
>>
>> diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
>> index e5a52dc2b39..a25f8622651 100644
>> --- a/gcc/cp/typeck.cc
>> +++ b/gcc/cp/typeck.cc
>> @@ -5501,6 +5501,7 @@ cp_build_binary_op (const op_location_t &location,
>> if (!TYPE_P (type1))
>> type1 = TREE_TYPE (type1);
>> if (type0
>> + && type1
>> && INDIRECT_TYPE_P (type0)
>> && same_type_p (TREE_TYPE (type0), type1))
>> {
>> diff --git a/gcc/testsuite/g++.dg/template/sizeof19.C b/gcc/testsuite/g++.dg/template/sizeof19.C
>> new file mode 100644
>> index 00000000000..a1467995a9b
>> --- /dev/null
>> +++ b/gcc/testsuite/g++.dg/template/sizeof19.C
>> @@ -0,0 +1,8 @@
>> +// PR c++/114888
>> +
>> +template<class>
>> +struct A {
>> + struct B {} *b;
>> + static const int c = sizeof (b) / sizeof (b[0]);
>> +};
>> +const int d = A<int>::c;
>> --
>> 2.45.0.rc1
>>
>
> Marek
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-04-29 22:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-29 14:28 [PATCH] c++: ICE with templated sizeof(E1) / sizeof(E2) [PR114888] Patrick Palka
2024-04-29 14:52 ` Marek Polacek
2024-04-29 22:19 ` Jason Merrill
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).