[3/4] remove %K from error() calls in the aarch64/arm back ends (PR 98512)

Message ID 24e1d1ea-33a0-bab8-3182-1dbb90ff7e3c@gmail.com
State New
Headers show
Series
  • improve warning suppression for inlined functions (PR 98512)
Related show

Commit Message

H.J. Lu via Gcc-patches June 10, 2021, 11:28 p.m.
This patch removes the uses of %K from error() calls in the aarch64
and arm back ends.  I tested this change only by building a cross-
compiler but I can't easily run the tests so I'd appreciate some help
validating it.  The fallout from the change should be limited to changes
to error messages so in the worst case it could be addressed after
committing the patch.

Comments

H.J. Lu via Gcc-patches June 11, 2021, 7:53 a.m. | #1
On Fri, 11 Jun 2021 at 01:29, Martin Sebor via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>

> This patch removes the uses of %K from error() calls in the aarch64

> and arm back ends.  I tested this change only by building a cross-

> compiler but I can't easily run the tests so I'd appreciate some help

> validating it.  The fallout from the change should be limited to changes

> to error messages so in the worst case it could be addressed after

> committing the patch.


I've submitted a validation with your patch, I'll let you know the
results (in a few hours)

Thanks

Christophe
H.J. Lu via Gcc-patches June 11, 2021, 9:58 a.m. | #2
Martin Sebor via Gcc-patches <gcc-patches@gcc.gnu.org> writes:
> diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c

> index 7b37e1b602c..7cdc824730c 100644

> --- a/gcc/config/arm/arm.c

> +++ b/gcc/config/arm/arm.c

> @@ -13242,13 +13242,8 @@ bounds_check (rtx operand, HOST_WIDE_INT low, HOST_WIDE_INT high,

>    lane = INTVAL (operand);

>  

>    if (lane < low || lane >= high)

> -    {

> -      if (exp)

> -	error ("%K%s %wd out of range %wd - %wd",

> -	       exp, desc, lane, low, high - 1);

> -      else

> -	error ("%s %wd out of range %wd - %wd", desc, lane, low, high - 1);

> -    }

> +    error_at (EXPR_LOCATION (exp),

> +	      "%s %wd out of range %wd - %wd", desc, lane, low, high - 1);

>  }

>  

>  /* Bounds-check lanes.  */


This part doesn't look safe: “exp” is null when called from arm_const_bounds.

Thanks,
Richard
H.J. Lu via Gcc-patches June 11, 2021, 1:10 p.m. | #3
On Fri, 11 Jun 2021 at 09:53, Christophe Lyon
<christophe.lyon@linaro.org> wrote:
>

> On Fri, 11 Jun 2021 at 01:29, Martin Sebor via Gcc-patches

> <gcc-patches@gcc.gnu.org> wrote:

> >

> > This patch removes the uses of %K from error() calls in the aarch64

> > and arm back ends.  I tested this change only by building a cross-

> > compiler but I can't easily run the tests so I'd appreciate some help

> > validating it.  The fallout from the change should be limited to changes

> > to error messages so in the worst case it could be addressed after

> > committing the patch.

>

> I've submitted a validation with your patch, I'll let you know the

> results (in a few hours)

>


I haven't noticed any regression with that patch alone.
I just noticed it is patch 3/4: I didn't apply patches 1 and 2 before
this one, do you want me to relaunch the tests with the 3 patches
combined?

Thanks,

Christophe

> Thanks

>

> Christophe
H.J. Lu via Gcc-patches June 11, 2021, 2:46 p.m. | #4
On 6/11/21 3:58 AM, Richard Sandiford wrote:
> Martin Sebor via Gcc-patches <gcc-patches@gcc.gnu.org> writes:

>> diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c

>> index 7b37e1b602c..7cdc824730c 100644

>> --- a/gcc/config/arm/arm.c

>> +++ b/gcc/config/arm/arm.c

>> @@ -13242,13 +13242,8 @@ bounds_check (rtx operand, HOST_WIDE_INT low, HOST_WIDE_INT high,

>>     lane = INTVAL (operand);

>>   

>>     if (lane < low || lane >= high)

>> -    {

>> -      if (exp)

>> -	error ("%K%s %wd out of range %wd - %wd",

>> -	       exp, desc, lane, low, high - 1);

>> -      else

>> -	error ("%s %wd out of range %wd - %wd", desc, lane, low, high - 1);

>> -    }

>> +    error_at (EXPR_LOCATION (exp),

>> +	      "%s %wd out of range %wd - %wd", desc, lane, low, high - 1);

>>   }

>>   

>>   /* Bounds-check lanes.  */

> 

> This part doesn't look safe: “exp” is null when called from arm_const_bounds.


Doh!  Yes, will fix, thanks.

Martin

> 

> Thanks,

> Richard

>
H.J. Lu via Gcc-patches June 11, 2021, 2:47 p.m. | #5
On 6/11/21 7:10 AM, Christophe Lyon wrote:
> On Fri, 11 Jun 2021 at 09:53, Christophe Lyon

> <christophe.lyon@linaro.org> wrote:

>>

>> On Fri, 11 Jun 2021 at 01:29, Martin Sebor via Gcc-patches

>> <gcc-patches@gcc.gnu.org> wrote:

>>>

>>> This patch removes the uses of %K from error() calls in the aarch64

>>> and arm back ends.  I tested this change only by building a cross-

>>> compiler but I can't easily run the tests so I'd appreciate some help

>>> validating it.  The fallout from the change should be limited to changes

>>> to error messages so in the worst case it could be addressed after

>>> committing the patch.

>>

>> I've submitted a validation with your patch, I'll let you know the

>> results (in a few hours)

>>

> 

> I haven't noticed any regression with that patch alone.

> I just noticed it is patch 3/4: I didn't apply patches 1 and 2 before

> this one, do you want me to relaunch the tests with the 3 patches

> combined?


That would be great, as soon as I fix the thinko Richard Sandiford
pointed out.

Thanks for the offer!

Martin

> 

> Thanks,

> 

> Christophe

> 

>> Thanks

>>

>> Christophe
H.J. Lu via Gcc-patches June 30, 2021, 7:56 p.m. | #6
On 6/11/21 8:46 AM, Martin Sebor wrote:
> On 6/11/21 3:58 AM, Richard Sandiford wrote:

>> Martin Sebor via Gcc-patches <gcc-patches@gcc.gnu.org> writes:

>>> diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c

>>> index 7b37e1b602c..7cdc824730c 100644

>>> --- a/gcc/config/arm/arm.c

>>> +++ b/gcc/config/arm/arm.c

>>> @@ -13242,13 +13242,8 @@ bounds_check (rtx operand, HOST_WIDE_INT 

>>> low, HOST_WIDE_INT high,

>>>     lane = INTVAL (operand);

>>>     if (lane < low || lane >= high)

>>> -    {

>>> -      if (exp)

>>> -    error ("%K%s %wd out of range %wd - %wd",

>>> -           exp, desc, lane, low, high - 1);

>>> -      else

>>> -    error ("%s %wd out of range %wd - %wd", desc, lane, low, high - 1);

>>> -    }

>>> +    error_at (EXPR_LOCATION (exp),

>>> +          "%s %wd out of range %wd - %wd", desc, lane, low, high - 1);

>>>   }

>>>   /* Bounds-check lanes.  */

>>

>> This part doesn't look safe: “exp” is null when called from 

>> arm_const_bounds.

> 

> Doh!  Yes, will fix, thanks.


Attached is an updated patch with the test above restored.

Christophe, if you could apply it on top of patches 1 and 2 and run
the aarch64/arm tests that would be great!

Patch 1:
https://gcc.gnu.org/pipermail/gcc-patches/2021-June/573859.html
Patch 2:
https://gcc.gnu.org/pipermail/gcc-patches/2021-June/574088.html

Thanks
Martin
Improve warning suppression for inlined functions.

gcc/ChangeLog:

	* config/aarch64/aarch64-builtins.c (aarch64_simd_expand_builtin):
	Remove %K and use error_at.
	(aarch64_expand_fcmla_builtin): Same.
	(aarch64_expand_builtin_tme): Same.
	(aarch64_expand_builtin_memtag): Same.
	* config/arm/arm-builtins.c (arm_expand_acle_builtin): Same.
	(arm_expand_builtin): Same.
	* config/arm/arm.c (bounds_check): Same.

diff --git a/gcc/config/aarch64/aarch64-builtins.c b/gcc/config/aarch64/aarch64-builtins.c
index 3cab3ec992c..9ed4b72d005 100644
--- a/gcc/config/aarch64/aarch64-builtins.c
+++ b/gcc/config/aarch64/aarch64-builtins.c
@@ -1598,8 +1598,9 @@ constant_arg:
 	      if (!(*insn_data[icode].operand[opc].predicate)
 		  (op[opc], mode))
 	      {
-		error ("%Kargument %d must be a constant immediate",
-		       exp, opc + 1 - have_retval);
+		error_at (EXPR_LOCATION (exp),
+			  "argument %d must be a constant immediate",
+			  opc + 1 - have_retval);
 		return const0_rtx;
 	      }
 	      break;
@@ -1669,10 +1670,13 @@ aarch64_simd_expand_builtin (int fcode, tree exp, rtx target)
 				       / UINTVAL (elementsize),
 				      exp);
           else
-	    error ("%Klane index must be a constant immediate", exp);
+	    error_at (EXPR_LOCATION (exp),
+		      "lane index must be a constant immediate");
 	}
       else
-	error ("%Ktotal size and element size must be a non-zero constant immediate", exp);
+	error_at (EXPR_LOCATION (exp),
+		  "total size and element size must be a non-zero "
+		  "constant immediate");
       /* Don't generate any RTL.  */
       return const0_rtx;
     }
@@ -1828,7 +1832,8 @@ aarch64_expand_fcmla_builtin (tree exp, rtx target, int fcode)
   /* Validate that the lane index is a constant.  */
   if (!CONST_INT_P (lane_idx))
     {
-      error ("%Kargument %d must be a constant immediate", exp, 4);
+      error_at (EXPR_LOCATION (exp),
+		"argument %d must be a constant immediate", 4);
       return const0_rtx;
     }
 
@@ -1917,7 +1922,8 @@ aarch64_expand_builtin_tme (int fcode, tree exp, rtx target)
 	  emit_insn (GEN_FCN (CODE_FOR_tcancel) (op0));
 	else
 	  {
-	    error ("%Kargument must be a 16-bit constant immediate", exp);
+	    error_at (EXPR_LOCATION (exp),
+		      "argument must be a 16-bit constant immediate");
 	    return const0_rtx;
 	  }
       }
@@ -2006,8 +2012,9 @@ aarch64_expand_builtin_memtag (int fcode, tree exp, rtx target)
 		  pat = GEN_FCN (icode) (target, op0, const0_rtx, op1);
 		  break;
 		}
-	      error ("%Kargument %d must be a constant immediate "
-		     "in range [0,15]", exp, 2);
+	      error_at (EXPR_LOCATION (exp),
+			"argument %d must be a constant immediate "
+			"in range [0,15]", 2);
 	      return const0_rtx;
 	    }
 	  else
diff --git a/gcc/config/arm/arm-builtins.c b/gcc/config/arm/arm-builtins.c
index fa0fb0b16ab..3a9ff8f26b8 100644
--- a/gcc/config/arm/arm-builtins.c
+++ b/gcc/config/arm/arm-builtins.c
@@ -3092,26 +3092,30 @@ constant_arg:
 			  unsigned int cp_bit = (CONST_INT_P (op[argc])
 						 ? UINTVAL (op[argc]) : -1);
 			  if (IN_RANGE (cp_bit, 0, ARM_CDE_CONST_COPROC))
-			    error ("%Kcoprocessor %d is not enabled "
-				   "with +cdecp%d", exp, cp_bit, cp_bit);
+			    error_at (EXPR_LOCATION (exp),
+				      "coprocessor %d is not enabled "
+				      "with +cdecp%d", cp_bit, cp_bit);
 			  else
-			    error ("%Kcoproc must be a constant immediate in "
-				   "range [0-%d] enabled with +cdecp<N>", exp,
-				   ARM_CDE_CONST_COPROC);
+			    error_at (EXPR_LOCATION (exp),
+				      "coproc must be a constant immediate in "
+				      "range [0-%d] enabled with +cdecp<N>",
+				      ARM_CDE_CONST_COPROC);
 			}
 		      else
 			/* Here we mention the builtin name to follow the same
 			   format that the C/C++ frontends use for referencing
 			   a given argument index.  */
-			error ("%Kargument %d to %qE must be a constant immediate "
-			       "in range [0-%d]", exp, argc + 1,
+			error_at (EXPR_LOCATION (exp),
+				  "argument %d to %qE must be a constant "
+				  "immediate in range [0-%d]", argc + 1,
 			       arm_builtin_decls[fcode],
 			       cde_builtin_data[fcode -
 			       ARM_BUILTIN_CDE_PATTERN_START].imm_max);
 		    }
 		  else
-		    error ("%Kargument %d must be a constant immediate",
-			   exp, argc + 1);
+		    error_at (EXPR_LOCATION (exp),
+			      "argument %d must be a constant immediate",
+			      argc + 1);
 		  /* We have failed to expand the pattern, and are safely
 		     in to invalid code.  But the mid-end will still try to
 		     build an assignment for this node while it expands,
@@ -3328,11 +3332,13 @@ arm_expand_acle_builtin (int fcode, tree exp, rtx target)
       if (CONST_INT_P (sat_imm))
 	{
 	  if (!IN_RANGE (sat_imm, min_sat, max_sat))
-	    error ("%Ksaturation bit range must be in the range [%wd, %wd]",
-		   exp, UINTVAL (min_sat), UINTVAL (max_sat));
+	    error_at (EXPR_LOCATION (exp),
+		      "saturation bit range must be in the range [%wd, %wd]",
+		      UINTVAL (min_sat), UINTVAL (max_sat));
 	}
       else
-	error ("%Ksaturation bit range must be a constant immediate", exp);
+	error_at (EXPR_LOCATION (exp),
+		  "saturation bit range must be a constant immediate");
       /* Don't generate any RTL.  */
       return const0_rtx;
     }
@@ -3455,7 +3461,8 @@ arm_expand_builtin (tree exp,
       if (CONST_INT_P (lane_idx))
 	neon_lane_bounds (lane_idx, 0, TREE_INT_CST_LOW (nlanes), exp);
       else
-	error ("%Klane index must be a constant immediate", exp);
+	error_at (EXPR_LOCATION (exp),
+		  "lane index must be a constant immediate");
       /* Don't generate any RTL.  */
       return const0_rtx;
     }
diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index 7b37e1b602c..de37c903450 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -13244,8 +13244,8 @@ bounds_check (rtx operand, HOST_WIDE_INT low, HOST_WIDE_INT high,
   if (lane < low || lane >= high)
     {
       if (exp)
-	error ("%K%s %wd out of range %wd - %wd",
-	       exp, desc, lane, low, high - 1);
+	error_at (EXPR_LOCATION (exp),
+		  "%s %wd out of range %wd - %wd", desc, lane, low, high - 1);
       else
 	error ("%s %wd out of range %wd - %wd", desc, lane, low, high - 1);
     }
H.J. Lu via Gcc-patches July 1, 2021, 8:01 a.m. | #7
On 30/06/2021 21:56, Martin Sebor via Gcc-patches wrote:
> On 6/11/21 8:46 AM, Martin Sebor wrote:

>> On 6/11/21 3:58 AM, Richard Sandiford wrote:

>>> Martin Sebor via Gcc-patches <gcc-patches@gcc.gnu.org> writes:

>>>> diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c

>>>> index 7b37e1b602c..7cdc824730c 100644

>>>> --- a/gcc/config/arm/arm.c

>>>> +++ b/gcc/config/arm/arm.c

>>>> @@ -13242,13 +13242,8 @@ bounds_check (rtx operand, HOST_WIDE_INT 

>>>> low, HOST_WIDE_INT high,

>>>>     lane = INTVAL (operand);

>>>>     if (lane < low || lane >= high)

>>>> -    {

>>>> -      if (exp)

>>>> -    error ("%K%s %wd out of range %wd - %wd",

>>>> -           exp, desc, lane, low, high - 1);

>>>> -      else

>>>> -    error ("%s %wd out of range %wd - %wd", desc, lane, low, high 

>>>> - 1);

>>>> -    }

>>>> +    error_at (EXPR_LOCATION (exp),

>>>> +          "%s %wd out of range %wd - %wd", desc, lane, low, high - 

>>>> 1);

>>>>   }

>>>>   /* Bounds-check lanes.  */

>>>

>>> This part doesn't look safe: “exp” is null when called from 

>>> arm_const_bounds.

>>

>> Doh!  Yes, will fix, thanks.

>

> Attached is an updated patch with the test above restored.

>

> Christophe, if you could apply it on top of patches 1 and 2 and run

> the aarch64/arm tests that would be great!

>

> Patch 1:

> https://gcc.gnu.org/pipermail/gcc-patches/2021-June/573859.html

> Patch 2:

> https://gcc.gnu.org/pipermail/gcc-patches/2021-June/574088.html

>


Hi,


I hope I got it right, but there are a few regressions on aarch64/arm:

http://people.linaro.org/~christophe.lyon/cross-validation/gcc-test-patches/r12-1929-gf6bc9d9bddad7f9e3aad939bb6750770ac67f003-martin.patch

The patch I applied is 
https://people.linaro.org/~christophe.lyon/cross-validation/gcc-test-patches/r12-1929-gf6bc9d9bddad7f9e3aad939bb6750770ac67f003-martin.patch/commit.txt


The regressions are the same on aarch64/arm:

   Executed from: gcc.dg/format/format.exp
     gcc.dg/format/c90-printf-1.c    %s with NULL (test for warnings, line 243)
     gcc.dg/format/c90-printf-1.c    (test for excess errors)
     gcc.dg/format/c90-printf-1.c   -DWIDE  %s with NULL (test for warnings, line 243)
     gcc.dg/format/c90-printf-1.c   -DWIDE  (test for excess errors)
   Executed from: gcc.dg/dg.exp
     gcc.dg/pr79214.c  (test for warnings, line 25)
     gcc.dg/pr79214.c  (test for warnings, line 30)
     gcc.dg/pr79214.c  (test for warnings, line 35)
     gcc.dg/pr79214.c  (test for warnings, line 40)
     gcc.dg/pr79214.c  (test for warnings, line 45)
     gcc.dg/pr79214.c  (test for warnings, line 52)
     gcc.dg/pr79214.c  (test for warnings, line 59)
     gcc.dg/pr79214.c  (test for warnings, line 66)
     gcc.dg/pr79214.c  (test for warnings, line 73)
     gcc.dg/pr79214.c  (test for warnings, line 80)
     gcc.dg/pr79214.c  (test for warnings, line 87)


If you want to see the corresponding gcc.log, you can click on "log" in 
the red cells of the top-level report.


HTH


Christophe


> Thanks

> Martin
H.J. Lu via Gcc-patches July 1, 2021, 2:45 p.m. | #8
On 7/1/21 2:01 AM, Christophe LYON wrote:
> 

> On 30/06/2021 21:56, Martin Sebor via Gcc-patches wrote:

>> On 6/11/21 8:46 AM, Martin Sebor wrote:

>>> On 6/11/21 3:58 AM, Richard Sandiford wrote:

>>>> Martin Sebor via Gcc-patches <gcc-patches@gcc.gnu.org> writes:

>>>>> diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c

>>>>> index 7b37e1b602c..7cdc824730c 100644

>>>>> --- a/gcc/config/arm/arm.c

>>>>> +++ b/gcc/config/arm/arm.c

>>>>> @@ -13242,13 +13242,8 @@ bounds_check (rtx operand, HOST_WIDE_INT 

>>>>> low, HOST_WIDE_INT high,

>>>>>     lane = INTVAL (operand);

>>>>>     if (lane < low || lane >= high)

>>>>> -    {

>>>>> -      if (exp)

>>>>> -    error ("%K%s %wd out of range %wd - %wd",

>>>>> -           exp, desc, lane, low, high - 1);

>>>>> -      else

>>>>> -    error ("%s %wd out of range %wd - %wd", desc, lane, low, high 

>>>>> - 1);

>>>>> -    }

>>>>> +    error_at (EXPR_LOCATION (exp),

>>>>> +          "%s %wd out of range %wd - %wd", desc, lane, low, high - 

>>>>> 1);

>>>>>   }

>>>>>   /* Bounds-check lanes.  */

>>>>

>>>> This part doesn't look safe: “exp” is null when called from 

>>>> arm_const_bounds.

>>>

>>> Doh!  Yes, will fix, thanks.

>>

>> Attached is an updated patch with the test above restored.

>>

>> Christophe, if you could apply it on top of patches 1 and 2 and run

>> the aarch64/arm tests that would be great!

>>

>> Patch 1:

>> https://gcc.gnu.org/pipermail/gcc-patches/2021-June/573859.html

>> Patch 2:

>> https://gcc.gnu.org/pipermail/gcc-patches/2021-June/574088.html

>>

> 

> Hi,

> 

> 

> I hope I got it right, but there are a few regressions on aarch64/arm:


Thanks!

> 

> http://people.linaro.org/~christophe.lyon/cross-validation/gcc-test-patches/r12-1929-gf6bc9d9bddad7f9e3aad939bb6750770ac67f003-martin.patch

> 

> The patch I applied is 

> https://people.linaro.org/~christophe.lyon/cross-validation/gcc-test-patches/r12-1929-gf6bc9d9bddad7f9e3aad939bb6750770ac67f003-martin.patch/commit.txt

> 

> 

> The regressions are the same on aarch64/arm:

> 

>    Executed from: gcc.dg/format/format.exp

>      gcc.dg/format/c90-printf-1.c    %s with NULL (test for warnings, line 243)

>      gcc.dg/format/c90-printf-1.c    (test for excess errors)

>      gcc.dg/format/c90-printf-1.c   -DWIDE  %s with NULL (test for warnings, line 243)

>      gcc.dg/format/c90-printf-1.c   -DWIDE  (test for excess errors)


The location of the warning has improved here leading to the test
failing where it looks for it in the wrong place (wrong column).
This is (or will be) fixed in the final patch by adjusting the test.



>    Executed from: gcc.dg/dg.exp

>      gcc.dg/pr79214.c  (test for warnings, line 25)

>      gcc.dg/pr79214.c  (test for warnings, line 30)

>      gcc.dg/pr79214.c  (test for warnings, line 35)

>      gcc.dg/pr79214.c  (test for warnings, line 40)

>      gcc.dg/pr79214.c  (test for warnings, line 45)

>      gcc.dg/pr79214.c  (test for warnings, line 52)

>      gcc.dg/pr79214.c  (test for warnings, line 59)

>      gcc.dg/pr79214.c  (test for warnings, line 66)

>      gcc.dg/pr79214.c  (test for warnings, line 73)

>      gcc.dg/pr79214.c  (test for warnings, line 80)

>      gcc.dg/pr79214.c  (test for warnings, line 87)


This is also expected (on all targets) and something I'll deal with
before committing.

> 

> 

> If you want to see the corresponding gcc.log, you can click on "log" in 

> the red cells of the top-level report.


Your results validate the aarch64 and arm changes so they're all
I needed.

Thanks again for your help!

Martin

> 

> 

> HTH

> 

> 

> Christophe

> 

> 

>> Thanks

>> Martin

Patch

gcc/ChangeLog:

	* config/aarch64/aarch64-builtins.c (aarch64_simd_expand_builtin):
	Remove %K and use error_at.
	(aarch64_expand_fcmla_builtin): Same.
	(aarch64_expand_builtin_tme): Same.
	(aarch64_expand_builtin_memtag): Same.
	* config/arm/arm-builtins.c (arm_expand_acle_builtin): Same.
	(arm_expand_builtin): Same.
	* config/arm/arm.c (bounds_check): Same.

diff --git a/gcc/config/aarch64/aarch64-builtins.c b/gcc/config/aarch64/aarch64-builtins.c
index 3cab3ec992c..9ed4b72d005 100644
--- a/gcc/config/aarch64/aarch64-builtins.c
+++ b/gcc/config/aarch64/aarch64-builtins.c
@@ -1598,8 +1598,9 @@  constant_arg:
 	      if (!(*insn_data[icode].operand[opc].predicate)
 		  (op[opc], mode))
 	      {
-		error ("%Kargument %d must be a constant immediate",
-		       exp, opc + 1 - have_retval);
+		error_at (EXPR_LOCATION (exp),
+			  "argument %d must be a constant immediate",
+			  opc + 1 - have_retval);
 		return const0_rtx;
 	      }
 	      break;
@@ -1669,10 +1670,13 @@  aarch64_simd_expand_builtin (int fcode, tree exp, rtx target)
 				       / UINTVAL (elementsize),
 				      exp);
           else
-	    error ("%Klane index must be a constant immediate", exp);
+	    error_at (EXPR_LOCATION (exp),
+		      "lane index must be a constant immediate");
 	}
       else
-	error ("%Ktotal size and element size must be a non-zero constant immediate", exp);
+	error_at (EXPR_LOCATION (exp),
+		  "total size and element size must be a non-zero "
+		  "constant immediate");
       /* Don't generate any RTL.  */
       return const0_rtx;
     }
@@ -1828,7 +1832,8 @@  aarch64_expand_fcmla_builtin (tree exp, rtx target, int fcode)
   /* Validate that the lane index is a constant.  */
   if (!CONST_INT_P (lane_idx))
     {
-      error ("%Kargument %d must be a constant immediate", exp, 4);
+      error_at (EXPR_LOCATION (exp),
+		"argument %d must be a constant immediate", 4);
       return const0_rtx;
     }
 
@@ -1917,7 +1922,8 @@  aarch64_expand_builtin_tme (int fcode, tree exp, rtx target)
 	  emit_insn (GEN_FCN (CODE_FOR_tcancel) (op0));
 	else
 	  {
-	    error ("%Kargument must be a 16-bit constant immediate", exp);
+	    error_at (EXPR_LOCATION (exp),
+		      "argument must be a 16-bit constant immediate");
 	    return const0_rtx;
 	  }
       }
@@ -2006,8 +2012,9 @@  aarch64_expand_builtin_memtag (int fcode, tree exp, rtx target)
 		  pat = GEN_FCN (icode) (target, op0, const0_rtx, op1);
 		  break;
 		}
-	      error ("%Kargument %d must be a constant immediate "
-		     "in range [0,15]", exp, 2);
+	      error_at (EXPR_LOCATION (exp),
+			"argument %d must be a constant immediate "
+			"in range [0,15]", 2);
 	      return const0_rtx;
 	    }
 	  else
diff --git a/gcc/config/arm/arm-builtins.c b/gcc/config/arm/arm-builtins.c
index fa0fb0b16ab..3a9ff8f26b8 100644
--- a/gcc/config/arm/arm-builtins.c
+++ b/gcc/config/arm/arm-builtins.c
@@ -3092,26 +3092,30 @@  constant_arg:
 			  unsigned int cp_bit = (CONST_INT_P (op[argc])
 						 ? UINTVAL (op[argc]) : -1);
 			  if (IN_RANGE (cp_bit, 0, ARM_CDE_CONST_COPROC))
-			    error ("%Kcoprocessor %d is not enabled "
-				   "with +cdecp%d", exp, cp_bit, cp_bit);
+			    error_at (EXPR_LOCATION (exp),
+				      "coprocessor %d is not enabled "
+				      "with +cdecp%d", cp_bit, cp_bit);
 			  else
-			    error ("%Kcoproc must be a constant immediate in "
-				   "range [0-%d] enabled with +cdecp<N>", exp,
-				   ARM_CDE_CONST_COPROC);
+			    error_at (EXPR_LOCATION (exp),
+				      "coproc must be a constant immediate in "
+				      "range [0-%d] enabled with +cdecp<N>",
+				      ARM_CDE_CONST_COPROC);
 			}
 		      else
 			/* Here we mention the builtin name to follow the same
 			   format that the C/C++ frontends use for referencing
 			   a given argument index.  */
-			error ("%Kargument %d to %qE must be a constant immediate "
-			       "in range [0-%d]", exp, argc + 1,
+			error_at (EXPR_LOCATION (exp),
+				  "argument %d to %qE must be a constant "
+				  "immediate in range [0-%d]", argc + 1,
 			       arm_builtin_decls[fcode],
 			       cde_builtin_data[fcode -
 			       ARM_BUILTIN_CDE_PATTERN_START].imm_max);
 		    }
 		  else
-		    error ("%Kargument %d must be a constant immediate",
-			   exp, argc + 1);
+		    error_at (EXPR_LOCATION (exp),
+			      "argument %d must be a constant immediate",
+			      argc + 1);
 		  /* We have failed to expand the pattern, and are safely
 		     in to invalid code.  But the mid-end will still try to
 		     build an assignment for this node while it expands,
@@ -3328,11 +3332,13 @@  arm_expand_acle_builtin (int fcode, tree exp, rtx target)
       if (CONST_INT_P (sat_imm))
 	{
 	  if (!IN_RANGE (sat_imm, min_sat, max_sat))
-	    error ("%Ksaturation bit range must be in the range [%wd, %wd]",
-		   exp, UINTVAL (min_sat), UINTVAL (max_sat));
+	    error_at (EXPR_LOCATION (exp),
+		      "saturation bit range must be in the range [%wd, %wd]",
+		      UINTVAL (min_sat), UINTVAL (max_sat));
 	}
       else
-	error ("%Ksaturation bit range must be a constant immediate", exp);
+	error_at (EXPR_LOCATION (exp),
+		  "saturation bit range must be a constant immediate");
       /* Don't generate any RTL.  */
       return const0_rtx;
     }
@@ -3455,7 +3461,8 @@  arm_expand_builtin (tree exp,
       if (CONST_INT_P (lane_idx))
 	neon_lane_bounds (lane_idx, 0, TREE_INT_CST_LOW (nlanes), exp);
       else
-	error ("%Klane index must be a constant immediate", exp);
+	error_at (EXPR_LOCATION (exp),
+		  "lane index must be a constant immediate");
       /* Don't generate any RTL.  */
       return const0_rtx;
     }
diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index 7b37e1b602c..7cdc824730c 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -13242,13 +13242,8 @@  bounds_check (rtx operand, HOST_WIDE_INT low, HOST_WIDE_INT high,
   lane = INTVAL (operand);
 
   if (lane < low || lane >= high)
-    {
-      if (exp)
-	error ("%K%s %wd out of range %wd - %wd",
-	       exp, desc, lane, low, high - 1);
-      else
-	error ("%s %wd out of range %wd - %wd", desc, lane, low, high - 1);
-    }
+    error_at (EXPR_LOCATION (exp),
+	      "%s %wd out of range %wd - %wd", desc, lane, low, high - 1);
 }
 
 /* Bounds-check lanes.  */