Re: [PATCH][stage1] Enhance target and target_clone error messages.

2019-04-30 Thread Jeff Law
On 4/23/19 4:06 AM, Martin Liška wrote:
> On 4/19/19 2:28 AM, Martin Sebor wrote:
>> On 4/18/19 5:09 AM, Martin Liška wrote:
>>> Hi.
>>>
>>> The patch distinguishes among target and target_clone attribute when
>>> reporting for an error. I've also reworded the affected error messages
>>> a bit.
>>>
>>> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>>>
>>> Ready to be installed after stage1 opens?
>>> Thanks,
>>> Martin
>>>
>>> ---
>>>   gcc/cgraphclones.c |  2 +-
>>>   gcc/config/i386/i386-c.c   |  5 +-
>>>   gcc/config/i386/i386-protos.h  |  4 +-
>>>   gcc/config/i386/i386.c | 54 +-
>>>   gcc/testsuite/gcc.target/i386/funcspec-4.c |  2 +-
>>>   5 files changed, 39 insertions(+), 28 deletions(-)
>> Just a suggestion to also consider making the phrasing in the messages
>> consistent by adding "is" below
>>
>> @@ -5316,7 +5322,7 @@ ix86_valid_target_attribute_inner_p (tree args, char 
>> *p_strings[],
>>
>>    else if (TREE_CODE (args) != STRING_CST)
>>  {
>> -  error ("attribute % argument not a string");
>> +  error_at (loc, "attribute %qs argument not a string", attr_name);
>>    return false;
>>
>> i.e., "is not a string" and changing the below
>>
>> @@ -5382,7 +5386,8 @@ ix86_valid_target_attribute_inner_p (tree args, char 
>> *p_strings[],
>>    /* Process the option.  */
>>    if (opt == N_OPTS)
>>  {
>> -  error ("attribute(target(\"%s\")) is unknown", orig_p);
>> +  error_at (loc, "attribute value %qs is unknown in %qs attribute",
>> +    orig_p, attr_name);
>>
>> to
>>
>>   error_at (loc, "attribute %qs argument %qs is unknown",
>>     attr_name, orig_p);
>>
>> Martin
> Thank you Martin. I'm sending updated patch.
> 
> Martin
> 
> 
> 0001-Enhance-target-and-target_clone-error-messages.patch
> 
> From 2778f9ab4f1cd091780694e8cc1335d6125d95ec Mon Sep 17 00:00:00 2001
> From: marxin 
> Date: Wed, 17 Apr 2019 13:59:14 +0200
> Subject: [PATCH] Enhance target and target_clone error messages.
> 
> gcc/ChangeLog:
> 
> 2019-04-18  Martin Liska  
> 
>   * cgraphclones.c: Call valid_attribute_p with 1 for
>   target_clone.
>   * config/i386/i386-c.c (ix86_pragma_target_parse): Use 0 as
>   it's for target attribute.
>   * config/i386/i386-protos.h (ix86_valid_target_attribute_tree):
>   Add new boolean argument.
>   * config/i386/i386.c (ix86_valid_target_attribute_inner_p):
>   Likewise.
>   (ix86_valid_target_attribute_tree): Pass target_clone_attr
>   to ix86_valid_target_attribute_inner_p.
>   (ix86_valid_target_attribute_p): Pass flags argument to
>   ix86_valid_target_attribute_inner_p.
>   (get_builtin_code_for_version): Use 0 as it's target attribute.
> 
> gcc/testsuite/ChangeLog:
> 
> 2019-04-18  Martin Liska  
> 
>   * gcc.target/i386/funcspec-4.c: Update scanned pattern.
>   * g++.target/i386/pr57362.C: Likewise.
OK
Jeff


Re: [PATCH][stage1] Enhance target and target_clone error messages.

2019-04-23 Thread Martin Liška
On 4/19/19 2:28 AM, Martin Sebor wrote:
> On 4/18/19 5:09 AM, Martin Liška wrote:
>> Hi.
>>
>> The patch distinguishes among target and target_clone attribute when
>> reporting for an error. I've also reworded the affected error messages
>> a bit.
>>
>> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>>
>> Ready to be installed after stage1 opens?
>> Thanks,
>> Martin
>>
>> ---
>>   gcc/cgraphclones.c |  2 +-
>>   gcc/config/i386/i386-c.c   |  5 +-
>>   gcc/config/i386/i386-protos.h  |  4 +-
>>   gcc/config/i386/i386.c | 54 +-
>>   gcc/testsuite/gcc.target/i386/funcspec-4.c |  2 +-
>>   5 files changed, 39 insertions(+), 28 deletions(-)
> 
> Just a suggestion to also consider making the phrasing in the messages
> consistent by adding "is" below
> 
> @@ -5316,7 +5322,7 @@ ix86_valid_target_attribute_inner_p (tree args, char 
> *p_strings[],
> 
>    else if (TREE_CODE (args) != STRING_CST)
>  {
> -  error ("attribute % argument not a string");
> +  error_at (loc, "attribute %qs argument not a string", attr_name);
>    return false;
> 
> i.e., "is not a string" and changing the below
> 
> @@ -5382,7 +5386,8 @@ ix86_valid_target_attribute_inner_p (tree args, char 
> *p_strings[],
>    /* Process the option.  */
>    if (opt == N_OPTS)
>  {
> -  error ("attribute(target(\"%s\")) is unknown", orig_p);
> +  error_at (loc, "attribute value %qs is unknown in %qs attribute",
> +    orig_p, attr_name);
> 
> to
> 
>   error_at (loc, "attribute %qs argument %qs is unknown",
>     attr_name, orig_p);
> 
> Martin

Thank you Martin. I'm sending updated patch.

Martin
>From 2778f9ab4f1cd091780694e8cc1335d6125d95ec Mon Sep 17 00:00:00 2001
From: marxin 
Date: Wed, 17 Apr 2019 13:59:14 +0200
Subject: [PATCH] Enhance target and target_clone error messages.

gcc/ChangeLog:

2019-04-18  Martin Liska  

	* cgraphclones.c: Call valid_attribute_p with 1 for
	target_clone.
	* config/i386/i386-c.c (ix86_pragma_target_parse): Use 0 as
	it's for target attribute.
	* config/i386/i386-protos.h (ix86_valid_target_attribute_tree):
	Add new boolean argument.
	* config/i386/i386.c (ix86_valid_target_attribute_inner_p):
	Likewise.
	(ix86_valid_target_attribute_tree): Pass target_clone_attr
	to ix86_valid_target_attribute_inner_p.
	(ix86_valid_target_attribute_p): Pass flags argument to
	ix86_valid_target_attribute_inner_p.
	(get_builtin_code_for_version): Use 0 as it's target attribute.

gcc/testsuite/ChangeLog:

2019-04-18  Martin Liska  

	* gcc.target/i386/funcspec-4.c: Update scanned pattern.
	* g++.target/i386/pr57362.C: Likewise.
---
 gcc/cgraphclones.c |  2 +-
 gcc/config/i386/i386-c.c   |  5 +-
 gcc/config/i386/i386-protos.h  |  4 +-
 gcc/config/i386/i386.c | 56 +-
 gcc/testsuite/g++.target/i386/pr57362.C|  2 +-
 gcc/testsuite/gcc.target/i386/funcspec-4.c |  2 +-
 6 files changed, 42 insertions(+), 29 deletions(-)

diff --git a/gcc/cgraphclones.c b/gcc/cgraphclones.c
index 15f7e119d18..fd867ecac91 100644
--- a/gcc/cgraphclones.c
+++ b/gcc/cgraphclones.c
@@ -1056,7 +1056,7 @@ cgraph_node::create_version_clone_with_body
   location_t saved_loc = input_location;
   tree v = TREE_VALUE (target_attributes);
   input_location = DECL_SOURCE_LOCATION (new_decl);
-  bool r = targetm.target_option.valid_attribute_p (new_decl, NULL, v, 0);
+  bool r = targetm.target_option.valid_attribute_p (new_decl, NULL, v, 1);
   input_location = saved_loc;
   if (!r)
 	return NULL;
diff --git a/gcc/config/i386/i386-c.c b/gcc/config/i386/i386-c.c
index 5e7e46fcebe..50cac3b1a9f 100644
--- a/gcc/config/i386/i386-c.c
+++ b/gcc/config/i386/i386-c.c
@@ -586,8 +586,9 @@ ix86_pragma_target_parse (tree args, tree pop_target)
 }
   else
 {
-  cur_tree = ix86_valid_target_attribute_tree (args, _options,
-		   _options_set);
+  cur_tree = ix86_valid_target_attribute_tree (NULL_TREE, args,
+		   _options,
+		   _options_set, 0);
   if (!cur_tree || cur_tree == error_mark_node)
{
  cl_target_option_restore (_options,
diff --git a/gcc/config/i386/i386-protos.h b/gcc/config/i386/i386-protos.h
index 83645e89a81..cfc4783205e 100644
--- a/gcc/config/i386/i386-protos.h
+++ b/gcc/config/i386/i386-protos.h
@@ -215,9 +215,9 @@ extern unsigned int ix86_minimum_alignment (tree, machine_mode,
 extern tree ix86_handle_shared_attribute (tree *, tree, tree, int, bool *);
 extern tree ix86_handle_selectany_attribute (tree *, tree, tree, int, bool *);
 extern int x86_field_alignment (tree, int);
-extern tree ix86_valid_target_attribute_tree (tree,
+extern tree ix86_valid_target_attribute_tree (tree, tree,
 	  struct gcc_options *,
-	  struct gcc_options *);
+	  struct gcc_options *, bool);
 extern unsigned int ix86_get_callcvt 

Re: [PATCH][stage1] Enhance target and target_clone error messages.

2019-04-18 Thread Martin Sebor

On 4/18/19 5:09 AM, Martin Liška wrote:

Hi.

The patch distinguishes among target and target_clone attribute when
reporting for an error. I've also reworded the affected error messages
a bit.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed after stage1 opens?
Thanks,
Martin

---
  gcc/cgraphclones.c |  2 +-
  gcc/config/i386/i386-c.c   |  5 +-
  gcc/config/i386/i386-protos.h  |  4 +-
  gcc/config/i386/i386.c | 54 +-
  gcc/testsuite/gcc.target/i386/funcspec-4.c |  2 +-
  5 files changed, 39 insertions(+), 28 deletions(-)


Just a suggestion to also consider making the phrasing in the messages
consistent by adding "is" below

@@ -5316,7 +5322,7 @@ ix86_valid_target_attribute_inner_p (tree args, 
char *p_strings[],


   else if (TREE_CODE (args) != STRING_CST)
 {
-  error ("attribute % argument not a string");
+  error_at (loc, "attribute %qs argument not a string", attr_name);
   return false;

i.e., "is not a string" and changing the below

@@ -5382,7 +5386,8 @@ ix86_valid_target_attribute_inner_p (tree args, 
char *p_strings[],

   /* Process the option.  */
   if (opt == N_OPTS)
{
- error ("attribute(target(\"%s\")) is unknown", orig_p);
+ error_at (loc, "attribute value %qs is unknown in %qs attribute",
+   orig_p, attr_name);

to

  error_at (loc, "attribute %qs argument %qs is unknown",
attr_name, orig_p);

Martin


Re: [PATCH][stage1] Enhance target and target_clone error messages.

2019-04-18 Thread Martin Liška
On 4/18/19 1:09 PM, Martin Liška wrote:
> Hi.
> 
> The patch distinguishes among target and target_clone attribute when
> reporting for an error. I've also reworded the affected error messages
> a bit.
> 
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
> 
> Ready to be installed after stage1 opens?
> Thanks,
> Martin
> 
> ---
>  gcc/cgraphclones.c |  2 +-
>  gcc/config/i386/i386-c.c   |  5 +-
>  gcc/config/i386/i386-protos.h  |  4 +-
>  gcc/config/i386/i386.c | 54 +-
>  gcc/testsuite/gcc.target/i386/funcspec-4.c |  2 +-
>  5 files changed, 39 insertions(+), 28 deletions(-)
> 
> 

I forgot to attach ChangeLog.

Martin
>From 8330ad8d25463ea2f596a617f3e133d2050b9ac8 Mon Sep 17 00:00:00 2001
From: marxin 
Date: Wed, 17 Apr 2019 13:59:14 +0200
Subject: [PATCH] Enhance target and target_clone error messages.

gcc/ChangeLog:

2019-04-18  Martin Liska  

	* cgraphclones.c: Call valid_attribute_p with 1 for
	target_clone.
	* config/i386/i386-c.c (ix86_pragma_target_parse): Use 0 as
	it's for target attribute.
	* config/i386/i386-protos.h (ix86_valid_target_attribute_tree):
	Add new boolean argument.
	* config/i386/i386.c (ix86_valid_target_attribute_inner_p):
	Likewise.
	(ix86_valid_target_attribute_tree): Pass target_clone_attr
	to ix86_valid_target_attribute_inner_p.
	(ix86_valid_target_attribute_p): Pass flags argument to
	ix86_valid_target_attribute_inner_p.
	(get_builtin_code_for_version): Use 0 as it's target attribute.

gcc/testsuite/ChangeLog:

2019-04-18  Martin Liska  

	* gcc.target/i386/funcspec-4.c: Update scanned pattern.
---
 gcc/cgraphclones.c |  2 +-
 gcc/config/i386/i386-c.c   |  5 +-
 gcc/config/i386/i386-protos.h  |  4 +-
 gcc/config/i386/i386.c | 56 +-
 gcc/testsuite/gcc.target/i386/funcspec-4.c |  2 +-
 5 files changed, 41 insertions(+), 28 deletions(-)

diff --git a/gcc/cgraphclones.c b/gcc/cgraphclones.c
index 15f7e119d18..fd867ecac91 100644
--- a/gcc/cgraphclones.c
+++ b/gcc/cgraphclones.c
@@ -1056,7 +1056,7 @@ cgraph_node::create_version_clone_with_body
   location_t saved_loc = input_location;
   tree v = TREE_VALUE (target_attributes);
   input_location = DECL_SOURCE_LOCATION (new_decl);
-  bool r = targetm.target_option.valid_attribute_p (new_decl, NULL, v, 0);
+  bool r = targetm.target_option.valid_attribute_p (new_decl, NULL, v, 1);
   input_location = saved_loc;
   if (!r)
 	return NULL;
diff --git a/gcc/config/i386/i386-c.c b/gcc/config/i386/i386-c.c
index 5e7e46fcebe..50cac3b1a9f 100644
--- a/gcc/config/i386/i386-c.c
+++ b/gcc/config/i386/i386-c.c
@@ -586,8 +586,9 @@ ix86_pragma_target_parse (tree args, tree pop_target)
 }
   else
 {
-  cur_tree = ix86_valid_target_attribute_tree (args, _options,
-		   _options_set);
+  cur_tree = ix86_valid_target_attribute_tree (NULL_TREE, args,
+		   _options,
+		   _options_set, 0);
   if (!cur_tree || cur_tree == error_mark_node)
{
  cl_target_option_restore (_options,
diff --git a/gcc/config/i386/i386-protos.h b/gcc/config/i386/i386-protos.h
index 83645e89a81..cfc4783205e 100644
--- a/gcc/config/i386/i386-protos.h
+++ b/gcc/config/i386/i386-protos.h
@@ -215,9 +215,9 @@ extern unsigned int ix86_minimum_alignment (tree, machine_mode,
 extern tree ix86_handle_shared_attribute (tree *, tree, tree, int, bool *);
 extern tree ix86_handle_selectany_attribute (tree *, tree, tree, int, bool *);
 extern int x86_field_alignment (tree, int);
-extern tree ix86_valid_target_attribute_tree (tree,
+extern tree ix86_valid_target_attribute_tree (tree, tree,
 	  struct gcc_options *,
-	  struct gcc_options *);
+	  struct gcc_options *, bool);
 extern unsigned int ix86_get_callcvt (const_tree);
 
 #endif
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index ed9a9c2e3f7..eff22215e99 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -847,10 +847,11 @@ static void ix86_function_specific_post_stream_in (struct cl_target_option *);
 static void ix86_function_specific_print (FILE *, int,
 	  struct cl_target_option *);
 static bool ix86_valid_target_attribute_p (tree, tree, tree, int);
-static bool ix86_valid_target_attribute_inner_p (tree, char *[],
+static bool ix86_valid_target_attribute_inner_p (tree, tree, char *[],
 		 struct gcc_options *,
 		 struct gcc_options *,
-		 struct gcc_options *);
+		 struct gcc_options *,
+		 bool);
 static bool ix86_can_inline_p (tree, tree);
 static void ix86_set_current_function (tree);
 static unsigned int ix86_minimum_incoming_stack_boundary (bool);
@@ -5149,10 +5150,11 @@ ix86_function_specific_print (FILE *file, int indent,
over the list.  */
 
 static bool
-ix86_valid_target_attribute_inner_p (tree args, char *p_strings[],
+ix86_valid_target_attribute_inner_p 

[PATCH][stage1] Enhance target and target_clone error messages.

2019-04-18 Thread Martin Liška
Hi.

The patch distinguishes among target and target_clone attribute when
reporting for an error. I've also reworded the affected error messages
a bit.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed after stage1 opens?
Thanks,
Martin

---
 gcc/cgraphclones.c |  2 +-
 gcc/config/i386/i386-c.c   |  5 +-
 gcc/config/i386/i386-protos.h  |  4 +-
 gcc/config/i386/i386.c | 54 +-
 gcc/testsuite/gcc.target/i386/funcspec-4.c |  2 +-
 5 files changed, 39 insertions(+), 28 deletions(-)


diff --git a/gcc/cgraphclones.c b/gcc/cgraphclones.c
index 15f7e119d18..fd867ecac91 100644
--- a/gcc/cgraphclones.c
+++ b/gcc/cgraphclones.c
@@ -1056,7 +1056,7 @@ cgraph_node::create_version_clone_with_body
   location_t saved_loc = input_location;
   tree v = TREE_VALUE (target_attributes);
   input_location = DECL_SOURCE_LOCATION (new_decl);
-  bool r = targetm.target_option.valid_attribute_p (new_decl, NULL, v, 0);
+  bool r = targetm.target_option.valid_attribute_p (new_decl, NULL, v, 1);
   input_location = saved_loc;
   if (!r)
 	return NULL;
diff --git a/gcc/config/i386/i386-c.c b/gcc/config/i386/i386-c.c
index 5e7e46fcebe..50cac3b1a9f 100644
--- a/gcc/config/i386/i386-c.c
+++ b/gcc/config/i386/i386-c.c
@@ -586,8 +586,9 @@ ix86_pragma_target_parse (tree args, tree pop_target)
 }
   else
 {
-  cur_tree = ix86_valid_target_attribute_tree (args, _options,
-		   _options_set);
+  cur_tree = ix86_valid_target_attribute_tree (NULL_TREE, args,
+		   _options,
+		   _options_set, 0);
   if (!cur_tree || cur_tree == error_mark_node)
{
  cl_target_option_restore (_options,
diff --git a/gcc/config/i386/i386-protos.h b/gcc/config/i386/i386-protos.h
index 83645e89a81..cfc4783205e 100644
--- a/gcc/config/i386/i386-protos.h
+++ b/gcc/config/i386/i386-protos.h
@@ -215,9 +215,9 @@ extern unsigned int ix86_minimum_alignment (tree, machine_mode,
 extern tree ix86_handle_shared_attribute (tree *, tree, tree, int, bool *);
 extern tree ix86_handle_selectany_attribute (tree *, tree, tree, int, bool *);
 extern int x86_field_alignment (tree, int);
-extern tree ix86_valid_target_attribute_tree (tree,
+extern tree ix86_valid_target_attribute_tree (tree, tree,
 	  struct gcc_options *,
-	  struct gcc_options *);
+	  struct gcc_options *, bool);
 extern unsigned int ix86_get_callcvt (const_tree);
 
 #endif
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index ed9a9c2e3f7..aa8adc7b2aa 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -847,10 +847,11 @@ static void ix86_function_specific_post_stream_in (struct cl_target_option *);
 static void ix86_function_specific_print (FILE *, int,
 	  struct cl_target_option *);
 static bool ix86_valid_target_attribute_p (tree, tree, tree, int);
-static bool ix86_valid_target_attribute_inner_p (tree, char *[],
+static bool ix86_valid_target_attribute_inner_p (tree, tree, char *[],
 		 struct gcc_options *,
 		 struct gcc_options *,
-		 struct gcc_options *);
+		 struct gcc_options *,
+		 bool);
 static bool ix86_can_inline_p (tree, tree);
 static void ix86_set_current_function (tree);
 static unsigned int ix86_minimum_incoming_stack_boundary (bool);
@@ -5149,10 +5150,11 @@ ix86_function_specific_print (FILE *file, int indent,
over the list.  */
 
 static bool
-ix86_valid_target_attribute_inner_p (tree args, char *p_strings[],
+ix86_valid_target_attribute_inner_p (tree fndecl, tree args, char *p_strings[],
  struct gcc_options *opts,
  struct gcc_options *opts_set,
- struct gcc_options *enum_opts_set)
+ struct gcc_options *enum_opts_set,
+ bool target_clone_attr)
 {
   char *next_optstr;
   bool ret = true;
@@ -5296,9 +5298,12 @@ ix86_valid_target_attribute_inner_p (tree args, char *p_strings[],
 IX86_ATTR_YES ("recip",
 		   OPT_mrecip,
 		   MASK_RECIP),
-
   };
 
+  location_t loc
+= fndecl == NULL ? UNKNOWN_LOCATION : DECL_SOURCE_LOCATION (fndecl);
+  const char *attr_name = target_clone_attr ? "target_clone" : "target";
+
   /* If this is a list, recurse to get the options.  */
   if (TREE_CODE (args) == TREE_LIST)
 {
@@ -5306,9 +5311,10 @@ ix86_valid_target_attribute_inner_p (tree args, char *p_strings[],
 
   for (; args; args = TREE_CHAIN (args))
 	if (TREE_VALUE (args)
-	&& !ix86_valid_target_attribute_inner_p (TREE_VALUE (args),
+	&& !ix86_valid_target_attribute_inner_p (fndecl, TREE_VALUE (args),
 		 p_strings, opts, opts_set,
-		 enum_opts_set))
+		 enum_opts_set,
+		 target_clone_attr))
 	  ret = false;
 
   return ret;
@@ -5316,7 +5322,7 @@ ix86_valid_target_attribute_inner_p (tree args, char *p_strings[],
 
   else if (TREE_CODE (args) != STRING_CST)
 {
-  error ("attribute % argument not a string");
+