public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "lin1.hu at intel dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/114700] middle-end optimization generates causes -fsanitize=undefined not to happen in some cases
Date: Wed, 17 Apr 2024 01:50:23 +0000	[thread overview]
Message-ID: <bug-114700-4-W1cEg5Eoes@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-114700-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114700

--- Comment #20 from Hu Lin <lin1.hu at intel dot com> ---
Created attachment 57967
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57967&action=edit
A new version

When I tested this patch, I met another question. g++.dg/ubsan/vla-1.C will
raise a ICE without (TREE_TYPE (@2) == ssizetype at match.pd:3497.

In the original step, GCC generates the intermediate language using variables
declared in other blocks. Like _5 = _1 + 1, this led to the ICE in 022t.ssa. I
don't know if it is a bug, and I didn't find a test to raise this ICE on trunk.
So I add a condition to avoid this optimization in this case, any other
comments on my newly added conditions?



I paste some information that I think is important.

vla-1.C.005t.original:

The original line 12 is 
__builtin___ubsan_handle_vla_bound_not_positive (&*.Lubsan_data0, (unsigned
long) ((ssizetype) SAVE_EXPR <i>));

The current is
__builtin___ubsan_handle_vla_bound_not_positive (&*.Lubsan_data0, (unsigned
long) (((ssizetype) SAVE_EXPR <i> - 1) + 1));


vla-1.C.006t.gimple
original:
 22       i.0 = i;
 23       if (i.0 <= 0) goto <D.3270>; else goto <D.3271>;
 24       <D.3270>:
 25       _1 = (unsigned long) i.0;
 26       __builtin___ubsan_handle_vla_bound_not_positive (&*.Lubsan_data0,
_1);
 27       goto <D.3272>;
 28       <D.3271>:
 29       <D.3272>:
 30       _2 = (ssizetype) i.0;
 31       _3 = _2 - 1;

current:
 22       i.0 = i;
 23       if (i.0 <= 0) goto <D.3270>; else goto <D.3271>;
 24       <D.3270>:
 25       _1 = (ssizetype) i.0;
 26       _2 = _1 - 1;
 27       _3 = _2 + 1;
 28       _4 = (unsigned long) _3;
 29       __builtin___ubsan_handle_vla_bound_not_positive (&*.Lubsan_data0,
_4);
 30       goto <D.3272>;
 31       <D.3271>:
 32       <D.3272>:
 33       _5 = _1 - 1;


vla-1.C.015t.cfg
original:
 37   int i.0;
 38
 39   <bb 2> :
 40   saved_stack.5 = __builtin_stack_save ();
 41   i.0 = i;
 42   if (i.0 <= 0)
 43     goto <bb 3>; [INV]
 44   else
 45     goto <bb 4>; [INV]
 46
 47   <bb 3> :
 48   _1 = (unsigned long) i.0;
 49   __builtin___ubsan_handle_vla_bound_not_positive (&*.Lubsan_data0, _1);
 50
 51   <bb 4> :
 52   _2 = (ssizetype) i.0;
 53   _3 = _2 - 1;

current:
 37   int i.0;
 38
 39   <bb 2> :
 40   saved_stack.5 = __builtin_stack_save ();
 41   i.0 = i;
 42   if (i.0 <= 0)
 43     goto <bb 3>; [INV]
 44   else
 45     goto <bb 4>; [INV]
 46
 47   <bb 3> :
 48   _1 = (ssizetype) i.0;
 49   _2 = _1 - 1;
 50   _3 = _2 + 1;
 51   _4 = (unsigned long) _3;
 52   __builtin___ubsan_handle_vla_bound_not_positive (&*.Lubsan_data0, _4);
 53
 54   <bb 4> :
 55   _5 = _1 - 1;
 56   _6 = (sizetype) _5;
 57   D.3273 = _6;

      parent reply	other threads:[~2024-04-17  1:50 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-12  2:22 [Bug c/114700] New: Front-end optimization generates wrong code with -ftrapv lin1.hu at intel dot com
2024-04-12  2:34 ` [Bug middle-end/114700] " pinskia at gcc dot gnu.org
2024-04-12  2:47 ` lin1.hu at intel dot com
2024-04-12  2:47 ` lin1.hu at intel dot com
2024-04-12  3:21 ` pinskia at gcc dot gnu.org
2024-04-12  3:26 ` pinskia at gcc dot gnu.org
2024-04-12  3:35 ` pinskia at gcc dot gnu.org
2024-04-12  3:53 ` lin1.hu at intel dot com
2024-04-12  3:56 ` lin1.hu at intel dot com
2024-04-12  5:56 ` rguenth at gcc dot gnu.org
2024-04-12  6:33 ` [Bug middle-end/114700] Front-end optimization generates wrong code with -fsanitize=undefined xry111 at gcc dot gnu.org
2024-04-12  6:44 ` lin1.hu at intel dot com
2024-04-12  7:12 ` lin1.hu at intel dot com
2024-04-12  7:14 ` xry111 at gcc dot gnu.org
2024-04-12  8:51 ` lin1.hu at intel dot com
2024-04-12 10:15 ` [Bug middle-end/114700] middle-end " jakub at gcc dot gnu.org
2024-04-12 10:25 ` jakub at gcc dot gnu.org
2024-04-15  3:43 ` [Bug middle-end/114700] middle-end optimization generates causes -fsanitize=undefined not to happen in some cases lin1.hu at intel dot com
2024-04-15  6:49 ` jakub at gcc dot gnu.org
2024-04-15  7:44 ` lin1.hu at intel dot com
2024-04-17  1:50 ` lin1.hu at intel dot com [this message]

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=bug-114700-4-W1cEg5Eoes@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).