diff mbox series

[RFA] tree: Change error_operand_p to an inline function

Message ID 20210902144152.1039879-1-jason@redhat.com
State New
Headers show
Series [RFA] tree: Change error_operand_p to an inline function | expand

Commit Message

Jason Merrill Sept. 2, 2021, 2:41 p.m. UTC
I've thought for a while that many of the macros in tree.h and such should
become inline functions.  This one in particular was confusing Coverity; the
null check in the macro made it think that all code guarded by
error_operand_p would also need null checks.

Tested x86_64-pc-linux-gnu.  OK for trunk?

---
 gcc/tree.h | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)


base-commit: 483e400870601f650c80f867ec781cd5f83507d6

Comments

Marek Polacek Sept. 2, 2021, 2:46 p.m. UTC | #1
On Thu, Sep 02, 2021 at 10:41:52AM -0400, Jason Merrill via Gcc-patches wrote:
> I've thought for a while that many of the macros in tree.h and such should
> become inline functions.  This one in particular was confusing Coverity; the
> null check in the macro made it think that all code guarded by
> error_operand_p would also need null checks.
> 
> Tested x86_64-pc-linux-gnu.  OK for trunk?

Please!  One nit:

> ---
>  gcc/tree.h | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/gcc/tree.h b/gcc/tree.h
> index 2c8973f34e2..5f27f02df9e 100644
> --- a/gcc/tree.h
> +++ b/gcc/tree.h
> @@ -4349,9 +4349,12 @@ tree_strip_any_location_wrapper (tree exp)
>  
>  /* True if NODE is an erroneous expression.  */

s/NODE/T/
  
> -#define error_operand_p(NODE)					\
> -  ((NODE) == error_mark_node					\
> -   || ((NODE) && TREE_TYPE ((NODE)) == error_mark_node))
> +inline bool
> +error_operand_p (const_tree t)
> +{
> +  return (t == error_mark_node
> +	  || (t && TREE_TYPE (t) == error_mark_node));
> +}
>  
>  /* Return the number of elements encoded directly in a VECTOR_CST.  */
>  
> 
> base-commit: 483e400870601f650c80f867ec781cd5f83507d6
> -- 
> 2.27.0
> 

Marek
diff mbox series

Patch

diff --git a/gcc/tree.h b/gcc/tree.h
index 2c8973f34e2..5f27f02df9e 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -4349,9 +4349,12 @@  tree_strip_any_location_wrapper (tree exp)
 
 /* True if NODE is an erroneous expression.  */
 
-#define error_operand_p(NODE)					\
-  ((NODE) == error_mark_node					\
-   || ((NODE) && TREE_TYPE ((NODE)) == error_mark_node))
+inline bool
+error_operand_p (const_tree t)
+{
+  return (t == error_mark_node
+	  || (t && TREE_TYPE (t) == error_mark_node));
+}
 
 /* Return the number of elements encoded directly in a VECTOR_CST.  */