Hi,

This patch changes an assertion into an early return condition,
handling the case of delegate literals defined at module scope.
Fixing PR d/89041.

Bootstrapped and regression tested on x86_64-linux-gnu.

Committed to trunk as r269533.

-- 
Iain
---
gcc/d/ChangeLog:

2019-03-09  Iain Buclaw  <ibuc...@gdcproject.org>

        PR d/89041
        * d-codegen.cc (get_frame_for_symbol): Delegate literals defined in
        global scope don't have a frame pointer.

gcc/testsuite/ChangeLog:

2019-03-09  Iain Buclaw  <ibuc...@gdcproject.org>

        PR d/89041
        * gdc.dg/pr89041.d: New test.

---
diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index 58c8257c63c..e8233b43c67 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -2172,7 +2172,16 @@ get_frame_for_symbol (Dsymbol *sym)
       fdparent = (FuncDeclaration *) sym;
     }
 
-  gcc_assert (fdparent != NULL);
+  /* Not a nested function, there is no frame pointer to pass.  */
+  if (fdparent == NULL)
+    {
+      /* Only delegate literals report as being nested, even if they are in
+	 global scope.  */
+      gcc_assert (fd && fd->isFuncLiteralDeclaration ());
+      return null_pointer_node;
+    }
+
+  gcc_assert (thisfd != NULL);
 
   if (thisfd != fdparent)
     {
@@ -2180,8 +2189,8 @@ get_frame_for_symbol (Dsymbol *sym)
       if (!thisfd->vthis)
 	{
 	  error_at (make_location_t (sym->loc),
-		    "is a nested function and cannot be accessed from %qs",
-		    thisfd->toChars ());
+		    "%qs is a nested function and cannot be accessed from %qs",
+		    fd->toPrettyChars (), thisfd->toPrettyChars ());
 	  return null_pointer_node;
 	}
 
diff --git a/gcc/testsuite/gdc.dg/pr89041.d b/gcc/testsuite/gdc.dg/pr89041.d
new file mode 100644
index 00000000000..b62c2db85d4
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr89041.d
@@ -0,0 +1,13 @@
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89041
+module pr89041;
+
+enum dg = delegate {};
+
+void fn()
+{
+    auto var = dg;
+
+    auto inner() {
+        return dg();
+    }
+}

Reply via email to