]> gcc.gnu.org Git - gcc.git/commitdiff
d: Fix ICE in uda_attribute_p when looking up unknown attribute
authorIain Buclaw <ibuclaw@gdcproject.org>
Tue, 23 Jun 2020 14:25:29 +0000 (16:25 +0200)
committerIain Buclaw <ibuclaw@gdcproject.org>
Fri, 26 Jun 2020 13:29:28 +0000 (15:29 +0200)
The target attribute table is not guaranteed to be set in all backends.

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.

(cherry picked from commit 62e02c8729a75c4a859edc18e0bcafb87d717f46)

gcc/d/d-attribs.cc
gcc/testsuite/gdc.dg/pr95173.d [new file with mode: 0644]

index 69434c639e7b4f6d73100ea33f95aeb90d26fc27..727807e9231c1657b6b1d508df37c34c57cd5bad 100644 (file)
@@ -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 (file)
index 0000000..2a4b2ed
--- /dev/null
@@ -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() 
+{
+}
This page took 0.069991 seconds and 5 git commands to generate.