From 5959cf8217e90b1331170fce96d83dd796a2bd8d Mon Sep 17 00:00:00 2001 From: Iain Buclaw Date: Fri, 24 Jun 2022 15:30:13 +0200 Subject: [PATCH] d: Give consistent error message when attribute argument not a string constant gcc/d/ChangeLog: * d-attribs.cc (d_handle_section_attribute): Update error message. (d_handle_symver_attribute): Likewise. (d_handle_no_sanitize_attribute): Likewise. (d_handle_visibility_attribute): Likewise. gcc/testsuite/ChangeLog: * gdc.dg/attr_section1.d: Update dg-error. * gdc.dg/attr_visibility1.d: Likewise. --- gcc/d/d-attribs.cc | 11 ++++++----- gcc/testsuite/gdc.dg/attr_section1.d | 2 +- gcc/testsuite/gdc.dg/attr_visibility1.d | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/gcc/d/d-attribs.cc b/gcc/d/d-attribs.cc index 23bbe39..1dd806f 100644 --- a/gcc/d/d-attribs.cc +++ b/gcc/d/d-attribs.cc @@ -1015,7 +1015,7 @@ d_handle_section_attribute (tree *node, tree name, tree args, int flags, if (TREE_CODE (TREE_VALUE (args)) != STRING_CST) { - error ("section attribute argument not a string constant"); + error ("%qE attribute argument not a string constant", name); *no_add_attrs = true; return NULL_TREE; } @@ -1065,7 +1065,8 @@ d_handle_section_attribute (tree *node, tree name, tree args, int flags, struct attribute_spec.handler. */ static tree -d_handle_symver_attribute (tree *node, tree, tree args, int, bool *no_add_attrs) +d_handle_symver_attribute (tree *node, tree name, tree args, int, + bool *no_add_attrs) { if (TREE_CODE (*node) != FUNCTION_DECL && TREE_CODE (*node) != VAR_DECL) { @@ -1088,7 +1089,7 @@ d_handle_symver_attribute (tree *node, tree, tree args, int, bool *no_add_attrs) tree symver = TREE_VALUE (args); if (TREE_CODE (symver) != STRING_CST) { - error ("% attribute argument not a string constant"); + error ("%qE attribute argument not a string constant", name); *no_add_attrs = true; return NULL_TREE; } @@ -1391,7 +1392,7 @@ d_handle_no_sanitize_attribute (tree *node, tree name, tree args, int, tree id = TREE_VALUE (args); if (TREE_CODE (id) != STRING_CST) { - error ("%qE argument not a string", name); + error ("%qE attribute argument not a string constant", name); return NULL_TREE; } @@ -1525,7 +1526,7 @@ d_handle_visibility_attribute (tree *node, tree name, tree args, tree id = TREE_VALUE (args); if (TREE_CODE (id) != STRING_CST) { - error ("visibility argument not a string"); + error ("%qE attribute argument not a string constant", name); return NULL_TREE; } diff --git a/gcc/testsuite/gdc.dg/attr_section1.d b/gcc/testsuite/gdc.dg/attr_section1.d index c24634f..759b203 100644 --- a/gcc/testsuite/gdc.dg/attr_section1.d +++ b/gcc/testsuite/gdc.dg/attr_section1.d @@ -7,7 +7,7 @@ import gcc.attributes; struct S {} // { dg-warning ".section. attribute does not apply to types" } @attribute("section", 123) -int f1(); // { dg-error "section attribute argument not a string constant" } +int f1(); // { dg-error ".section. attribute argument not a string constant" } int f2(@section("param") int a) // { dg-error "section attribute not allowed for .a." } { diff --git a/gcc/testsuite/gdc.dg/attr_visibility1.d b/gcc/testsuite/gdc.dg/attr_visibility1.d index a7ed406..932e6e6 100644 --- a/gcc/testsuite/gdc.dg/attr_visibility1.d +++ b/gcc/testsuite/gdc.dg/attr_visibility1.d @@ -13,7 +13,7 @@ void nested() } @attribute("visibility", 123) -int not_a_string(); // { dg-error "visibility argument not a string" } +int not_a_string(); // { dg-error ".visibility. attribute argument not a string constant" } @attribute("visibility", "invalid argument") int invalid_argument(); // { dg-error ".visibility. argument must be one of" } -- 2.7.4