Patchwork Quash undefined behavior in ipa-inline-analysis.c

login
register
mail settings
Submitter Marek Polacek
Date Aug. 13, 2013, 12:20 p.m.
Message ID <20130813122049.GQ17022@redhat.com>
Download mbox | patch
Permalink /patch/266783/
State New
Headers show

Comments

Marek Polacek - Aug. 13, 2013, 12:20 p.m.
When doing bootstrap with -fsanitize=undefined, I noticed undefined
behavior in this file.  We basically do 1 << 32, since NUM_CONDITIONS
is #defined to 32, which is not defined.  I admit I didn't followed
the algorithm at all, but this patch passed bootstrap + regtesting
on x86_64-linux.  So, ok for trunk?

2013-08-13  Marek Polacek  <polacek@redhat.com>

	* ipa-inline-analysis.c (add_clause): Avoid undefined behavior 
	when shifting integer.


	Marek
Jan Hubicka - Aug. 13, 2013, 10:47 p.m.
> When doing bootstrap with -fsanitize=undefined, I noticed undefined
> behavior in this file.  We basically do 1 << 32, since NUM_CONDITIONS
> is #defined to 32, which is not defined.  I admit I didn't followed
> the algorithm at all, but this patch passed bootstrap + regtesting
> on x86_64-linux.  So, ok for trunk?
> 
> 2013-08-13  Marek Polacek  <polacek@redhat.com>
> 
> 	* ipa-inline-analysis.c (add_clause): Avoid undefined behavior 
> 	when shifting integer.
OK, thanks!
Honza
> 
> --- gcc/ipa-inline-analysis.c.mp	2013-08-13 14:07:48.632662047 +0200
> +++ gcc/ipa-inline-analysis.c	2013-08-13 14:08:16.728770973 +0200
> @@ -337,7 +337,7 @@ add_clause (conditions conditions, struc
>           and thus there is no point for looking for them.  */
>        if (cc1->code == CHANGED || cc1->code == IS_NOT_CONSTANT)
>  	continue;
> -      for (c2 = c1 + 1; c2 <= NUM_CONDITIONS; c2++)
> +      for (c2 = c1 + 1; c2 < NUM_CONDITIONS; c2++)
>  	if (clause & (1 << c2))
>  	  {
>  	    condition *cc1 =
> 
> 	Marek

Patch

--- gcc/ipa-inline-analysis.c.mp	2013-08-13 14:07:48.632662047 +0200
+++ gcc/ipa-inline-analysis.c	2013-08-13 14:08:16.728770973 +0200
@@ -337,7 +337,7 @@  add_clause (conditions conditions, struc
          and thus there is no point for looking for them.  */
       if (cc1->code == CHANGED || cc1->code == IS_NOT_CONSTANT)
 	continue;
-      for (c2 = c1 + 1; c2 <= NUM_CONDITIONS; c2++)
+      for (c2 = c1 + 1; c2 < NUM_CONDITIONS; c2++)
 	if (clause & (1 << c2))
 	  {
 	    condition *cc1 =