Resolve the TODO in fold_builtin_strlen

Message ID VI1PR0701MB28621D0A535ACAA27571A1B0E4190@VI1PR0701MB2862.eurprd07.prod.outlook.com
State New
Headers show
Series
  • Resolve the TODO in fold_builtin_strlen
Related show

Commit Message

Bernd Edlinger Sept. 14, 2018, 7:51 p.m.
Hi,

this resolves the TODO I left in fold_builtin_strlen by adding some test cases
that fail without the c_strlen call with the TODO comment and pass when the
additional c_strlen call is done.


Bootstrapped and reg-tested on x86_64-pc-linux-gnu.
Is it OK for trunk?


Thanks
Bernd.

Comments

Jeff Law Sept. 14, 2018, 8:30 p.m. | #1
On 9/14/18 1:51 PM, Bernd Edlinger wrote:
> Hi,

> 

> this resolves the TODO I left in fold_builtin_strlen by adding some test cases

> that fail without the c_strlen call with the TODO comment and pass when the

> additional c_strlen call is done.

> 

> 

> Bootstrapped and reg-tested on x86_64-pc-linux-gnu.

> Is it OK for trunk?

> 

> 

> Thanks

> Bernd.

> 

> 

> patch-fix-todo.diff

> 

> 2018-09-14  Bernd Edlinger  <bernd.edlinger@hotmail.de>

> 

> 	* builtins.c (fold_builtin_strlen): Remove TODO comment.

> 

> testsuite:

> 2018-09-14  Bernd Edlinger  <bernd.edlinger@hotmail.de>

> 

> 	* gcc.dg/warn-strlen-no-nul.c: Add some missing test cases.

OK.
jeff

Patch

2018-09-14  Bernd Edlinger  <bernd.edlinger@hotmail.de>

	* builtins.c (fold_builtin_strlen): Remove TODO comment.

testsuite:
2018-09-14  Bernd Edlinger  <bernd.edlinger@hotmail.de>

	* gcc.dg/warn-strlen-no-nul.c: Add some missing test cases.


diff -Npur gcc/builtins.c gcc/builtins.c
--- gcc/builtins.c	2018-08-30 08:21:13.000000000 +0200
+++ gcc/builtins.c	2018-08-30 21:46:11.155211333 +0200
Index: gcc/builtins.c
===================================================================
--- gcc/builtins.c	(revision 264318)
+++ gcc/builtins.c	(working copy)
@@ -8417,7 +8417,7 @@  fold_builtin_strlen (location_t loc, tree type, tr
 	return fold_convert_loc (loc, type, len);
 
       if (!nonstr)
-	c_strlen (arg, 1, &nonstr); /* TODO: add test coverage here.  */
+	c_strlen (arg, 1, &nonstr);
 
       if (nonstr)
 	{
Index: gcc/testsuite/gcc.dg/warn-strlen-no-nul.c
===================================================================
--- gcc/testsuite/gcc.dg/warn-strlen-no-nul.c	(revision 264318)
+++ gcc/testsuite/gcc.dg/warn-strlen-no-nul.c	(working copy)
@@ -9,6 +9,7 @@  const char a[5] = "12345";   /* { dg-message "decl
 
 int v0 = 0;
 int v1 = 1;
+volatile int v2;
 
 void sink (int, ...);
 
@@ -117,10 +118,8 @@  T (v0 ? b[i0] : &b[i3][i0] + i1);    /* { dg-warni
 T (v0 ? b[i0] : &b[i3][i0] + i1);    /* { dg-warning "nul" }  */
 T (v0 ? b[i1] : &b[i3][i1] + v0);    /* { dg-warning "nul" }  */
 
-/* It's possible to detect the missing nul in the following two
-   expressions but GCC doesn't do it yet.  */
-T (v0 ? &b[3][1] + v0 : b[2]);    /* { dg-warning "nul" "bug" }  */
-T (v0 ? &b[3][v0] : &b[3][v1]);   /* { dg-warning "nul" "bug" }  */
+T (v0 ? &b[3][1] + v0 : b[2]);    /* { dg-warning "nul" }  */
+T (v0 ? &b[3][v0] : &b[3][v1]);   /* { dg-warning "nul" }  */
 
 
 struct A { char a[5], b[5]; };
@@ -299,3 +298,7 @@  T (v0 ? &ba[3].a[1].a[1] :  ba[0].a[0].a);      /*
 
 T (v0 ? ba[0].a[0].a : ba[0].a[1].b);
 T (v0 ? ba[0].a[1].b : ba[0].a[0].a);
+
+T (v2 ? b[1] : &b[3][1] + v2);    /* { dg-warning "nul" }  */
+T (v2 ? &b[3][1] + v2 : b[2]);    /* { dg-warning "nul" }  */
+T (v2 ? &b[3][v2] : &b[2][v2]);   /* { dg-warning "nul" }  */