Patchwork Add __stpncpy_chk builtin support

login
register
mail settings
Submitter Jakub Jelinek
Date Dec. 8, 2011, 6:09 p.m.
Message ID <20111208180955.GN1957@tyan-ft48-01.lab.bos.redhat.com>
Download mbox | patch
Permalink /patch/130209/
State New
Headers show

Comments

Jakub Jelinek - Dec. 8, 2011, 6:09 p.m.
On Mon, Nov 28, 2011 at 12:16:52PM +0100, Romain Geissler wrote:
> 2011-11-28  Romain Geissler  <romain.geissler@gmail.com>
> 
> 	* builtins.def (BUILT_IN_STPNCPY_CHK): New definition.
> 	* builtins.c (expand_builtin, fold_builtin_4, maybe_emit_chk_warning):
> 	Add BUILT_IN_STPNCPY_CHK case.
> 	* gimple-fold.c (gimple_fold_builtin): Likewise.
> 	* tree-object-size.c (pass_through_call): Likewise.
> 	* tree-ssa-alias.c (ref_maybe_used_by_call_p_1,
> 	call_may_clobber_ref_p_1): Likewise.
> 	* tree-ssa-structalias.c (find_func_aliases_for_builtin_call,
> 	find_func_clobbers): Likewise.
> 	* tree.h (fold_builtin_strncpy_chk): Rename to fold_builtin_stxncpy_chk
> 	* builtins.c (fold_builtin_strncpy_chk): Likewise.
> 	Rewrite stpncpy_chk calls to strncpy_chk calls if returned value is
> 	ignored.
> 
> gcc/testsuite/
> 
> 2011-11-28  Romain Geissler  <romain.geissler@gmail.com>
> 
> 	* gcc.c-torture/execute/builtins/chk.h (stpncpy, stpncpy_disallowed):
> 	New definitions.
> 	* gcc.c-torture/execute/builtins/lib/chk.c (stpncpy_disallowed):
> 	Likewise.
> 	(stpncpy, __stpncpy_chk): New functions.
> 	* gcc.c-torture/execute/builtins/stpncpy-chk-lib.c: New file.
> 	* gcc.c-torture/execute/builtins/stpncpy-chk.c: Likewise.
> 

This is ok for trunk, if you fix formatting nits mentioned below:

@@ -10910,7 +10911,8 @@ fold_builtin_4 (location_t loc, tree fndecl,
 				      DECL_FUNCTION_CODE (fndecl));
 
     case BUILT_IN_STRNCPY_CHK:
-      return fold_builtin_strncpy_chk (loc, arg0, arg1, arg2, arg3, NULL_TREE);
+    case BUILT_IN_STPNCPY_CHK:
+      return fold_builtin_stxncpy_chk (loc, arg0, arg1, arg2, arg3, NULL_TREE, ignore, fcode);

Please watch formatting, this line is too long.
 
     case BUILT_IN_STRNCAT_CHK:
       return fold_builtin_strncat_chk (loc, fndecl, arg0, arg1, arg2, arg3);
@@ -12863,8 +12877,9 @@ fold_builtin_strncpy_chk (location_t loc, tree dest, tree src,
 	return NULL_TREE;
     }
 
-  /* If __builtin_strncpy_chk is used, assume strncpy is available.  */
-  fn = builtin_decl_explicit (BUILT_IN_STRNCPY);
+  /* If __builtin_st{r,p}ncpy_chk is used, assume st{r,p}ncpy is available.  */
+  fn = builtin_decl_explicit (fcode == BUILT_IN_STPNCPY_CHK
+         ? BUILT_IN_STPNCPY : BUILT_IN_STRNCPY);

"? BUILT_IN_STPNCPY" needs to be below "fcode == " on the previous line.

+	result = fold_builtin_stxncpy_chk (loc, gimple_call_arg (stmt, 0),
                                            gimple_call_arg (stmt, 1),
                                            gimple_call_arg (stmt, 2),
                                            gimple_call_arg (stmt, 3),
-					   val[2]);
+					   val[2],
+					   ignore,
+					  DECL_FUNCTION_CODE (callee));

Please put ignore, on the same line as val[2], and align DECL_FUNCTION_CODE
properly below val[2].

	Jakub
Romain Geissler - Dec. 15, 2011, 8:08 a.m.
Le 8 déc. 2011 à 19:09, Jakub Jelinek a écrit :

> On Mon, Nov 28, 2011 at 12:16:52PM +0100, Romain Geissler wrote:
>> 2011-11-28  Romain Geissler  <romain.geissler@gmail.com>
>> 
>> 	* builtins.def (BUILT_IN_STPNCPY_CHK): New definition.
>> 	* builtins.c (expand_builtin, fold_builtin_4, maybe_emit_chk_warning):
>> 	Add BUILT_IN_STPNCPY_CHK case.
>> 	* gimple-fold.c (gimple_fold_builtin): Likewise.
>> 	* tree-object-size.c (pass_through_call): Likewise.
>> 	* tree-ssa-alias.c (ref_maybe_used_by_call_p_1,
>> 	call_may_clobber_ref_p_1): Likewise.
>> 	* tree-ssa-structalias.c (find_func_aliases_for_builtin_call,
>> 	find_func_clobbers): Likewise.
>> 	* tree.h (fold_builtin_strncpy_chk): Rename to fold_builtin_stxncpy_chk
>> 	* builtins.c (fold_builtin_strncpy_chk): Likewise.
>> 	Rewrite stpncpy_chk calls to strncpy_chk calls if returned value is
>> 	ignored.
>> 
>> gcc/testsuite/
>> 
>> 2011-11-28  Romain Geissler  <romain.geissler@gmail.com>
>> 
>> 	* gcc.c-torture/execute/builtins/chk.h (stpncpy, stpncpy_disallowed):
>> 	New definitions.
>> 	* gcc.c-torture/execute/builtins/lib/chk.c (stpncpy_disallowed):
>> 	Likewise.
>> 	(stpncpy, __stpncpy_chk): New functions.
>> 	* gcc.c-torture/execute/builtins/stpncpy-chk-lib.c: New file.
>> 	* gcc.c-torture/execute/builtins/stpncpy-chk.c: Likewise.
>> 
> 
> This is ok for trunk, if you fix formatting nits mentioned below:
> 
> @@ -10910,7 +10911,8 @@ fold_builtin_4 (location_t loc, tree fndecl,
> 				      DECL_FUNCTION_CODE (fndecl));
> 
>     case BUILT_IN_STRNCPY_CHK:
> -      return fold_builtin_strncpy_chk (loc, arg0, arg1, arg2, arg3, NULL_TREE);
> +    case BUILT_IN_STPNCPY_CHK:
> +      return fold_builtin_stxncpy_chk (loc, arg0, arg1, arg2, arg3, NULL_TREE, ignore, fcode);
> 
> Please watch formatting, this line is too long.
> 
>     case BUILT_IN_STRNCAT_CHK:
>       return fold_builtin_strncat_chk (loc, fndecl, arg0, arg1, arg2, arg3);
> @@ -12863,8 +12877,9 @@ fold_builtin_strncpy_chk (location_t loc, tree dest, tree src,
> 	return NULL_TREE;
>     }
> 
> -  /* If __builtin_strncpy_chk is used, assume strncpy is available.  */
> -  fn = builtin_decl_explicit (BUILT_IN_STRNCPY);
> +  /* If __builtin_st{r,p}ncpy_chk is used, assume st{r,p}ncpy is available.  */
> +  fn = builtin_decl_explicit (fcode == BUILT_IN_STPNCPY_CHK
> +         ? BUILT_IN_STPNCPY : BUILT_IN_STRNCPY);
> 
> "? BUILT_IN_STPNCPY" needs to be below "fcode == " on the previous line.
> 
> +	result = fold_builtin_stxncpy_chk (loc, gimple_call_arg (stmt, 0),
>                                            gimple_call_arg (stmt, 1),
>                                            gimple_call_arg (stmt, 2),
>                                            gimple_call_arg (stmt, 3),
> -					   val[2]);
> +					   val[2],
> +					   ignore,
> +					  DECL_FUNCTION_CODE (callee));
> 
> Please put ignore, on the same line as val[2], and align DECL_FUNCTION_CODE
> properly below val[2].
> 
> --- gcc/tree.h
> +++ gcc/tree.h
> @@ -5444,7 +5444,8 @@ extern tree fold_builtin_memory_chk (location_t, tree, tree, tree, tree, tree, t
> 				     enum built_in_function);
> extern tree fold_builtin_stxcpy_chk (location_t, tree, tree, tree, tree, tree, bool,
> 				     enum built_in_function);
> -extern tree fold_builtin_strncpy_chk (location_t, tree, tree, tree, tree, tree);
> +extern tree fold_builtin_stxncpy_chk (location_t, tree, tree, tree, tree, tree, bool,
> +				     enum built_in_function);
> 
> "enum " should be aligned below "location_t,".
> 
> 	Jakub

Hi

Here is the patch with fixed coding style.
Can you please apply it, i don't have write access to the repository.

Romain Geissler

Patch

--- gcc/tree.h
+++ gcc/tree.h
@@ -5444,7 +5444,8 @@  extern tree fold_builtin_memory_chk (location_t, tree, tree, tree, tree, tree, t
 				     enum built_in_function);
 extern tree fold_builtin_stxcpy_chk (location_t, tree, tree, tree, tree, tree, bool,
 				     enum built_in_function);
-extern tree fold_builtin_strncpy_chk (location_t, tree, tree, tree, tree, tree);
+extern tree fold_builtin_stxncpy_chk (location_t, tree, tree, tree, tree, tree, bool,
+				     enum built_in_function);

"enum " should be aligned below "location_t,".