diff mbox series

[committed] d: Fix ICE in uda_attribute_p when looking up unknown attribute

Message ID 20200625153828.2304469-3-ibuclaw@gdcproject.org
State New
Headers show
Series [committed] d: Fix ICE in uda_attribute_p when looking up unknown attribute | expand

Commit Message

Iain Buclaw June 25, 2020, 3:38 p.m. UTC
Hi,

This patch fixes an ICE in uda_attribute_p when looking up an unknown
attribute.  The target attribute table is not guaranteed to be set by
all backends.

Bootstrapped and regression tested on x86_64-linux-gnu, and committed to
mainline.

Regards
Iain.

---
gcc/d/ChangeLog:

	PR d/95173
	* d-attribs.cc (uda_attribute_p): Don't search target attribute table
	if NULL.

gcc/testsuite/ChangeLog:

	PR d/95173
	* gdc.dg/pr95173.d: New test.
---
 gcc/d/d-attribs.cc             |  9 ++++++---
 gcc/testsuite/gdc.dg/pr95173.d | 10 ++++++++++
 2 files changed, 16 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gdc.dg/pr95173.d

Comments

Iain Buclaw June 26, 2020, 1:53 p.m. UTC | #1
Hi,

This patch has been backported, bootstrapped and regression tested on the
releases/gcc-9 and releases/gcc-10 branches.

Regards
Iain.

On 25/06/2020 17:38, Iain Buclaw wrote:
> Hi,
> 
> This patch fixes an ICE in uda_attribute_p when looking up an unknown
> attribute.  The target attribute table is not guaranteed to be set by
> all backends.
> 
> Bootstrapped and regression tested on x86_64-linux-gnu, and committed to
> mainline.
> 
> Regards
> Iain.
> 
> ---
> gcc/d/ChangeLog:
> 
> 	PR d/95173
> 	* d-attribs.cc (uda_attribute_p): Don't search target attribute table
> 	if NULL.
> 
> gcc/testsuite/ChangeLog:
> 
> 	PR d/95173
> 	* gdc.dg/pr95173.d: New test.
> ---
>  gcc/d/d-attribs.cc             |  9 ++++++---
>  gcc/testsuite/gdc.dg/pr95173.d | 10 ++++++++++
>  2 files changed, 16 insertions(+), 3 deletions(-)
>  create mode 100644 gcc/testsuite/gdc.dg/pr95173.d
> 
> diff --git a/gcc/d/d-attribs.cc b/gcc/d/d-attribs.cc
> index 964f59f96f4..f4086c0f0ee 100644
> --- a/gcc/d/d-attribs.cc
> +++ b/gcc/d/d-attribs.cc
> @@ -216,10 +216,13 @@ uda_attribute_p (const char *name)
>  	return true;
>      }
>  
> -  for (const attribute_spec *p = targetm.attribute_table; p->name; p++)
> +  if (targetm.attribute_table)
>      {
> -      if (get_identifier (p->name) == ident)
> -	return true;
> +      for (const attribute_spec *p = targetm.attribute_table; p->name; p++)
> +	{
> +	  if (get_identifier (p->name) == ident)
> +	    return true;
> +	}
>      }
>  
>    return false;
> diff --git a/gcc/testsuite/gdc.dg/pr95173.d b/gcc/testsuite/gdc.dg/pr95173.d
> new file mode 100644
> index 00000000000..2a4b2ed8232
> --- /dev/null
> +++ b/gcc/testsuite/gdc.dg/pr95173.d
> @@ -0,0 +1,10 @@
> +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95173
> +// { dg-do compile }
> +// { dg-options "-Wattributes" }
> +
> +import gcc.attribute;
> +
> +@attribute("foo") // { dg-warning "unknown attribute .foo." }
> +void f95173() 
> +{
> +}
>
diff mbox series

Patch

diff --git a/gcc/d/d-attribs.cc b/gcc/d/d-attribs.cc
index 964f59f96f4..f4086c0f0ee 100644
--- a/gcc/d/d-attribs.cc
+++ b/gcc/d/d-attribs.cc
@@ -216,10 +216,13 @@  uda_attribute_p (const char *name)
 	return true;
     }
 
-  for (const attribute_spec *p = targetm.attribute_table; p->name; p++)
+  if (targetm.attribute_table)
     {
-      if (get_identifier (p->name) == ident)
-	return true;
+      for (const attribute_spec *p = targetm.attribute_table; p->name; p++)
+	{
+	  if (get_identifier (p->name) == ident)
+	    return true;
+	}
     }
 
   return false;
diff --git a/gcc/testsuite/gdc.dg/pr95173.d b/gcc/testsuite/gdc.dg/pr95173.d
new file mode 100644
index 00000000000..2a4b2ed8232
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr95173.d
@@ -0,0 +1,10 @@ 
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95173
+// { dg-do compile }
+// { dg-options "-Wattributes" }
+
+import gcc.attribute;
+
+@attribute("foo") // { dg-warning "unknown attribute .foo." }
+void f95173() 
+{
+}