public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Gary Oblock <gary@amperecomputing.com>
To: "gcc@gcc.gnu.org" <gcc@gcc.gnu.org>
Subject: A problem with field decl offsets in newly minted types
Date: Thu, 31 Dec 2020 07:00:18 +0000	[thread overview]
Message-ID: <BYAPR01MB54645B52C3F0ADECAD36DE6BC6D60@BYAPR01MB5464.prod.exchangelabs.com> (raw)

I'm having some grief with creating/using some modified types.

I problem occurs in tree-ssa-sccvn.c when some code tries
to take a DECL_FIELD_OFFSET and unfortuenately gets a null
that causes a crash.

So, I traced this back the to types I created. Note, the method I used
has seemed to be fairly robust (some other engineers in our China
group even successfully copied it for thier own optimization.)
However, the DECL_FIELD_OFFSET offset is definitely null for
the fields which I created in the new versions of the types.

Here is what I'm doing.

    tree type_prime = lang_hooks.types.make_type (RECORD_TYPE);

    const char *base_type_name =
      identifier_to_locale ( IDENTIFIER_POINTER ( TYPE_NAME ( type)));
    size_t len = strlen ( MY_PREFIX) + strlen ( base_type_name);
    char *rec_name = ( char*)alloca ( len + 1);
    strcpy ( rec_name, MY_PREFIX);
    strcat ( rec_name, base_type_name);

    TYPE_NAME ( reorg_type_prime) = get_identifier ( rec_name);

    tree field;
    tree new_fields = NULL;
    for ( field = TYPE_FIELDS ( type); field; field = DECL_CHAIN ( field))
      {
        // Probably useful in creating the new field type.
        tree old_fld_type = TREE_TYPE ( field);

        // Whatever you want the new field type to be
        tree new_fld_type = ...;
        tree new_decl =
          build_decl ( DECL_SOURCE_LOCATION (field),
                              FIELD_DECL, DECL_NAME (field), new_fld_type);
         DECL_CONTEXT ( new_decl) = type_prime;
         layout_decl ( new_decl, 0);
         DECL_CHAIN ( new_decl) = new_fields;
         new_fields = new_decl;
      }

    TYPE_FIELDS ( type_prime) = nreverse ( new_fields);
    layout_type ( type_prime);

Note, when I change any declaration to have a modified type
I run relayout_decl on them.

If somebody could please tell what bit I'm missing or what I'm doing
wrong I'd really appreciate it. Looking at the code in layout_type,
it should be setting the decl field offsets with place_field and I
don't have a clue what's going on.

Thanks,

Gary


CONFIDENTIALITY NOTICE: This e-mail message, including any attachments, is for the sole use of the intended recipient(s) and contains information that is confidential and proprietary to Ampere Computing or its subsidiaries. It is to be used solely for the purpose of furthering the parties' business relationship. Any unauthorized review, copying, or distribution of this email (or any attachments thereto) is strictly prohibited. If you are not the intended recipient, please contact the sender immediately and permanently delete the original and any copies of this email and any attachments thereto.

             reply	other threads:[~2020-12-31  7:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-31  7:00 Gary Oblock [this message]
2021-01-01 21:14 ` Gary Oblock
2021-01-04 13:59   ` Richard Biener

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=BYAPR01MB54645B52C3F0ADECAD36DE6BC6D60@BYAPR01MB5464.prod.exchangelabs.com \
    --to=gary@amperecomputing.com \
    --cc=gcc@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).