public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Qing Zhao <qing.zhao@oracle.com>
To: Richard Sandiford <richard.sandiford@arm.com>
Cc: Richard Biener <rguenther@suse.de>,
	Kees Cook <keescook@chromium.org>,
	Gcc-patches Qing Zhao via <gcc-patches@gcc.gnu.org>
Subject: Re: [patch for gcc12 stage1][version 2] add -ftrivial-auto-var-init and variable attribute "uninitialized" to gcc
Date: Wed, 5 May 2021 09:41:42 -0500	[thread overview]
Message-ID: <0A50A5F3-9F17-4F4D-85A8-F59FF31BD58E@oracle.com> (raw)
In-Reply-To: <mptzgxokeiu.fsf@arm.com>

Hi, Richard, 

During the change for the 2nd version based on your previous comments, I have the following questions need your help:

> 
>> +	  sra_stats.subtree_deferred_init++;
>> +	}
>> +      else if (access->grp_to_be_debug_replaced)
>> +	{
>> +	  /* FIXME, this part might have some issue.  */
>> +	  tree drhs = build_debug_ref_for_model (loc, agg,
>> +						 access->offset - top_offset,
>> +						 access);
>> +	  gdebug *ds = gimple_build_debug_bind (get_access_replacement (access),
>> +						drhs, gsi_stmt (*gsi));
>> +	  gsi_insert_before (gsi, ds, GSI_SAME_STMT);
> 
> Would be good to fix the FIXME :-)
> 
> I guess the thing we need to decide here is whether -ftrivial-auto-var-init
> should affect debug-only constructs too.  If it doesn't, exmaining removed
> components in a debugger might show uninitialised values in cases where
> the user was expecting initialised ones.  There would be no security
> concern, but it might be surprising.
> 
> I think in principle the DRHS can contain a call to DEFERRED_INIT.
> Doing that would probably require further handling elsewhere though.

Right now, what I did is:

  else if (lhs_access->grp_to_be_debug_replaced)
    {
      tree lhs_drepl = get_access_replacement (lhs_access);
      tree init_type_node
           = build_int_cst (integer_type_node, (int) init_type);
      tree call = build_call_expr_internal_loc
                  (UNKNOWN_LOCATION, IFN_DEFERRED_INIT,
                  TREE_TYPE (lhs_drepl), 2, lhs_drepl, init_type_node);
      gdebug *ds = gimple_build_debug_bind (lhs_drepl, call,
                                            gsi_stmt (*gsi));
      gsi_insert_before (gsi, ds, GSI_SAME_STMT);
    }

Is the above matching what you suggested?

What do you mean by “further handling elsewhere”?

> 
>> +	 is better even for pattern initialization.  */
>> +      return build_int_cstu (type, largevalue);
> 
> I've no objection to that choice for booleans, but: booleans in some
> languages (like Ada) can have multibit precision.  If we want booleans
> to be zero then it would probably be better to treat them as a separate
> case and just use build_zero_cst (type) for them.
> 
> Also, the above won't work correctly for 128-bit integers: it will
> zero-initialize the upper half.  It would probably be better to use
> wi::from_buffer to construct the integer instead.

You mean using wi::from_buffer to construct all the integer type (including 64-bit, 32-bit, etc.)?

I read the corresponding source codes related to “wi::from_buffer”, but still not very clear
On how to use it for my purpose,

From my current understanding, I should use it like the following:

"

unsigned char *ptr = “0xAAAAAAAAAAAAAAAA”;

Int total_bytes = GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (type));
wide_int result = wi::from_buffer (ptr, total_bytes);
return wide_int_to_tree (type, result);

“

Is the above correct for INTEGER type?

thanks.

Qing

      parent reply	other threads:[~2021-05-05 14:41 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-24 21:21 Qing Zhao
2021-04-07 14:44 ` Qing Zhao
2021-04-07 22:19 ` Kees Cook
2021-04-08 15:22   ` Qing Zhao
2021-04-23 19:05 ` Richard Sandiford
2021-04-23 19:33   ` Kees Cook
2021-04-26 15:09   ` Qing Zhao
2021-04-26 17:47     ` Richard Sandiford
2021-04-26 20:02       ` Qing Zhao
2021-04-27  6:30       ` Richard Biener
2021-04-27 15:10         ` Qing Zhao
2021-05-05 17:29     ` Qing Zhao
2021-05-05 14:41   ` Qing Zhao [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=0A50A5F3-9F17-4F4D-85A8-F59FF31BD58E@oracle.com \
    --to=qing.zhao@oracle.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=keescook@chromium.org \
    --cc=rguenther@suse.de \
    --cc=richard.sandiford@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).