diff mbox

[IPA] Check pointer for 0 before use in `get_odr_type`

Message ID 394ceee5-dfc2-f9a7-c534-7a09f222c2ab@gmail.com
State New
Headers show

Commit Message

Kirill Yukhin Sept. 2, 2016, 8:53 p.m. UTC
Hello,
Looks like `get_odr_type ()` contains code which dereferences
pointer before check it for zero. I moved the line under the check.

Bootstrap/regtest on x?86|x86_64 in progress.

Is it ok for trunk if pass?

gcc/
	* gcc/ipa-devirt.c (get_odr_type): Check odr_types_ptr for
	zero before dereferencing it.

--
Thanks, K

commit 9b822dfb4db14ce762a8d55cf76c677f3fae04bc
Author: Kirill Yukhin <kirill.yukhin@gmail.com>
Date:   Fri Sep 2 23:40:55 2016 +0300

     Access odr_type only if odr_type_ptr is not 0.

Comments

Jakub Jelinek Sept. 2, 2016, 8:56 p.m. UTC | #1
On Fri, Sep 02, 2016 at 11:53:01PM +0300, Kirill Yukhin wrote:
> Hello,
> Looks like `get_odr_type ()` contains code which dereferences
> pointer before check it for zero. I moved the line under the check.
> 
> Bootstrap/regtest on x?86|x86_64 in progress.
> 
> Is it ok for trunk if pass?
> 
> gcc/
> 	* gcc/ipa-devirt.c (get_odr_type): Check odr_types_ptr for
> 	zero before dereferencing it.

I've already tested/posted
http://gcc.gnu.org/ml/gcc-patches/2016-09/msg00089.html
for this.

	Jakub
Kirill Yukhin Sept. 2, 2016, 9:03 p.m. UTC | #2
On 02.09.2016 23:56, Jakub Jelinek wrote:
> On Fri, Sep 02, 2016 at 11:53:01PM +0300, Kirill Yukhin wrote:
>> gcc/
>> 	* gcc/ipa-devirt.c (get_odr_type): Check odr_types_ptr for
>> 	zero before dereferencing it.
>
> I've already tested/posted
> http://gcc.gnu.org/ml/gcc-patches/2016-09/msg00089.html
> for this.
Okay, disregard then.

--
Thanks, K

>
> 	Jakub
>
diff mbox

Patch

diff --git a/gcc/ipa-devirt.c b/gcc/ipa-devirt.c
index 2cf018b..cca912c 100644
--- a/gcc/ipa-devirt.c
+++ b/gcc/ipa-devirt.c
@@ -2132,12 +2132,14 @@  get_odr_type (tree type, bool insert)
      }
    else if (base_id > val->id)
      {
-      odr_types[val->id] = 0;
        /* Be sure we did not recorded any derived types; these may need
          renumbering too.  */
        gcc_assert (val->derived_types.length() == 0);
        if (odr_types_ptr)
-       val->id = odr_types.length ();
+       {
+         odr_types[val->id] = 0;
+         val->id = odr_types.length ();
+       }
        vec_safe_push (odr_types_ptr, val);
      }
    return val;