From: Richard Biener <rguenther@suse.de>
To: Jakub Jelinek <jakub@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] Fix ubsan type reporting (PR tree-optimization/65709)
Date: Thu, 09 Apr 2015 18:21:00 -0000 [thread overview]
Message-ID: <DB6E29F7-9B5B-4DCE-9ED6-D34C890D6D98@suse.de> (raw)
In-Reply-To: <20150409181122.GM19273@tucnak.redhat.com>
On April 9, 2015 8:11:22 PM GMT+02:00, Jakub Jelinek <jakub@redhat.com> wrote:
>Hi!
>
>As can be seen on the following testcase, instrument_mem_ref (for
>both -fsanitize=alignment and -fsanitize=null) has been using wrong
>type
>to find out what is the access type - instead of the type of MEM_REF
>which is the access type it was using the TREE_TYPE of MEM_REF's
>argument
>type, which can be some arbitrary other type, either due to type
>punning,
>or if it is a SSA_NAME it can be random other type because most pointer
>types are considered type compatible in GIMPLE.
>
>Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok
>for
>trunk?
OK.
Thanks,
Richard.
>2015-04-09 Jakub Jelinek <jakub@redhat.com>
>
> PR tree-optimization/65709
> * ubsan.c (instrument_mem_ref): Use TREE_TYPE (base) instead of
> TREE_TYPE (TREE_TYPE (t)).
>
> * c-c++-common/ubsan/align-9.c: New test.
>
>--- gcc/ubsan.c.jj 2015-03-27 10:48:33.000000000 +0100
>+++ gcc/ubsan.c 2015-04-09 10:05:48.841221438 +0200
>@@ -1232,9 +1232,9 @@ instrument_mem_ref (tree mem, tree base,
> tree t = TREE_OPERAND (base, 0);
> if (!POINTER_TYPE_P (TREE_TYPE (t)))
> return;
>- if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (TREE_TYPE (t))) && mem !=
>base)
>+ if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (base)) && mem != base)
> ikind = UBSAN_MEMBER_ACCESS;
>- tree kind = build_int_cst (TREE_TYPE (t), ikind);
>+ tree kind = build_int_cst (build_pointer_type (TREE_TYPE (base)),
>ikind);
> tree alignt = build_int_cst (pointer_sized_int_node, align);
>gcall *g = gimple_build_call_internal (IFN_UBSAN_NULL, 3, t, kind,
>alignt);
> gimple_set_location (g, gimple_location (gsi_stmt (*iter)));
>--- gcc/testsuite/c-c++-common/ubsan/align-9.c.jj 2015-04-09
>10:11:15.227973011 +0200
>+++ gcc/testsuite/c-c++-common/ubsan/align-9.c 2015-04-09
>10:13:16.857017169 +0200
>@@ -0,0 +1,21 @@
>+/* Limit this to known non-strict alignment targets. */
>+/* { dg-do run { target { i?86-*-linux* x86_64-*-linux* } } } */
>+/* { dg-options "-O2 -fsanitize=alignment
>-fsanitize-recover=alignment" } */
>+
>+__attribute__((noinline, noclone)) void
>+foo (void *p, const void *q)
>+{
>+ *(long int *) p = *(const long int *) q;
>+}
>+
>+int
>+main ()
>+{
>+ struct S { long c; char f[64]; char d; char e[2 * sizeof (long)];
>char g[64]; } s;
>+ __builtin_memset (&s, '\0', sizeof s);
>+ foo (&s.e[0], &s.e[sizeof (long)]);
>+ return 0;
>+}
>+
>+/* { dg-output "\.c:8:\[0-9]*: \[^\n\r]*load of misaligned address
>0x\[0-9a-fA-F]* for type 'const long int', which requires \[48] byte
>alignment.*" } */
>+/* { dg-output "\.c:8:\[0-9]*: \[^\n\r]*store to misaligned address
>0x\[0-9a-fA-F]* for type 'long int', which requires \[48] byte
>alignment" } */
>
> Jakub
prev parent reply other threads:[~2015-04-09 18:21 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-09 18:11 Jakub Jelinek
2015-04-09 18:21 ` Richard Biener [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=DB6E29F7-9B5B-4DCE-9ED6-D34C890D6D98@suse.de \
--to=rguenther@suse.de \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.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).