* [PATCH] Fix __builtin_clear_padding for empty struct.
@ 2020-12-02 9:25 Martin Liška
2020-12-02 10:11 ` Jakub Jelinek
0 siblings, 1 reply; 3+ messages in thread
From: Martin Liška @ 2020-12-02 9:25 UTC (permalink / raw)
To: gcc-patches; +Cc: Jakub Jelinek
It's a simple fix of a division by zero.
Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
Ready to be installed?
Thanks,
Martin
gcc/ChangeLog:
PR c/98087
* gimple-fold.c (clear_padding_type): Do not divide by zero.
gcc/testsuite/ChangeLog:
PR c/98087
* gcc.c-torture/compile/pr98087.c: New test.
---
gcc/gimple-fold.c | 2 ++
gcc/testsuite/gcc.c-torture/compile/pr98087.c | 8 ++++++++
2 files changed, 10 insertions(+)
create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr98087.c
diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
index 1f3d80e2881..ab74494703a 100644
--- a/gcc/gimple-fold.c
+++ b/gcc/gimple-fold.c
@@ -4552,6 +4552,8 @@ clear_padding_type (clear_padding_struct *buf, tree type, HOST_WIDE_INT sz)
case ARRAY_TYPE:
HOST_WIDE_INT nelts, fldsz;
fldsz = int_size_in_bytes (TREE_TYPE (type));
+ if (fldsz == 0)
+ break;
nelts = sz / fldsz;
if (nelts > 1
&& sz > 8 * UNITS_PER_WORD
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr98087.c b/gcc/testsuite/gcc.c-torture/compile/pr98087.c
new file mode 100644
index 00000000000..9f0e5c4be7d
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr98087.c
@@ -0,0 +1,8 @@
+/* PR c/98087 */
+
+struct S {};
+void foo (int n)
+{
+ struct S a[n][0];
+ __builtin_clear_padding (a);
+}
--
2.29.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Fix __builtin_clear_padding for empty struct.
2020-12-02 9:25 [PATCH] Fix __builtin_clear_padding for empty struct Martin Liška
@ 2020-12-02 10:11 ` Jakub Jelinek
2020-12-02 10:32 ` Martin Liška
0 siblings, 1 reply; 3+ messages in thread
From: Jakub Jelinek @ 2020-12-02 10:11 UTC (permalink / raw)
To: Martin Liška; +Cc: gcc-patches
On Wed, Dec 02, 2020 at 10:25:32AM +0100, Martin Liška wrote:
> It's a simple fix of a division by zero.
>
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>
> Ready to be installed?
> Thanks,
> Martin
>
> gcc/ChangeLog:
>
> PR c/98087
> * gimple-fold.c (clear_padding_type): Do not divide by zero.
>
> gcc/testsuite/ChangeLog:
>
> PR c/98087
> * gcc.c-torture/compile/pr98087.c: New test.
Ok, but can you extend the testcase a little bit to cover more cases?
> --- /dev/null
> +++ b/gcc/testsuite/gcc.c-torture/compile/pr98087.c
> @@ -0,0 +1,8 @@
> +/* PR c/98087 */
> +
> +struct S {};
> +void foo (int n)
> +{
> + struct S a[n][0];
> + __builtin_clear_padding (a);
> +}
Like:
struct S { char a; long long b; };
struct T { struct S c[0]; char d; };
void foo (int n)
{
struct S a[n][0];
__builtin_clear_padding (a);
__builtin_clear_padding (&a);
struct S b[7][0];
__builtin_clear_padding (&b);
struct T c;
__builtin_clear_padding (&c);
}
Without your patch we ICE on the first 3, the 4th not because the zero
length array satisfies is_empty_type. For the &a case, I even thought
I do handle that (the if (eltsz) conditional), but unlike my expectations,
int_size_in_bytes of the VLA with zero sized elements is not -1, but 0.
Jakub
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Fix __builtin_clear_padding for empty struct.
2020-12-02 10:11 ` Jakub Jelinek
@ 2020-12-02 10:32 ` Martin Liška
0 siblings, 0 replies; 3+ messages in thread
From: Martin Liška @ 2020-12-02 10:32 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches
On 12/2/20 11:11 AM, Jakub Jelinek wrote:
> On Wed, Dec 02, 2020 at 10:25:32AM +0100, Martin Liška wrote:
>> It's a simple fix of a division by zero.
>>
>> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>>
>> Ready to be installed?
>> Thanks,
>> Martin
>>
>> gcc/ChangeLog:
>>
>> PR c/98087
>> * gimple-fold.c (clear_padding_type): Do not divide by zero.
>>
>> gcc/testsuite/ChangeLog:
>>
>> PR c/98087
>> * gcc.c-torture/compile/pr98087.c: New test.
>
> Ok, but can you extend the testcase a little bit to cover more cases?
>
>> --- /dev/null
>> +++ b/gcc/testsuite/gcc.c-torture/compile/pr98087.c
>> @@ -0,0 +1,8 @@
>> +/* PR c/98087 */
>> +
>> +struct S {};
>> +void foo (int n)
>> +{
>> + struct S a[n][0];
>> + __builtin_clear_padding (a);
>> +}
>
> Like:
>
> struct S { char a; long long b; };
> struct T { struct S c[0]; char d; };
> void foo (int n)
> {
> struct S a[n][0];
> __builtin_clear_padding (a);
> __builtin_clear_padding (&a);
> struct S b[7][0];
> __builtin_clear_padding (&b);
> struct T c;
> __builtin_clear_padding (&c);
> }
>
> Without your patch we ICE on the first 3, the 4th not because the zero
> length array satisfies is_empty_type. For the &a case, I even thought
> I do handle that (the if (eltsz) conditional), but unlike my expectations,
> int_size_in_bytes of the VLA with zero sized elements is not -1, but 0.
Sure, thanks for improvement.
Pushed to master.
Martin
>
> Jakub
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-12-02 10:32 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-02 9:25 [PATCH] Fix __builtin_clear_padding for empty struct Martin Liška
2020-12-02 10:11 ` Jakub Jelinek
2020-12-02 10:32 ` Martin Liška
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).