From: Richard Biener <rguenther@suse.de>
To: Qing Zhao <qing.zhao@oracle.com>
Cc: Martin Jambor <mjambor@suse.cz>, Jakub Jelinek <jakub@redhat.com>,
Kees Cook <keescook@chromium.org>,
Nick Alcock via Gcc-patches <gcc-patches@gcc.gnu.org>,
Richard Biener <richard.guenther@gmail.com>
Subject: Re: [patch][version 6] add -ftrivial-auto-var-init and variable attribute "uninitialized" to gcc
Date: Tue, 10 Aug 2021 17:22:36 +0200 (CEST) [thread overview]
Message-ID: <nycvar.YFH.7.76.2108101720010.11781@zhemvz.fhfr.qr> (raw)
In-Reply-To: <B3B236CC-A596-4A2E-A5B8-F0DE70D265D6@oracle.com>
On Tue, 10 Aug 2021, Qing Zhao wrote:
> Hi,
>
> > On Aug 10, 2021, at 9:16 AM, Richard Biener <rguenther@suse.de> wrote:
> >
> > On Tue, 10 Aug 2021, Qing Zhao wrote:
> >
> >>>>>
> >>>>> +static void
> >>>>> +expand_DEFERRED_INIT (internal_fn, gcall *stmt)
> >>>>> +{
> >>>>> + tree var = gimple_call_lhs (stmt);
> >>>>> + tree size_of_var = gimple_call_arg (stmt, 0);
> >>>>> + tree vlaaddr = NULL_TREE;
> >>>>> + tree var_type = TREE_TYPE (var);
> >>>>> + bool is_vla = (bool) TREE_INT_CST_LOW (gimple_call_arg (stmt, 2));
> >>>>> + enum auto_init_type init_type
> >>>>> + = (enum auto_init_type) TREE_INT_CST_LOW (gimple_call_arg (stmt, 1));
> >>>>> +
> >>>>> + gcc_assert (init_type > AUTO_INIT_UNINITIALIZED);
> >>>>> +
> >>>>> + /* if this variable is a VLA, get its SIZE and ADDR first. */
> >>>>> + if (is_vla)
> >>>>> + {
> >>>>> + /* The temporary address variable for this vla should have been
> >>>>> + created during gimplification phase. Refer to gimplify_vla_decl
> >>>>> + for details. */
> >>>>> + tree var_decl = (TREE_CODE (var) == SSA_NAME) ?
> >>>>> + SSA_NAME_VAR (var) : var;
> >>>>> + gcc_assert (DECL_HAS_VALUE_EXPR_P (var_decl));
> >>>>> + gcc_assert (TREE_CODE (DECL_VALUE_EXPR (var_decl)) ==
> >>>>> INDIRECT_REF);
> >>>>> + /* Get the address of this vla variable. */
> >>>>> + vlaaddr = TREE_OPERAND (DECL_VALUE_EXPR (var_decl), 0);
> >>>>>
> >>>>> err - isn't the address of the decl represented by the LHS
> >>>>> regardless whether this is a VLA or not?
> >>>>
> >>>> The LHS of the call to .DEFERRED_INIT is the DECL itself whatever it’s a VLA or not.
> >>>>
> >>>> In order to create a memset call, we need the Address of this DECL as the first argument.
> >>>> If the DECL is not a VLA, we just simply apply “build_fold_addr_expr” on this DECL to get its address,
> >>>> However, for VLA, during gimplification phase “gimplify_vla_decl”, we have already created a temporary
> >>>> address variable for this DECL, and recorded this address variable with “DECL_VALUE_EXPR(DECL),
> >>>> We should use this already created address variable for VLAs.
> >>>
> >>> So the issue is that the LHS of the .DEFERRED_INIT call is not properly
> >>> gimplified. We should not have such decl there but I see we do not
> >>> have IL verification that covers this.
> >>
> >> Don’t quite understand here: do you mean all the LHS of .DEFERRED_INIT call are not properly gimplified, or
> >> Only the LHS of .DEFERRED_INIT call for VLA are not properly gimplified?
> >
> > Especially in the VLA case but likely also in general (though unlikely
> > since usually the receiver of initializations are simple enough). I'd
> > expect the VLA case end up as
> >
> > *ptr_to_decl = .DEFERRED_INIT (...);
> >
> > where *ptr_to_decl is the DECL_VALUE_EXPR of the decl.
>
> So, for the following small testing case:
>
> ====
> extern void bar (int);
>
> void foo(int n)
> {
> int arr[n];
> bar (arr[2]);
> return;
> }
> =====
>
> If I compile it with -ftrivial-auto-var-init=zero -fdump-tree-gimple -S -o auto-init-11.s -fdump-rtl-expand, the *.gimple dump is:
>
> =====
> void foo (int n)
> {
> int n.0;
> sizetype D.1950;
> bitsizetype D.1951;
> sizetype D.1952;
> bitsizetype D.1953;
> sizetype D.1954;
> int[0:D.1950] * arr.1;
> void * saved_stack.2;
> int arr[0:D.1950] [value-expr: *arr.1];
>
> saved_stack.2 = __builtin_stack_save ();
> try
> {
> n.0 = n;
> _1 = (long int) n.0;
> _2 = _1 + -1;
> _3 = (sizetype) _2;
> D.1950 = _3;
> _4 = (sizetype) n.0;
> _5 = (bitsizetype) _4;
> _6 = _5 * 32;
> D.1951 = _6;
> _7 = (sizetype) n.0;
> _8 = _7 * 4;
> D.1952 = _8;
> _9 = (sizetype) n.0;
> _10 = (bitsizetype) _9;
> _11 = _10 * 32;
> D.1953 = _11;
> _12 = (sizetype) n.0;
> _13 = _12 * 4;
> D.1954 = _13;
> arr.1 = __builtin_alloca_with_align (D.1954, 32);
> arr = .DEFERRED_INIT (D.1952, 2, 1);
> _14 = (*arr.1)[2];
> bar (_14);
> return;
> }
> finally
> {
> __builtin_stack_restore (saved_stack.2);
> }
> }
>
> ====
>
> You think that the above .DEFEERED_INIT is not correct?
> It should be:
>
> *arr.1 = .DEFERRED_INIT (D.1952. 2, 1);
>
> ?
Yes.
> >
> >> What do you mean by “such” decl? A decl whole “DECL_VALUE_EXPR(DECL)” is valid?
> >
> > A 'decl' that has a DECL_VALUE_EXPR should not appear in the IL, it should
> > always be refered to as its DECL_VALUE_EXPR.
>
> Okay.
I'm going to test
diff --git a/gcc/tree-ssa-operands.c b/gcc/tree-ssa-operands.c
index ebf7eea3b04..15c73b6d6f4 100644
--- a/gcc/tree-ssa-operands.c
+++ b/gcc/tree-ssa-operands.c
@@ -799,10 +799,11 @@ operands_scanner::get_expr_operands (tree *expr_p,
int flags)
flags | opf_not_non_addressable |
opf_address_taken);
return;
- case SSA_NAME:
case VAR_DECL:
case PARM_DECL:
case RESULT_DECL:
+ gcc_checking_assert (!DECL_HAS_VALUE_EXPR_P (expr));
+ case SSA_NAME:
case STRING_CST:
case CONST_DECL:
if (!(flags & opf_address_taken))
which should pass on unmodified trunk (fingers crossing ;)), but
it would likely trip on the current -ftrivial-auto-init patch.
The issue with the current IL is that nothing keeps arr.1 live
and thus the allocation could be DCEd but the .DEFERRED_INIT
call would remain, eventually being expanded to zero storage
that isn't there.
Richard.
next prev parent reply other threads:[~2021-08-10 15:22 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-27 3:26 Qing Zhao
2021-07-28 20:21 ` Kees Cook
2021-07-28 21:53 ` Qing Zhao
2021-08-09 14:09 ` Richard Biener
2021-08-09 16:38 ` Qing Zhao
2021-08-09 17:14 ` Richard Biener
2021-08-10 7:36 ` Richard Biener
2021-08-10 13:39 ` Qing Zhao
2021-08-10 14:16 ` Richard Biener
2021-08-10 15:02 ` Qing Zhao
2021-08-10 15:22 ` Richard Biener [this message]
2021-08-10 15:55 ` Qing Zhao
2021-08-10 20:16 ` Qing Zhao
2021-08-10 22:26 ` Qing Zhao
2021-08-11 7:02 ` Richard Biener
2021-08-11 13:33 ` Qing Zhao
2021-08-11 13:37 ` Richard Biener
2021-08-11 13:54 ` Qing Zhao
2021-08-11 13:58 ` Richard Biener
2021-08-11 14:00 ` Qing Zhao
2021-08-11 15:30 ` Qing Zhao
2021-08-11 15:53 ` Richard Biener
2021-08-11 16:22 ` Qing Zhao
2021-08-11 16:55 ` Richard Biener
2021-08-11 16:57 ` Qing Zhao
2021-08-11 20:30 ` Qing Zhao
2021-08-11 22:03 ` Qing Zhao
2021-08-16 7:12 ` Richard Biener
2021-08-16 14:48 ` Qing Zhao
2021-08-16 15:08 ` Richard Biener
2021-08-16 15:39 ` Qing Zhao
2021-08-16 7:11 ` Richard Biener
2021-08-16 16:48 ` Qing Zhao
2021-08-17 15:04 ` Qing Zhao
2021-08-17 20:40 ` Qing Zhao
2021-08-18 7:19 ` Richard Biener
2021-08-18 14:39 ` Qing Zhao
2021-08-11 9:02 ` Richard Sandiford
2021-08-11 13:44 ` Qing Zhao
2021-08-11 16:15 ` Richard Sandiford
2021-08-11 16:29 ` Qing Zhao
2021-08-12 19:24 ` Qing Zhao
2021-08-12 22:45 ` Qing Zhao
2021-08-16 7:40 ` Richard Biener
2021-08-16 15:45 ` Qing Zhao
2021-08-17 8:29 ` Richard Biener
2021-08-17 14:50 ` Qing Zhao
2021-08-17 16:08 ` Qing Zhao
2021-08-18 7:15 ` Richard Biener
2021-08-18 16:02 ` Qing Zhao
2021-08-19 9:00 ` Richard Biener
2021-08-19 13:54 ` Qing Zhao
2021-08-20 14:52 ` Qing Zhao
2021-08-23 13:55 ` Richard Biener
2021-09-02 17:24 ` Qing Zhao
2021-08-16 19:49 ` Qing Zhao
2021-08-17 8:43 ` Richard Biener
2021-08-17 14:03 ` Qing Zhao
2021-08-17 14:45 ` Richard Biener
2021-08-17 14:53 ` Qing Zhao
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=nycvar.YFH.7.76.2108101720010.11781@zhemvz.fhfr.qr \
--to=rguenther@suse.de \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
--cc=keescook@chromium.org \
--cc=mjambor@suse.cz \
--cc=qing.zhao@oracle.com \
--cc=richard.guenther@gmail.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).