]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
d: Implement attribute no_split_stack
authorIain Buclaw <ibuclaw@gdcproject.org>
Sat, 18 Apr 2026 18:19:59 +0000 (20:19 +0200)
committerIain Buclaw <ibuclaw@gdcproject.org>
Sun, 19 Apr 2026 14:45:06 +0000 (16:45 +0200)
Adds handler for @gcc.attributes.attribute("no_split_stack") and the
UDA @gcc.attributes.noSplitStack for compatibility with LDC.

gcc/d/ChangeLog:

* d-attribs.cc (d_langhook_gnu_attributes): Add no_split_stack
attribute.
(d_handle_no_split_stack_attribute): New function.

libphobos/ChangeLog:

* libdruntime/gcc/attributes.d (noSplitStack): New UDA.

gcc/testsuite/ChangeLog:

* gdc.dg/attr_no_split_stack.d: New test.

gcc/d/d-attribs.cc
gcc/testsuite/gdc.dg/attr_no_split_stack.d [new file with mode: 0644]
libphobos/libdruntime/gcc/attributes.d

index 1e7493e4d03730091bf09b9e1369e50db96e2f59..3f748b7bef3e1231fe4604645948e665c85c0617 100644 (file)
@@ -81,6 +81,7 @@ static tree d_handle_restrict_attribute (tree *, tree, tree, int, bool *);
 static tree d_handle_used_attribute (tree *, tree, tree, int, bool *);
 static tree d_handle_visibility_attribute (tree *, tree, tree, int, bool *);
 static tree d_handle_no_sanitize_attribute (tree *, tree, tree, int, bool *);
+static tree d_handle_no_split_stack_attribute (tree *, tree, tree, int, bool *);
 static tree d_handle_simd_attribute (tree *, tree, tree, int, bool *);
 
 /* Helper to define attribute exclusions.  */
@@ -234,6 +235,8 @@ static const attribute_spec d_langhook_gnu_attributes[] =
             d_handle_cold_attribute, attr_cold_hot_exclusions),
   ATTR_SPEC ("no_sanitize", 1, -1, true, false, false, false,
             d_handle_no_sanitize_attribute, NULL),
+  ATTR_SPEC ("no_split_stack", 0, 0, true, false, false, false,
+            d_handle_no_split_stack_attribute, NULL),
   ATTR_SPEC ("register", 1, 1, true, false, false, false,
             d_handle_register_attribute, NULL),
   ATTR_SPEC ("restrict", 0, 0, true, false, false, false,
@@ -1441,6 +1444,23 @@ d_handle_no_sanitize_attribute (tree *node, tree name, tree args, int,
   return NULL_TREE;
 }
 
+/* Handle a "no_split_stack" attribute; arguments as in
+   struct attribute_spec.handler.  */
+
+static tree
+d_handle_no_split_stack_attribute (tree *node, tree name, tree, int,
+                                  bool *no_add_attrs)
+{
+  if (TREE_CODE (*node) != FUNCTION_DECL)
+    {
+      error_at (DECL_SOURCE_LOCATION (*node),
+               "%qE attribute applies only to functions", name);
+      *no_add_attrs = true;
+    }
+
+  return NULL_TREE;
+}
+
 /* Handle a "register" attribute; arguments as in
    struct attribute_spec.handler.  */
 
diff --git a/gcc/testsuite/gdc.dg/attr_no_split_stack.d b/gcc/testsuite/gdc.dg/attr_no_split_stack.d
new file mode 100644 (file)
index 0000000..48f9d8d
--- /dev/null
@@ -0,0 +1,21 @@
+// { dg-do compile }
+// { dg-require-effective-target split_stack }
+// { dg-options "-fsplit-stack -fno-moduleinfo" }
+
+import gcc.attributes;
+
+void use(ref int[100]);
+
+void split()
+{
+    int[100] arr;
+    use(arr);
+}
+
+@attribute("no_split_stack")
+void nosplit()
+{
+    int[100] arr;
+    use(arr);
+}
+// { dg-final { scan-assembler-times "__morestack" 1 } }
index 30fc9feb47da31908f690858c45bec32d40eb223..a69cb9040094d78192ee352f0a33c59811ac3bf0 100644 (file)
@@ -697,6 +697,19 @@ enum naked = attribute("naked");
  */
 alias noSanitize = no_sanitize;
 
+/**
+ * Disables split-stack instrumentation for this function, overriding the
+ * `-fsplit-stack` commandline function.
+ *
+ * Examples:
+ * ---
+ * import gcc.attributes;
+ *
+ * @noSplitStack int user_function() { return 1; }
+ * ---
+ */
+enum noSplitStack = attribute("no_split_stack");
+
 /**
  * Sets the optimization strategy for a function.
  * Valid strategies are "none", "optsize", "minsize". The strategies are