Re: [C PATCH] Backport a fix for PR62294 to 4.9

2014-09-03 Thread Marek Polacek
On Tue, Sep 02, 2014 at 05:01:10PM +, Joseph S. Myers wrote:
 On Tue, 2 Sep 2014, Marek Polacek wrote:
 
  PR62294 reports that 4.9 does not emit an incompatible pointer type
  warning in certain scenario.  I unknowingly broke this in r207335, and
  then fixed it in r210980, which is a follow-up to the former.  But 4.9
  doesn't have the latter.  This patch is basically a backport of r210980,
  only without the traditional conversion stuff.
  
  Bootstrapped/regtested on x86_64-linux, ok for 4.9?
 
 OK with a testcase specifically for the regression case added on trunk and 
 4.9 if there isn't one already.

Sure, I managed to create one.  I'll add the testcase onto trunk in a
separate patch.

Bootstrapped/regtested on x86_64-linux, applying to 4.9.

2014-09-03  Marek Polacek  pola...@redhat.com

PR c/62294
* c-typeck.c (convert_arguments): Get location of a parameter.  Change
error and warning calls to error_at and warning_at.  Pass location of
a parameter to it.
(convert_for_assignment): Add parameter to WARN_FOR_ASSIGNMENT and
WARN_FOR_QUALIFIERS.  Pass expr_loc to those.

* gcc.dg/pr56724-1.c: New test.
* gcc.dg/pr56724-2.c: New test.
* gcc.dg/pr62294.c: New test.
* gcc.dg/pr62294.h: New file.

diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c
index 5838d6a..d096ad4 100644
--- gcc/c/c-typeck.c
+++ gcc/c/c-typeck.c
@@ -3071,6 +3071,12 @@ convert_arguments (location_t loc, veclocation_t 
arg_loc, tree typelist,
   bool excess_precision = false;
   bool npc;
   tree parmval;
+  /* Some __atomic_* builtins have additional hidden argument at
+position 0.  */
+  location_t ploc
+   = !arg_loc.is_empty ()  values-length () == arg_loc.length ()
+ ? expansion_point_location_if_in_system_header (arg_loc[parmnum])
+ : input_location;
 
   if (type == void_type_node)
{
@@ -3113,7 +3119,8 @@ convert_arguments (location_t loc, veclocation_t 
arg_loc, tree typelist,
 
  if (type == error_mark_node || !COMPLETE_TYPE_P (type))
{
- error (type of formal parameter %d is incomplete, parmnum + 1);
+ error_at (ploc, type of formal parameter %d is incomplete,
+   parmnum + 1);
  parmval = val;
}
  else
@@ -3128,34 +3135,34 @@ convert_arguments (location_t loc, veclocation_t 
arg_loc, tree typelist,
 
  if (INTEGRAL_TYPE_P (type)
   TREE_CODE (valtype) == REAL_TYPE)
-   warning (0, passing argument %d of %qE as integer 
-rather than floating due to prototype,
-argnum, rname);
+   warning_at (ploc, 0, passing argument %d of %qE as 
+   integer rather than floating due to 
+   prototype, argnum, rname);
  if (INTEGRAL_TYPE_P (type)
   TREE_CODE (valtype) == COMPLEX_TYPE)
-   warning (0, passing argument %d of %qE as integer 
-rather than complex due to prototype,
-argnum, rname);
+   warning_at (ploc, 0, passing argument %d of %qE as 
+   integer rather than complex due to 
+   prototype, argnum, rname);
  else if (TREE_CODE (type) == COMPLEX_TYPE
TREE_CODE (valtype) == REAL_TYPE)
-   warning (0, passing argument %d of %qE as complex 
-rather than floating due to prototype,
-argnum, rname);
+   warning_at (ploc, 0, passing argument %d of %qE as 
+   complex rather than floating due to 
+   prototype, argnum, rname);
  else if (TREE_CODE (type) == REAL_TYPE
INTEGRAL_TYPE_P (valtype))
-   warning (0, passing argument %d of %qE as floating 
-rather than integer due to prototype,
-argnum, rname);
+   warning_at (ploc, 0, passing argument %d of %qE as 
+   floating rather than integer due to 
+   prototype, argnum, rname);
  else if (TREE_CODE (type) == COMPLEX_TYPE
INTEGRAL_TYPE_P (valtype))
-   warning (0, passing argument %d of %qE as complex 
-rather than integer due to prototype,
-argnum, rname);
+   warning_at (ploc, 0, passing argument %d of %qE as 
+   complex rather than integer due to 
+   prototype, argnum, rname);
  else if (TREE_CODE (type) == REAL_TYPE
   

[C PATCH] Backport a fix for PR62294 to 4.9

2014-09-02 Thread Marek Polacek
PR62294 reports that 4.9 does not emit an incompatible pointer type
warning in certain scenario.  I unknowingly broke this in r207335, and
then fixed it in r210980, which is a follow-up to the former.  But 4.9
doesn't have the latter.  This patch is basically a backport of r210980,
only without the traditional conversion stuff.

Bootstrapped/regtested on x86_64-linux, ok for 4.9?

2014-09-02  Marek Polacek  pola...@redhat.com

PR c/62294
* c-typeck.c (convert_arguments): Get location of a parameter.  Change
error and warning calls to error_at and warning_at.  Pass location of
a parameter to it.
(convert_for_assignment): Add parameter to WARN_FOR_ASSIGNMENT and
WARN_FOR_QUALIFIERS.  Pass expr_loc to those.

* gcc.dg/pr56724-1.c: New test.
* gcc.dg/pr56724-2.c: New test.

diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c
index 5838d6a..d096ad4 100644
--- gcc/c/c-typeck.c
+++ gcc/c/c-typeck.c
@@ -3071,6 +3071,12 @@ convert_arguments (location_t loc, veclocation_t 
arg_loc, tree typelist,
   bool excess_precision = false;
   bool npc;
   tree parmval;
+  /* Some __atomic_* builtins have additional hidden argument at
+position 0.  */
+  location_t ploc
+   = !arg_loc.is_empty ()  values-length () == arg_loc.length ()
+ ? expansion_point_location_if_in_system_header (arg_loc[parmnum])
+ : input_location;
 
   if (type == void_type_node)
{
@@ -3113,7 +3119,8 @@ convert_arguments (location_t loc, veclocation_t 
arg_loc, tree typelist,
 
  if (type == error_mark_node || !COMPLETE_TYPE_P (type))
{
- error (type of formal parameter %d is incomplete, parmnum + 1);
+ error_at (ploc, type of formal parameter %d is incomplete,
+   parmnum + 1);
  parmval = val;
}
  else
@@ -3128,34 +3135,34 @@ convert_arguments (location_t loc, veclocation_t 
arg_loc, tree typelist,
 
  if (INTEGRAL_TYPE_P (type)
   TREE_CODE (valtype) == REAL_TYPE)
-   warning (0, passing argument %d of %qE as integer 
-rather than floating due to prototype,
-argnum, rname);
+   warning_at (ploc, 0, passing argument %d of %qE as 
+   integer rather than floating due to 
+   prototype, argnum, rname);
  if (INTEGRAL_TYPE_P (type)
   TREE_CODE (valtype) == COMPLEX_TYPE)
-   warning (0, passing argument %d of %qE as integer 
-rather than complex due to prototype,
-argnum, rname);
+   warning_at (ploc, 0, passing argument %d of %qE as 
+   integer rather than complex due to 
+   prototype, argnum, rname);
  else if (TREE_CODE (type) == COMPLEX_TYPE
TREE_CODE (valtype) == REAL_TYPE)
-   warning (0, passing argument %d of %qE as complex 
-rather than floating due to prototype,
-argnum, rname);
+   warning_at (ploc, 0, passing argument %d of %qE as 
+   complex rather than floating due to 
+   prototype, argnum, rname);
  else if (TREE_CODE (type) == REAL_TYPE
INTEGRAL_TYPE_P (valtype))
-   warning (0, passing argument %d of %qE as floating 
-rather than integer due to prototype,
-argnum, rname);
+   warning_at (ploc, 0, passing argument %d of %qE as 
+   floating rather than integer due to 
+   prototype, argnum, rname);
  else if (TREE_CODE (type) == COMPLEX_TYPE
INTEGRAL_TYPE_P (valtype))
-   warning (0, passing argument %d of %qE as complex 
-rather than integer due to prototype,
-argnum, rname);
+   warning_at (ploc, 0, passing argument %d of %qE as 
+   complex rather than integer due to 
+   prototype, argnum, rname);
  else if (TREE_CODE (type) == REAL_TYPE
TREE_CODE (valtype) == COMPLEX_TYPE)
-   warning (0, passing argument %d of %qE as floating 
-rather than complex due to prototype,
-argnum, rname);
+   warning_at (ploc, 0, passing argument %d of %qE as 
+   floating rather than complex due to 
+   prototype, argnum, rname);
  /* 

Re: [C PATCH] Backport a fix for PR62294 to 4.9

2014-09-02 Thread Joseph S. Myers
On Tue, 2 Sep 2014, Marek Polacek wrote:

 PR62294 reports that 4.9 does not emit an incompatible pointer type
 warning in certain scenario.  I unknowingly broke this in r207335, and
 then fixed it in r210980, which is a follow-up to the former.  But 4.9
 doesn't have the latter.  This patch is basically a backport of r210980,
 only without the traditional conversion stuff.
 
 Bootstrapped/regtested on x86_64-linux, ok for 4.9?

OK with a testcase specifically for the regression case added on trunk and 
4.9 if there isn't one already.

-- 
Joseph S. Myers
jos...@codesourcery.com