This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Handle bit-fields in ubsan.c (PR sanitizer/58413)
- From: Marek Polacek <polacek at redhat dot com>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 20 Sep 2013 10:22:43 +0200
- Subject: Re: [PATCH] Handle bit-fields in ubsan.c (PR sanitizer/58413)
- Authentication-results: sourceware.org; auth=none
- References: <20130916155927 dot GD23899 at redhat dot com> <20130916160423 dot GS1817 at tucnak dot redhat dot com> <20130916161811 dot GE23899 at redhat dot com>
On Mon, Sep 16, 2013 at 06:18:11PM +0200, Marek Polacek wrote:
> On Mon, Sep 16, 2013 at 06:04:23PM +0200, Jakub Jelinek wrote:
> > On Mon, Sep 16, 2013 at 05:59:28PM +0200, Marek Polacek wrote:
> > > Regtested/ran bootstrap-ubsan on x86_64-linux.
> >
> > That looks wrong. ubsan_type_descriptor shouldn't change TYPE_PRECISION of
> > the type it has been called with, whether type is a bitfield or not can
> > change what typedescriptor is generated, but not unrelated code.
>
> Ok, that was weird. What about this one? We use the TYPE_SIZE precision
> if we're dealing with bit-fields, but don't change the type in any
> way.
>
> Ubsan testsuite passes...
>
> 2013-09-16 Marek Polacek <polacek@redhat.com>
>
> PR sanitizer/58413
> * ubsan.c (get_ubsan_type_info_for_type): For bit-fields, use the
> precision of its TYPE_SIZE.
Is this one ok? (With testcase from
http://gcc.gnu.org/ml/gcc-patches/2013-09/msg01212.html .)
> --- gcc/ubsan.c.mp 2013-09-16 18:13:01.075903156 +0200
> +++ gcc/ubsan.c 2013-09-16 18:13:20.514974154 +0200
> @@ -233,7 +233,13 @@ ubsan_source_location (location_t loc)
> static unsigned short
> get_ubsan_type_info_for_type (tree type)
> {
> - int prec = exact_log2 (TYPE_PRECISION (type));
> + int prec = TYPE_PRECISION (type);
> +
> + /* Handle bit-fields. */
> + if (compare_tree_int (TYPE_SIZE (type), prec) == 1)
> + prec = tree_low_cst (TYPE_SIZE (type), 1);
> +
> + prec = exact_log2 (prec);
> if (prec == -1)
> error ("unexpected size of type %qT", type);
Marek