From: Iain Buclaw Date: Sat, 18 Apr 2026 18:19:59 +0000 (+0200) Subject: d: Implement attribute no_split_stack X-Git-Tag: basepoints/gcc-17~53 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e6ea8245cde290062359dd933ca63accebce281f;p=thirdparty%2Fgcc.git d: Implement attribute no_split_stack 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. --- diff --git a/gcc/d/d-attribs.cc b/gcc/d/d-attribs.cc index 1e7493e4d03..3f748b7bef3 100644 --- a/gcc/d/d-attribs.cc +++ b/gcc/d/d-attribs.cc @@ -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 index 00000000000..48f9d8dc402 --- /dev/null +++ b/gcc/testsuite/gdc.dg/attr_no_split_stack.d @@ -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 } } diff --git a/libphobos/libdruntime/gcc/attributes.d b/libphobos/libdruntime/gcc/attributes.d index 30fc9feb47d..a69cb904009 100644 --- a/libphobos/libdruntime/gcc/attributes.d +++ b/libphobos/libdruntime/gcc/attributes.d @@ -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