This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] relax -Wsizeof-pointer-memaccess for strncpy with size of source (PR 85931)


On Wed, Jun 13, 2018 at 10:22:29AM +0200, Jakub Jelinek wrote:
> Random testcase for -Wduplicated-branches -fsanitize=shift:
> int
> foo (int x, int y)
> {
>   if (x)
>     y = y << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1
>           << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1
>           << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1
>           << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1;
>   else
>     y = y << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1
>           << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1
>           << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1
>           << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1 << 1 >> 1;
>   return y;
> }
> 
> Though it seems we have that problem already in inchash::add_expr.  In that
> case perhaps we could have a pointer to a hashmap in inchash::hash objects,
> clear it in the ctors and destroy/clear in inchash::hash::end (), though we
> have the add_commutative that has two separate hash objects.

It isn't specific to just -fsanitize=undefined, even without that there are
cases we can end up with lots of nested SAVE_EXPRs, like
-Wduplicated-branches:
int bar (void);

void
foo (int x, int *y)
{
  if (x)
    y[0] += (y[1] += (y[2] += (y[3] += (y[4] += (y[5] += (y[6] += (y[7] += (y[8] +=
	    (y[9] += (y[10] += (y[11] += (y[12] += (y[13] += (y[14] += (y[15] += (y[16] +=
	    (y[17] += (y[18] += (y[19] += (y[20] += (y[21] += (y[22] += (y[23] += (y[24] +=
	    (y[25] += (y[26] += (y[27] += (y[28] += (y[29] += (y[30] += (y[31] += (y[32] +=
	    (y[33] += (y[34] += (y[35] += (y[36] += (y[37] += (y[38] += (y[39] += (y[40] +=
	    (y[41] += (y[42] += (y[43] += (y[44] += (y[45] += (y[46] += (y[47] += (y[48] +=
	    (y[49] += (y[50] += (y[51] += (y[52] += (y[53] += (y[54] += (y[55] += (y[56] +=
	    (y[57] += (y[58] += (y[59] += (y[60] += (y[61] += (y[62] += (y[63] += (y[64] += bar ()
	    ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))));
  else
    y[0] += (y[1] += (y[2] += (y[3] += (y[4] += (y[5] += (y[6] += (y[7] += (y[8] +=
	    (y[9] += (y[10] += (y[11] += (y[12] += (y[13] += (y[14] += (y[15] += (y[16] +=
	    (y[17] += (y[18] += (y[19] += (y[20] += (y[21] += (y[22] += (y[23] += (y[24] +=
	    (y[25] += (y[26] += (y[27] += (y[28] += (y[29] += (y[30] += (y[31] += (y[32] +=
	    (y[33] += (y[34] += (y[35] += (y[36] += (y[37] += (y[38] += (y[39] += (y[40] +=
	    (y[41] += (y[42] += (y[43] += (y[44] += (y[45] += (y[46] += (y[47] += (y[48] +=
	    (y[49] += (y[50] += (y[51] += (y[52] += (y[53] += (y[54] += (y[55] += (y[56] +=
	    (y[57] += (y[58] += (y[59] += (y[60] += (y[61] += (y[62] += (y[63] += (y[64] += bar ()
	    ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))));
}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]