Re: [PATCH v3 1/2] arm: Zero/Sign extends for CMSE security on Armv8-M.baseline [PR115253]

2024-06-12 Thread Torbjorn SVENSSON




On 2024-06-11 15:59, Richard Earnshaw (lists) wrote:

On 10/06/2024 15:04, Torbjörn SVENSSON wrote:

Properly handle zero and sign extension for Armv8-M.baseline as
Cortex-M23 can have the security extension active.
Currently, there is an internal compiler error on Cortex-M23 for the
epilog processing of sign extension.

This patch addresses the following CVE-2024-0151 for Armv8-M.baseline.

gcc/ChangeLog:

PR target/115253
* config/arm/arm.cc (cmse_nonsecure_call_inline_register_clear):
Sign extend for Thumb1.
(thumb1_expand_prologue): Add zero/sign extend.

Signed-off-by: Torbjörn SVENSSON 
Co-authored-by: Yvan ROUX 
---
  gcc/config/arm/arm.cc | 71 ++-
  1 file changed, 63 insertions(+), 8 deletions(-)

diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc
index ea0c963a4d6..e7b4caf1083 100644
--- a/gcc/config/arm/arm.cc
+++ b/gcc/config/arm/arm.cc
@@ -19220,17 +19220,22 @@ cmse_nonsecure_call_inline_register_clear (void)
  || TREE_CODE (ret_type) == BOOLEAN_TYPE)
  && known_lt (GET_MODE_SIZE (TYPE_MODE (ret_type)), 4))
{
- machine_mode ret_mode = TYPE_MODE (ret_type);
+ rtx ret_reg = gen_rtx_REG (TYPE_MODE (ret_type), R0_REGNUM);
+ rtx si_reg = gen_rtx_REG (SImode, R0_REGNUM);
  rtx extend;
  if (TYPE_UNSIGNED (ret_type))
-   extend = gen_rtx_ZERO_EXTEND (SImode,
- gen_rtx_REG (ret_mode, 
R0_REGNUM));
+   extend = gen_rtx_SET (si_reg, gen_rtx_ZERO_EXTEND (SImode,
+  ret_reg));
  else
-   extend = gen_rtx_SIGN_EXTEND (SImode,
- gen_rtx_REG (ret_mode, 
R0_REGNUM));
- emit_insn_after (gen_rtx_SET (gen_rtx_REG (SImode, R0_REGNUM),
-extend), insn);
-
+   /* Signed-extension is a special case because of
+  thumb1_extendhisi2.  */
+   if (TARGET_THUMB1


You effectively have an 'else if' split across a comment here, and the 
indentation looks weird.  Either write 'else if' on one line (and re-indent 
accordingly) or put this entire block inside braces.


+   && known_ge (GET_MODE_SIZE (TYPE_MODE (ret_type)), 2))


You can use known_eq here.  We'll never have any value other than 2, given the 
known_le (4) above and anyway it doesn't make sense to call extendhisi with any 
other size.


+ extend = gen_thumb1_extendhisi2 (si_reg, ret_reg);
+   else
+ extend = gen_rtx_SET (si_reg, gen_rtx_SIGN_EXTEND (SImode,
+ret_reg));
+ emit_insn_after (extend, insn);
}
  
  
@@ -27250,6 +27255,56 @@ thumb1_expand_prologue (void)

live_regs_mask = offsets->saved_regs_mask;
lr_needs_saving = live_regs_mask & (1 << LR_REGNUM);
  


Similar comments to above apply to the hunk below.


+  /* The AAPCS requires the callee to widen integral types narrower
+ than 32 bits to the full width of the register; but when handling
+ calls to non-secure space, we cannot trust the callee to have
+ correctly done so.  So forcibly re-widen the result here.  */
+  if (IS_CMSE_ENTRY (func_type))
+{
+  function_args_iterator args_iter;
+  CUMULATIVE_ARGS args_so_far_v;
+  cumulative_args_t args_so_far;
+  bool first_param = true;
+  tree arg_type;
+  tree fndecl = current_function_decl;
+  tree fntype = TREE_TYPE (fndecl);
+  arm_init_cumulative_args (_so_far_v, fntype, NULL_RTX, fndecl);
+  args_so_far = pack_cumulative_args (_so_far_v);
+  FOREACH_FUNCTION_ARGS (fntype, arg_type, args_iter)
+   {
+ rtx arg_rtx;
+
+ if (VOID_TYPE_P (arg_type))
+   break;
+
+ function_arg_info arg (arg_type, /*named=*/true);
+ if (!first_param)
+   /* We should advance after processing the argument and pass
+  the argument we're advancing past.  */
+   arm_function_arg_advance (args_so_far, arg);
+ first_param = false;
+ arg_rtx = arm_function_arg (args_so_far, arg);
+ gcc_assert (REG_P (arg_rtx));
+ if ((TREE_CODE (arg_type) == INTEGER_TYPE
+ || TREE_CODE (arg_type) == ENUMERAL_TYPE
+ || TREE_CODE (arg_type) == BOOLEAN_TYPE)
+ && known_lt (GET_MODE_SIZE (GET_MODE (arg_rtx)), 4))
+   {
+ rtx res_reg = gen_rtx_REG (SImode, REGNO (arg_rtx));
+ if (TYPE_UNSIGNED (arg_type))
+   emit_set_insn (res_reg, gen_rtx_ZERO_EXTEND (SImode, arg_rtx));
+ else
+   /* Signed-extension is a special case because of
+  thumb1_extendhisi2.  */
+   if (known_ge (GET_MODE_SIZE 

Re: [PATCH v3 2/2] testsuite: Fix expand-return CMSE test for Armv8.1-M [PR115253]

2024-06-12 Thread Torbjorn SVENSSON




On 2024-06-11 16:00, Richard Earnshaw (lists) wrote:

On 10/06/2024 15:04, Torbjörn SVENSSON wrote:

For Armv8.1-M, the clearing of the registers is handled differently than
for Armv8-M, so update the test case accordingly.

gcc/testsuite/ChangeLog:

PR target/115253
* gcc.target/arm/cmse/extend-return.c: Update test case
condition for Armv8.1-M.

Signed-off-by: Torbjörn SVENSSON 
Co-authored-by: Yvan ROUX 
---
  .../gcc.target/arm/cmse/extend-return.c   | 62 +--
  1 file changed, 56 insertions(+), 6 deletions(-)

diff --git a/gcc/testsuite/gcc.target/arm/cmse/extend-return.c 
b/gcc/testsuite/gcc.target/arm/cmse/extend-return.c
index 081de0d699f..2288d166bd3 100644
--- a/gcc/testsuite/gcc.target/arm/cmse/extend-return.c
+++ b/gcc/testsuite/gcc.target/arm/cmse/extend-return.c
@@ -1,5 +1,7 @@
  /* { dg-do compile } */
  /* { dg-options "-mcmse -fshort-enums" } */
+/* ARMv8-M expectation with target { ! arm_cmse_clear_ok }.  */
+/* ARMv8.1-M expectation with target arm_cmse_clear_ok.  */
  /* { dg-final { check-function-bodies "**" "" "" } } */
  
  #include 

@@ -20,7 +22,15 @@ typedef enum offset __attribute__ ((cmse_nonsecure_call)) 
ns_enum_foo_t (void);
  typedef bool __attribute__ ((cmse_nonsecure_call)) ns_bool_foo_t (void);
  
  /*

-**unsignNonsecure0:
+**unsignNonsecure0:  { target arm_cmse_clear_ok }
+** ...
+** blxns   r[0-3]
+** ...
+** uxtbr0, r0
+** ...
+*/
+/*
+**unsignNonsecure0: { target { ! arm_cmse_clear_ok } }
  **...
  **bl  __gnu_cmse_nonsecure_call
  **uxtbr0, r0
@@ -32,7 +42,15 @@ unsigned char unsignNonsecure0 (ns_unsign_foo_t * ns_foo_p)
  }
  
  /*

-**signNonsecure0:
+**signNonsecure0:  { target arm_cmse_clear_ok }
+** ...
+** blxns   r[0-3]
+** ...
+** sxtbr0, r0
+** ...
+*/
+/*
+**signNonsecure0: { target { ! arm_cmse_clear_ok } }
  **...
  **bl  __gnu_cmse_nonsecure_call
  **sxtbr0, r0
@@ -44,7 +62,15 @@ signed char signNonsecure0 (ns_sign_foo_t * ns_foo_p)
  }
  
  /*

-**shortUnsignNonsecure0:
+**shortUnsignNonsecure0:  { target arm_cmse_clear_ok }
+** ...
+** blxns   r[0-3]
+** ...
+** uxthr0, r0
+** ...
+*/
+/*
+**shortUnsignNonsecure0: { target { ! arm_cmse_clear_ok } }
  **...
  **bl  __gnu_cmse_nonsecure_call
  **uxthr0, r0
@@ -56,7 +82,15 @@ unsigned short shortUnsignNonsecure0 (ns_short_unsign_foo_t 
* ns_foo_p)
  }
  
  /*

-**shortSignNonsecure0:
+**shortSignNonsecure0:  { target arm_cmse_clear_ok }
+** ...
+** blxns   r[0-3]
+** ...
+** sxthr0, r0
+** ...
+*/
+/*
+**shortSignNonsecure0: { target { ! arm_cmse_clear_ok } }
  **...
  **bl  __gnu_cmse_nonsecure_call
  **sxthr0, r0
@@ -68,7 +102,15 @@ signed short shortSignNonsecure0 (ns_short_sign_foo_t * 
ns_foo_p)
  }
  
  /*

-**enumNonsecure0:
+**enumNonsecure0:  { target arm_cmse_clear_ok }
+** ...
+** blxns   r[0-3]
+** ...
+** uxtbr0, r0
+** ...
+*/
+/*
+**enumNonsecure0: { target { ! arm_cmse_clear_ok } }
  **...
  **bl  __gnu_cmse_nonsecure_call
  **uxtbr0, r0
@@ -80,7 +122,15 @@ unsigned char __attribute__((noipa)) enumNonsecure0 
(ns_enum_foo_t * ns_foo_p)
  }
  
  /*

-**boolNonsecure0:
+**boolNonsecure0:  { target arm_cmse_clear_ok }
+** ...
+** blxns   r[0-3]
+** ...
+** uxtbr0, r0
+** ...
+*/
+/*
+**boolNonsecure0: { target { ! arm_cmse_clear_ok } }
  **...
  **bl  __gnu_cmse_nonsecure_call
  **uxtbr0, r0


OK when the nits in the first patch are sorted.

R.


Pushed as:

basepoints/gcc-15-1201-gcf5f9171bae
releases/gcc-14.1.0-134-g9100e78ba28
releases/gcc-13.3.0-64-gdfab6851eb5
releases/gcc-12.3.0-1035-g3d9e4eedb6b
releases/gcc-11.4.0-650-gbf9c877c4c9

Kind regards,
Torbjörn


Re: [PATCH v2 1/2] arm: Zero/Sign extends for CMSE security on Armv8-M.baseline [PR115253]

2024-06-10 Thread Torbjorn SVENSSON

Hi Andre,

Thanks for the review!
Please see my questions below.

On 2024-06-10 12:37, Andre Vieira (lists) wrote:

Hi Torbjorn,

Thanks for this, I have some comments below.

On 07/06/2024 09:56, Torbjörn SVENSSON wrote:

Properly handle zero and sign extension for Armv8-M.baseline as
Cortex-M23 can have the security extension active.
Currently, there is a internal compiler error on Cortex-M23 for the
epilog processing of sign extension.

This patch addresses the following CVE-2024-0151 for Armv8-M.baseline.

gcc/ChangeLog:

PR target/115253
* config/arm/arm.cc (cmse_nonsecure_call_inline_register_clear):
Sign extend for Thumb1.
(thumb1_expand_prologue): Add zero/sign extend.

Signed-off-by: Torbjörn SVENSSON 
Co-authored-by: Yvan ROUX 
---
  gcc/config/arm/arm.cc | 68 ++-
  1 file changed, 60 insertions(+), 8 deletions(-)

diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc
index ea0c963a4d6..d1bb173c135 100644
--- a/gcc/config/arm/arm.cc
+++ b/gcc/config/arm/arm.cc
@@ -19220,17 +19220,23 @@ cmse_nonsecure_call_inline_register_clear 
(void)

    || TREE_CODE (ret_type) == BOOLEAN_TYPE)
    && known_lt (GET_MODE_SIZE (TYPE_MODE (ret_type)), 4))
  {
-  machine_mode ret_mode = TYPE_MODE (ret_type);
+  rtx ret_mode = gen_rtx_REG (TYPE_MODE (ret_type), R0_REGNUM);
+  rtx si_mode = gen_rtx_REG (SImode, R0_REGNUM);


I'd rename ret_mode and si_mode to ret_reg and si_reg, so its clear they 
are registers and not actually mode types.


Okay, will be changed before push and/or a V3 of the patches.


    rtx extend;
    if (TYPE_UNSIGNED (ret_type))
-    extend = gen_rtx_ZERO_EXTEND (SImode,
-  gen_rtx_REG (ret_mode, R0_REGNUM));
+    extend = gen_rtx_SET (si_mode, gen_rtx_ZERO_EXTEND (SImode,
+    ret_mode));
+  else if (TARGET_THUMB1)
+    {
+  if (known_lt (GET_MODE_SIZE (TYPE_MODE (ret_type)), 2))
+    extend = gen_thumb1_extendqisi2 (si_mode, ret_mode);
+  else
+    extend = gen_thumb1_extendhisi2 (si_mode, ret_mode);
+    }
    else
-    extend = gen_rtx_SIGN_EXTEND (SImode,
-  gen_rtx_REG (ret_mode, R0_REGNUM));
-  emit_insn_after (gen_rtx_SET (gen_rtx_REG (SImode, R0_REGNUM),
- extend), insn);
-
+    extend = gen_rtx_SET (si_mode, gen_rtx_SIGN_EXTEND (SImode,
+    ret_mode));
+  emit_insn_after (extend, insn);
  }


Using gen_rtx_SIGN_EXTEND should work for both, the reason it doesn't is 
because of some weird code in thumb1_extendhisi2, which I'm actually 
gonna look at removing, but I don't think we should block this fix as 
we'd want to backport it ASAP.


But for clearness we should re-order this code so it's clear we only 
need it for that specific case.

Can you maybe do:
if (TYPE_UNSIGNED ..)
{
}
else
{
    /*  Signed-extension is a special case because of 
thumb1_extendhisi2.  */

    if (TARGET_THUMB1
    && known_gt (GET_MODE_SIZE (TYPE_MODE (ret_type)), 2))
  {
     //call the gen_thumb1_extendhisi2
  }
     else
  {
     // use gen_RTX_SIGN_EXTEND
  }
}


So, you talk about gen_thumb1_extendhisi2, but there is also 
gen_thumb1_extendqisi2. Will it actually be cleaner if the block is 
indented one level?
The comment can be added in the "if (TARGET_THUMB1)" block regardless to 
indicate that gen_rtx_SIGN_EXTEND can't be used.



@@ -27250,6 +27256,52 @@ thumb1_expand_prologue (void)
    live_regs_mask = offsets->saved_regs_mask;
    lr_needs_saving = live_regs_mask & (1 << LR_REGNUM);
+  /* The AAPCS requires the callee to widen integral types narrower
+ than 32 bits to the full width of the register; but when handling
+ calls to non-secure space, we cannot trust the callee to have
+ correctly done so.  So forcibly re-widen the result here.  */
+  if (IS_CMSE_ENTRY (func_type))
+    {
+  function_args_iterator args_iter;
+  CUMULATIVE_ARGS args_so_far_v;
+  cumulative_args_t args_so_far;
+  bool first_param = true;
+  tree arg_type;
+  tree fndecl = current_function_decl;
+  tree fntype = TREE_TYPE (fndecl);
+  arm_init_cumulative_args (_so_far_v, fntype, NULL_RTX, 
fndecl);

+  args_so_far = pack_cumulative_args (_so_far_v);
+  FOREACH_FUNCTION_ARGS (fntype, arg_type, args_iter)
+    {
+  rtx arg_rtx;
+
+  if (VOID_TYPE_P (arg_type))
+    break;
+
+  function_arg_info arg (arg_type, /*named=*/true);
+  if (!first_param)
+    /* We should advance after processing the argument and pass
+   the argument we're advancing past.  */
+    arm_function_arg_advance (args_so_far, arg);
+  first_param = false;
+  arg_rtx = arm_function_arg (args_so_far, arg);
+  gcc_assert (REG_P (arg_rtx));
+  if ((TREE_CODE (arg_type) == 

Re: [PATCH v2] testsuite: Verify r0-r3 are extended with CMSE

2024-05-22 Thread Torbjorn SVENSSON

Hi,

I've now pushed the below change to the following branches with the 
corresponding commit id.


trunk: 9ddad76e98ac8f257f90b3814ed3c6ba78d0f3c7
releases/gcc-14: da3a6b0dda45bc676bb985d7940853b50803e11a
releases/gcc-13: 75d394c20b0ad85dfe8511324d61d13e453c9285
releases/gcc-12: d9c89402b54be4c15bb3c7bcce3465f534746204
releases/gcc-11: 08ca81e4b49bda153d678a372df7f7143a94f4ad

Kind regards,
Torbjörn


On 2024-05-22 13:54, Richard Earnshaw (lists) wrote:

On 22/05/2024 12:14, Torbjorn SVENSSON wrote:

Hello Richard,

Thanks for the reply.

 From my point of view, at least the -fshort-enums part should be on all 
branches. Just to be clean, maybe it's easier to backport the entire patch?


Yes, that's a fair point.  I was only thinking about the broadening of the test 
to the other argument registers when I said that.

So, just to be clear, OK all.

R.



Unless you have an objection, I would like to go ahead and just backport it to 
all branches.

Kind regards,
Torbjörn

On 2024-05-22 12:55, Richard Earnshaw (lists) wrote:

On 06/05/2024 12:50, Torbjorn SVENSSON wrote:

Hi,

Forgot to mention when I sent the patch that I would like to commit it to the 
following branches:

- releases/gcc-11
- releases/gcc-12
- releases/gcc-13
- releases/gcc-14
- trunk



Well you can [commit it to the release branches], but I'm not sure it's 
essential.  It seems pretty unlikely to me that this would regress on a release 
branch without having first regressed on trunk.

R.


Kind regards,
Torbjörn

On 2024-05-02 12:50, Torbjörn SVENSSON wrote:

Add regression test to the existing zero/sign extend tests for CMSE to
verify that r0, r1, r2 and r3 are properly extended, not just r0.

boolCharShortEnumSecureFunc test is done using -O0 to ensure the
instructions are in a predictable order.

gcc/testsuite/ChangeLog:

  * gcc.target/arm/cmse/extend-param.c: Add regression test. Add
    -fshort-enums.
  * gcc.target/arm/cmse/extend-return.c: Add -fshort-enums option.

Signed-off-by: Torbjörn SVENSSON 
---
    .../gcc.target/arm/cmse/extend-param.c    | 21 +++
    .../gcc.target/arm/cmse/extend-return.c   |  4 ++--
    2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/gcc/testsuite/gcc.target/arm/cmse/extend-param.c 
b/gcc/testsuite/gcc.target/arm/cmse/extend-param.c
index 01fac786238..d01ef87e0be 100644
--- a/gcc/testsuite/gcc.target/arm/cmse/extend-param.c
+++ b/gcc/testsuite/gcc.target/arm/cmse/extend-param.c
@@ -1,5 +1,5 @@
    /* { dg-do compile } */
-/* { dg-options "-mcmse" } */
+/* { dg-options "-mcmse -fshort-enums" } */
    /* { dg-final { check-function-bodies "**" "" "" } } */
      #include 
@@ -78,7 +78,6 @@ __attribute__((cmse_nonsecure_entry)) char enumSecureFunc 
(enum offset index) {
  if (index >= ARRAY_SIZE)
    return 0;
  return array[index];
-
    }
      /*
@@ -88,9 +87,23 @@ __attribute__((cmse_nonsecure_entry)) char enumSecureFunc 
(enum offset index) {
    **    ...
    */
    __attribute__((cmse_nonsecure_entry)) char boolSecureFunc (bool index) {
-
  if (index >= ARRAY_SIZE)
    return 0;
  return array[index];
+}
    -}
\ No newline at end of file
+/*
+**__acle_se_boolCharShortEnumSecureFunc:
+**    ...
+**    uxtb    r0, r0
+**    uxtb    r1, r1
+**    uxth    r2, r2
+**    uxtb    r3, r3
+**    ...
+*/
+__attribute__((cmse_nonsecure_entry,optimize(0))) char 
boolCharShortEnumSecureFunc (bool a, unsigned char b, unsigned short c, enum 
offset d) {
+  size_t index = a + b + c + d;
+  if (index >= ARRAY_SIZE)
+    return 0;
+  return array[index];
+}
diff --git a/gcc/testsuite/gcc.target/arm/cmse/extend-return.c 
b/gcc/testsuite/gcc.target/arm/cmse/extend-return.c
index cf731ed33df..081de0d699f 100644
--- a/gcc/testsuite/gcc.target/arm/cmse/extend-return.c
+++ b/gcc/testsuite/gcc.target/arm/cmse/extend-return.c
@@ -1,5 +1,5 @@
    /* { dg-do compile } */
-/* { dg-options "-mcmse" } */
+/* { dg-options "-mcmse -fshort-enums" } */
    /* { dg-final { check-function-bodies "**" "" "" } } */
      #include 
@@ -89,4 +89,4 @@ unsigned char __attribute__((noipa)) enumNonsecure0 
(ns_enum_foo_t * ns_foo_p)
    unsigned char boolNonsecure0 (ns_bool_foo_t * ns_foo_p)
    {
  return ns_foo_p ();
-}
\ No newline at end of file
+}






Re: [PATCH v2] testsuite: Verify r0-r3 are extended with CMSE

2024-05-22 Thread Torbjorn SVENSSON

Hello Richard,

Thanks for the reply.

From my point of view, at least the -fshort-enums part should be on all 
branches. Just to be clean, maybe it's easier to backport the entire patch?


Unless you have an objection, I would like to go ahead and just backport 
it to all branches.


Kind regards,
Torbjörn

On 2024-05-22 12:55, Richard Earnshaw (lists) wrote:

On 06/05/2024 12:50, Torbjorn SVENSSON wrote:

Hi,

Forgot to mention when I sent the patch that I would like to commit it to the 
following branches:

- releases/gcc-11
- releases/gcc-12
- releases/gcc-13
- releases/gcc-14
- trunk



Well you can [commit it to the release branches], but I'm not sure it's 
essential.  It seems pretty unlikely to me that this would regress on a release 
branch without having first regressed on trunk.

R.


Kind regards,
Torbjörn

On 2024-05-02 12:50, Torbjörn SVENSSON wrote:

Add regression test to the existing zero/sign extend tests for CMSE to
verify that r0, r1, r2 and r3 are properly extended, not just r0.

boolCharShortEnumSecureFunc test is done using -O0 to ensure the
instructions are in a predictable order.

gcc/testsuite/ChangeLog:

 * gcc.target/arm/cmse/extend-param.c: Add regression test. Add
   -fshort-enums.
 * gcc.target/arm/cmse/extend-return.c: Add -fshort-enums option.

Signed-off-by: Torbjörn SVENSSON 
---
   .../gcc.target/arm/cmse/extend-param.c    | 21 +++
   .../gcc.target/arm/cmse/extend-return.c   |  4 ++--
   2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/gcc/testsuite/gcc.target/arm/cmse/extend-param.c 
b/gcc/testsuite/gcc.target/arm/cmse/extend-param.c
index 01fac786238..d01ef87e0be 100644
--- a/gcc/testsuite/gcc.target/arm/cmse/extend-param.c
+++ b/gcc/testsuite/gcc.target/arm/cmse/extend-param.c
@@ -1,5 +1,5 @@
   /* { dg-do compile } */
-/* { dg-options "-mcmse" } */
+/* { dg-options "-mcmse -fshort-enums" } */
   /* { dg-final { check-function-bodies "**" "" "" } } */
     #include 
@@ -78,7 +78,6 @@ __attribute__((cmse_nonsecure_entry)) char enumSecureFunc 
(enum offset index) {
     if (index >= ARRAY_SIZE)
   return 0;
     return array[index];
-
   }
     /*
@@ -88,9 +87,23 @@ __attribute__((cmse_nonsecure_entry)) char enumSecureFunc 
(enum offset index) {
   **    ...
   */
   __attribute__((cmse_nonsecure_entry)) char boolSecureFunc (bool index) {
-
     if (index >= ARRAY_SIZE)
   return 0;
     return array[index];
+}
   -}
\ No newline at end of file
+/*
+**__acle_se_boolCharShortEnumSecureFunc:
+**    ...
+**    uxtb    r0, r0
+**    uxtb    r1, r1
+**    uxth    r2, r2
+**    uxtb    r3, r3
+**    ...
+*/
+__attribute__((cmse_nonsecure_entry,optimize(0))) char 
boolCharShortEnumSecureFunc (bool a, unsigned char b, unsigned short c, enum 
offset d) {
+  size_t index = a + b + c + d;
+  if (index >= ARRAY_SIZE)
+    return 0;
+  return array[index];
+}
diff --git a/gcc/testsuite/gcc.target/arm/cmse/extend-return.c 
b/gcc/testsuite/gcc.target/arm/cmse/extend-return.c
index cf731ed33df..081de0d699f 100644
--- a/gcc/testsuite/gcc.target/arm/cmse/extend-return.c
+++ b/gcc/testsuite/gcc.target/arm/cmse/extend-return.c
@@ -1,5 +1,5 @@
   /* { dg-do compile } */
-/* { dg-options "-mcmse" } */
+/* { dg-options "-mcmse -fshort-enums" } */
   /* { dg-final { check-function-bodies "**" "" "" } } */
     #include 
@@ -89,4 +89,4 @@ unsigned char __attribute__((noipa)) enumNonsecure0 
(ns_enum_foo_t * ns_foo_p)
   unsigned char boolNonsecure0 (ns_bool_foo_t * ns_foo_p)
   {
     return ns_foo_p ();
-}
\ No newline at end of file
+}




[PING^2] [PATCH v2] testsuite: Verify r0-r3 are extended with CMSE

2024-05-21 Thread Torbjorn SVENSSON

Gentle ping!

Kind regards,
Torbjörn

On 2024-05-14 13:01, Torbjorn SVENSSON wrote:

Hi,

I'm not sure if the previous "ok" from Richard on the v1 is enough for 
this or if there needs another approval.


Adding extra maintainers since Richard Earnshaw appears to be busy the 
past weeks.


Kind regards,
Torbjörn

On 2024-05-06 13:50, Torbjorn SVENSSON wrote:

Hi,

Forgot to mention when I sent the patch that I would like to commit it 
to the following branches:


- releases/gcc-11
- releases/gcc-12
- releases/gcc-13
- releases/gcc-14
- trunk

Kind regards,
Torbjörn

On 2024-05-02 12:50, Torbjörn SVENSSON wrote:

Add regression test to the existing zero/sign extend tests for CMSE to
verify that r0, r1, r2 and r3 are properly extended, not just r0.

boolCharShortEnumSecureFunc test is done using -O0 to ensure the
instructions are in a predictable order.

gcc/testsuite/ChangeLog:

* gcc.target/arm/cmse/extend-param.c: Add regression test. Add
  -fshort-enums.
* gcc.target/arm/cmse/extend-return.c: Add -fshort-enums option.

Signed-off-by: Torbjörn SVENSSON 
---
  .../gcc.target/arm/cmse/extend-param.c    | 21 +++
  .../gcc.target/arm/cmse/extend-return.c   |  4 ++--
  2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/gcc/testsuite/gcc.target/arm/cmse/extend-param.c 
b/gcc/testsuite/gcc.target/arm/cmse/extend-param.c

index 01fac786238..d01ef87e0be 100644
--- a/gcc/testsuite/gcc.target/arm/cmse/extend-param.c
+++ b/gcc/testsuite/gcc.target/arm/cmse/extend-param.c
@@ -1,5 +1,5 @@
  /* { dg-do compile } */
-/* { dg-options "-mcmse" } */
+/* { dg-options "-mcmse -fshort-enums" } */
  /* { dg-final { check-function-bodies "**" "" "" } } */
  #include 
@@ -78,7 +78,6 @@ __attribute__((cmse_nonsecure_entry)) char 
enumSecureFunc (enum offset index) {

    if (index >= ARRAY_SIZE)
  return 0;
    return array[index];
-
  }
  /*
@@ -88,9 +87,23 @@ __attribute__((cmse_nonsecure_entry)) char 
enumSecureFunc (enum offset index) {

  **    ...
  */
  __attribute__((cmse_nonsecure_entry)) char boolSecureFunc (bool 
index) {

-
    if (index >= ARRAY_SIZE)
  return 0;
    return array[index];
+}
-}
\ No newline at end of file
+/*
+**__acle_se_boolCharShortEnumSecureFunc:
+**    ...
+**    uxtb    r0, r0
+**    uxtb    r1, r1
+**    uxth    r2, r2
+**    uxtb    r3, r3
+**    ...
+*/
+__attribute__((cmse_nonsecure_entry,optimize(0))) char 
boolCharShortEnumSecureFunc (bool a, unsigned char b, unsigned short 
c, enum offset d) {

+  size_t index = a + b + c + d;
+  if (index >= ARRAY_SIZE)
+    return 0;
+  return array[index];
+}
diff --git a/gcc/testsuite/gcc.target/arm/cmse/extend-return.c 
b/gcc/testsuite/gcc.target/arm/cmse/extend-return.c

index cf731ed33df..081de0d699f 100644
--- a/gcc/testsuite/gcc.target/arm/cmse/extend-return.c
+++ b/gcc/testsuite/gcc.target/arm/cmse/extend-return.c
@@ -1,5 +1,5 @@
  /* { dg-do compile } */
-/* { dg-options "-mcmse" } */
+/* { dg-options "-mcmse -fshort-enums" } */
  /* { dg-final { check-function-bodies "**" "" "" } } */
  #include 
@@ -89,4 +89,4 @@ unsigned char __attribute__((noipa)) enumNonsecure0 
(ns_enum_foo_t * ns_foo_p)

  unsigned char boolNonsecure0 (ns_bool_foo_t * ns_foo_p)
  {
    return ns_foo_p ();
-}
\ No newline at end of file
+}


[PING] [PATCH v2] testsuite: Verify r0-r3 are extended with CMSE

2024-05-14 Thread Torbjorn SVENSSON

Hi,

I'm not sure if the previous "ok" from Richard on the v1 is enough for 
this or if there needs another approval.


Adding extra maintainers since Richard Earnshaw appears to be busy the 
past weeks.


Kind regards,
Torbjörn

On 2024-05-06 13:50, Torbjorn SVENSSON wrote:

Hi,

Forgot to mention when I sent the patch that I would like to commit it 
to the following branches:


- releases/gcc-11
- releases/gcc-12
- releases/gcc-13
- releases/gcc-14
- trunk

Kind regards,
Torbjörn

On 2024-05-02 12:50, Torbjörn SVENSSON wrote:

Add regression test to the existing zero/sign extend tests for CMSE to
verify that r0, r1, r2 and r3 are properly extended, not just r0.

boolCharShortEnumSecureFunc test is done using -O0 to ensure the
instructions are in a predictable order.

gcc/testsuite/ChangeLog:

* gcc.target/arm/cmse/extend-param.c: Add regression test. Add
  -fshort-enums.
* gcc.target/arm/cmse/extend-return.c: Add -fshort-enums option.

Signed-off-by: Torbjörn SVENSSON 
---
  .../gcc.target/arm/cmse/extend-param.c    | 21 +++
  .../gcc.target/arm/cmse/extend-return.c   |  4 ++--
  2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/gcc/testsuite/gcc.target/arm/cmse/extend-param.c 
b/gcc/testsuite/gcc.target/arm/cmse/extend-param.c

index 01fac786238..d01ef87e0be 100644
--- a/gcc/testsuite/gcc.target/arm/cmse/extend-param.c
+++ b/gcc/testsuite/gcc.target/arm/cmse/extend-param.c
@@ -1,5 +1,5 @@
  /* { dg-do compile } */
-/* { dg-options "-mcmse" } */
+/* { dg-options "-mcmse -fshort-enums" } */
  /* { dg-final { check-function-bodies "**" "" "" } } */
  #include 
@@ -78,7 +78,6 @@ __attribute__((cmse_nonsecure_entry)) char 
enumSecureFunc (enum offset index) {

    if (index >= ARRAY_SIZE)
  return 0;
    return array[index];
-
  }
  /*
@@ -88,9 +87,23 @@ __attribute__((cmse_nonsecure_entry)) char 
enumSecureFunc (enum offset index) {

  **    ...
  */
  __attribute__((cmse_nonsecure_entry)) char boolSecureFunc (bool 
index) {

-
    if (index >= ARRAY_SIZE)
  return 0;
    return array[index];
+}
-}
\ No newline at end of file
+/*
+**__acle_se_boolCharShortEnumSecureFunc:
+**    ...
+**    uxtb    r0, r0
+**    uxtb    r1, r1
+**    uxth    r2, r2
+**    uxtb    r3, r3
+**    ...
+*/
+__attribute__((cmse_nonsecure_entry,optimize(0))) char 
boolCharShortEnumSecureFunc (bool a, unsigned char b, unsigned short 
c, enum offset d) {

+  size_t index = a + b + c + d;
+  if (index >= ARRAY_SIZE)
+    return 0;
+  return array[index];
+}
diff --git a/gcc/testsuite/gcc.target/arm/cmse/extend-return.c 
b/gcc/testsuite/gcc.target/arm/cmse/extend-return.c

index cf731ed33df..081de0d699f 100644
--- a/gcc/testsuite/gcc.target/arm/cmse/extend-return.c
+++ b/gcc/testsuite/gcc.target/arm/cmse/extend-return.c
@@ -1,5 +1,5 @@
  /* { dg-do compile } */
-/* { dg-options "-mcmse" } */
+/* { dg-options "-mcmse -fshort-enums" } */
  /* { dg-final { check-function-bodies "**" "" "" } } */
  #include 
@@ -89,4 +89,4 @@ unsigned char __attribute__((noipa)) enumNonsecure0 
(ns_enum_foo_t * ns_foo_p)

  unsigned char boolNonsecure0 (ns_bool_foo_t * ns_foo_p)
  {
    return ns_foo_p ();
-}
\ No newline at end of file
+}


Re: [PATCH v2] testsuite: Verify r0-r3 are extended with CMSE

2024-05-06 Thread Torbjorn SVENSSON

Hi,

Forgot to mention when I sent the patch that I would like to commit it 
to the following branches:


- releases/gcc-11
- releases/gcc-12
- releases/gcc-13
- releases/gcc-14
- trunk

Kind regards,
Torbjörn

On 2024-05-02 12:50, Torbjörn SVENSSON wrote:

Add regression test to the existing zero/sign extend tests for CMSE to
verify that r0, r1, r2 and r3 are properly extended, not just r0.

boolCharShortEnumSecureFunc test is done using -O0 to ensure the
instructions are in a predictable order.

gcc/testsuite/ChangeLog:

* gcc.target/arm/cmse/extend-param.c: Add regression test. Add
  -fshort-enums.
* gcc.target/arm/cmse/extend-return.c: Add -fshort-enums option.

Signed-off-by: Torbjörn SVENSSON 
---
  .../gcc.target/arm/cmse/extend-param.c| 21 +++
  .../gcc.target/arm/cmse/extend-return.c   |  4 ++--
  2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/gcc/testsuite/gcc.target/arm/cmse/extend-param.c 
b/gcc/testsuite/gcc.target/arm/cmse/extend-param.c
index 01fac786238..d01ef87e0be 100644
--- a/gcc/testsuite/gcc.target/arm/cmse/extend-param.c
+++ b/gcc/testsuite/gcc.target/arm/cmse/extend-param.c
@@ -1,5 +1,5 @@
  /* { dg-do compile } */
-/* { dg-options "-mcmse" } */
+/* { dg-options "-mcmse -fshort-enums" } */
  /* { dg-final { check-function-bodies "**" "" "" } } */
  
  #include 

@@ -78,7 +78,6 @@ __attribute__((cmse_nonsecure_entry)) char enumSecureFunc 
(enum offset index) {
if (index >= ARRAY_SIZE)
  return 0;
return array[index];
-
  }
  
  /*

@@ -88,9 +87,23 @@ __attribute__((cmse_nonsecure_entry)) char enumSecureFunc 
(enum offset index) {
  **...
  */
  __attribute__((cmse_nonsecure_entry)) char boolSecureFunc (bool index) {
-
if (index >= ARRAY_SIZE)
  return 0;
return array[index];
+}
  
-}

\ No newline at end of file
+/*
+**__acle_se_boolCharShortEnumSecureFunc:
+** ...
+** uxtbr0, r0
+** uxtbr1, r1
+** uxthr2, r2
+** uxtbr3, r3
+** ...
+*/
+__attribute__((cmse_nonsecure_entry,optimize(0))) char 
boolCharShortEnumSecureFunc (bool a, unsigned char b, unsigned short c, enum 
offset d) {
+  size_t index = a + b + c + d;
+  if (index >= ARRAY_SIZE)
+return 0;
+  return array[index];
+}
diff --git a/gcc/testsuite/gcc.target/arm/cmse/extend-return.c 
b/gcc/testsuite/gcc.target/arm/cmse/extend-return.c
index cf731ed33df..081de0d699f 100644
--- a/gcc/testsuite/gcc.target/arm/cmse/extend-return.c
+++ b/gcc/testsuite/gcc.target/arm/cmse/extend-return.c
@@ -1,5 +1,5 @@
  /* { dg-do compile } */
-/* { dg-options "-mcmse" } */
+/* { dg-options "-mcmse -fshort-enums" } */
  /* { dg-final { check-function-bodies "**" "" "" } } */
  
  #include 

@@ -89,4 +89,4 @@ unsigned char __attribute__((noipa)) enumNonsecure0 
(ns_enum_foo_t * ns_foo_p)
  unsigned char boolNonsecure0 (ns_bool_foo_t * ns_foo_p)
  {
return ns_foo_p ();
-}
\ No newline at end of file
+}


Re: [PATCH] testsuite: Verify r0-r3 are extended with CMSE

2024-04-30 Thread Torbjorn SVENSSON




On 2024-04-30 17:11, Richard Earnshaw (lists) wrote:

On 27/04/2024 15:13, Torbjörn SVENSSON wrote:

Add regression test to the existing zero/sign extend tests for CMSE to
verify that r0, r1, r2 and r3 are properly extended, not just r0.

Test is done using -O0 to ensure the instructions are in a predictable
order.

gcc/testsuite/ChangeLog:

* gcc.target/arm/cmse/extend-param.c: Add regression test.

Signed-off-by: Torbjörn SVENSSON 
---
  .../gcc.target/arm/cmse/extend-param.c| 20 ++-
  1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.target/arm/cmse/extend-param.c 
b/gcc/testsuite/gcc.target/arm/cmse/extend-param.c
index 01fac786238..b8b8ecbff56 100644
--- a/gcc/testsuite/gcc.target/arm/cmse/extend-param.c
+++ b/gcc/testsuite/gcc.target/arm/cmse/extend-param.c
@@ -93,4 +93,22 @@ __attribute__((cmse_nonsecure_entry)) char boolSecureFunc 
(bool index) {
  return 0;
return array[index];
  
-}

\ No newline at end of file
+}
+
+/*
+**__acle_se_boolCharShortEnumSecureFunc:
+** ...
+** uxtbr0, r0
+** uxtbr1, r1
+** uxthr2, r2
+** uxtbr3, r3
+** ...
+*/
+__attribute__((cmse_nonsecure_entry,optimize(0))) char 
boolCharShortEnumSecureFunc (bool a, unsigned char b, unsigned short c, enum 
offset d) {
+
+  size_t index = a + b + c + d;
+  if (index >= ARRAY_SIZE)
+return 0;
+  return array[index];
+
+}


Ok, but please can you add '-fshort-enums' to dg-options to ensure this test 
still behaves correctly if run with a different default (I missed that last 
time around).


Ok, I'll add that to extend-param.c. Do you want me to also add it to 
the extend-return.c test case?


Kind regards,
Torbjörn


Re: [PATCH] arm: Zero/Sign extends for CMSE security

2024-04-26 Thread Torbjorn SVENSSON

Hi,

On 2024-04-25 16:25, Richard Ball wrote:

Hi Torbjorn,

Thanks very much for the comments.
I think given that the code that handles this, is within a 
FOREACH_FUNCTION_ARGS loop.
It seems a fairly safe assumption that if the code works for one that it 
will work for all.

To go back and add extra tests to me seems a little overkill.


For verifying that the implementation does the right thing now, no, but 
for verifying against future regressions, then yes.


So, from a regression point of view, I think it makes sense to have the 
check that more than the first argument is managed properly.


Kind regards,
Torbjörn


Re: [PATCH] arm: Zero/Sign extends for CMSE security

2024-04-25 Thread Torbjorn SVENSSON

Hi,

On 2024-04-24 17:55, Richard Ball wrote:

This patch makes the following changes:

1) When calling a secure function from non-secure code then any arguments
smaller than 32-bits that are passed in registers are zero- or 
sign-extended.
2) After a non-secure function returns into secure code then any return value
smaller than 32-bits that is passed in a register is  zero- or 
sign-extended.

This patch addresses the following CVE-2024-0151.

gcc/ChangeLog:
 PR target/114837
 * config/arm/arm.cc (cmse_nonsecure_call_inline_register_clear):
   Add zero/sign extend.
 (arm_expand_prologue): Add zero/sign extend.

gcc/testsuite/ChangeLog:

 * gcc.target/arm/cmse/extend-param.c: New test.
 * gcc.target/arm/cmse/extend-return.c: New test.


I think it would make sense that there is at least one test case that 
takes 2 or more arguments to ensure that not only the first argument is 
extended. WDYT?



Kind regards,
Torbjörn


Re: [PING^5] Re: [PATCH] analyzer: deal with -fshort-enums

2024-04-10 Thread Torbjorn SVENSSON

Ping!

Kind regards,
Torbjörn

On 2024-03-25 15:59, Yvan ROUX - foss wrote:

Ping!

Rgds,
Yvan

From: Torbjorn SVENSSON - foss
Sent: Friday, March 15, 2024 11:32 AM
To: David Malcolm; Alexandre Oliva
Cc: gcc-patches@gcc.gnu.org; Yvan ROUX - foss
Subject: [PING^3] Re: [PATCH] analyzer: deal with -fshort-enums

Ping!

Kind regards,
Torbjörn

On 2024-03-08 10:14, Torbjorn SVENSSON wrote:

Ping!

Kind regards,
Torbjörn

On 2024-02-22 09:51, Torbjorn SVENSSON wrote:

Ping!

Kind regards,
Torbjörn

On 2024-02-07 17:21, Torbjorn SVENSSON wrote:

Hi,

Is it okay to backport 3cbab07b08d2f3a3ed34b6ec12e67727c59d285c to
releases/gcc-13?

Without this backport, I see these failures on arm-none-eabi:

FAIL: gcc.dg/analyzer/switch-enum-1.c  (test for bogus messages, line
26)
FAIL: gcc.dg/analyzer/switch-enum-1.c  (test for bogus messages, line
44)
FAIL: gcc.dg/analyzer/switch-enum-2.c  (test for bogus messages, line
34)
FAIL: gcc.dg/analyzer/switch-enum-2.c  (test for bogus messages, line
52)
FAIL: gcc.dg/analyzer/torture/switch-enum-pr105273-doom-p_floor.c -O0
   (test for bogus messages, line 82)
FAIL: gcc.dg/analyzer/torture/switch-enum-pr105273-doom-p_maputl.c
-O0(test for bogus messages, line 83)

Kind regards,
Torbjörn


On 2023-12-06 23:22, David Malcolm wrote:

On Wed, 2023-12-06 at 02:31 -0300, Alexandre Oliva wrote:

On Nov 22, 2023, Alexandre Oliva  wrote:


Ah, nice, that's a great idea, I wish I'd thought of that!  Will
do.


Sorry it took me so long, here it is.  I added two tests, so that,
regardless of the defaults, we get both circumstances tested, without
repetition.

Regstrapped on x86_64-linux-gnu.  Also tested on arm-eabi.  Ok to
install?


Thanks for the updated patch.

Looks good to me.

Dave




analyzer: deal with -fshort-enums

On platforms that enable -fshort-enums by default, various switch-
enum
analyzer tests fail, because apply_constraints_for_gswitch doesn't
expect the integral promotion type cast.  I've arranged for the code
to cope with those casts.


for  gcc/analyzer/ChangeLog

  * region-model.cc (has_nondefault_case_for_value_p): Take
  enumerate type as a parameter.
  (region_model::apply_constraints_for_gswitch): Cope with
  integral promotion type casts.

for  gcc/testsuite/ChangeLog

  * gcc.dg/analyzer/switch-short-enum-1.c: New.
  * gcc.dg/analyzer/switch-no-short-enum-1.c: New.
---
   gcc/analyzer/region-model.cc   |   27 +++-
   .../gcc.dg/analyzer/switch-no-short-enum-1.c   |  141

   .../gcc.dg/analyzer/switch-short-enum-1.c  |  140

   3 files changed, 304 insertions(+), 4 deletions(-)
   create mode 100644 gcc/testsuite/gcc.dg/analyzer/switch-no-short-
enum-1.c
   create mode 100644 gcc/testsuite/gcc.dg/analyzer/switch-short-enum-
1.c

diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-
model.cc
index 2157ad2578b85..6a7a8bc9f4884 100644
--- a/gcc/analyzer/region-model.cc
+++ b/gcc/analyzer/region-model.cc
@@ -5387,10 +5387,10 @@ has_nondefault_case_for_value_p (const
gswitch *switch_stmt, tree int_cst)
  has nondefault cases handling all values in the enum.  */
   static bool
-has_nondefault_cases_for_all_enum_values_p (const gswitch
*switch_stmt)
+has_nondefault_cases_for_all_enum_values_p (const gswitch
*switch_stmt,
+   tree type)
   {
 gcc_assert (switch_stmt);
-  tree type = TREE_TYPE (gimple_switch_index (switch_stmt));
 gcc_assert (TREE_CODE (type) == ENUMERAL_TYPE);
 for (tree enum_val_iter = TYPE_VALUES (type);
@@ -5426,6 +5426,23 @@ apply_constraints_for_gswitch (const
switch_cfg_superedge ,
   {
 tree index  = gimple_switch_index (switch_stmt);
 const svalue *index_sval = get_rvalue (index, ctxt);
+  bool check_index_type = true;
+
+  /* With -fshort-enum, there may be a type cast.  */
+  if (ctxt && index_sval->get_kind () == SK_UNARYOP
+  && TREE_CODE (index_sval->get_type ()) == INTEGER_TYPE)
+{
+  const unaryop_svalue *unaryop = as_a 
(index_sval);
+  if (unaryop->get_op () == NOP_EXPR
+ && is_a  (unaryop->get_arg ()))
+   if (const initial_svalue *initvalop = (as_a 
+  (unaryop->get_arg
(
+ if (TREE_CODE (initvalop->get_type ()) == ENUMERAL_TYPE)
+   {
+ index_sval = initvalop;
+ check_index_type = false;
+   }
+}
 /* If we're switching based on an enum type, assume that the user
is only
working with values from the enum.  Hence if this is an
@@ -5437,12 +5454,14 @@ apply_constraints_for_gswitch (const
switch_cfg_superedge ,
 ctxt
 /* Must be an enum value.  */
 && index_sval->get_type ()
-  && TREE_CODE (TREE_TYPE (index)) == ENUMERAL_TYPE
+  && (!check_index_type
+ || 

Re: [PATCH] testsuite: Define _POSIX_C_SOURCE for test

2024-03-18 Thread Torbjorn SVENSSON




On 2024-03-17 18:48, Mike Stump wrote:

On Mar 10, 2024, at 10:26 AM, Torbjörn SVENSSON  
wrote:


Ok for trunk?


Ok.


Pushed as basepoints/gcc-14-9513-g58753dba800 to trunk.

Kind regards,
Torbjörn


[PING] Re: [PATCH] testsuite: Define _POSIX_C_SOURCE for test

2024-03-16 Thread Torbjorn SVENSSON

Ping!

Kind regards,
Torbjörn

On 2024-03-10 18:26, Torbjörn SVENSSON wrote:

Ok for trunk?

--

As the tests assume that strndup() is visible (only part of
POSIX.1-2008) define the guard to ensure that it's visible.  Currently,
glibc appears to always have this defined in C++, newlib does not.

Without this patch, fails like this can be seen:

Testing analyzer/strndup-1.c,  -std=c++98
.../strndup-1.c: In function 'void test_1(const char*)':
.../strndup-1.c:11:13: error: 'strndup' was not declared in this scope; did you 
mean 'strncmp'?
.../strndup-1.c: In function 'void test_2(const char*)':
.../strndup-1.c:16:13: error: 'strndup' was not declared in this scope; did you 
mean 'strncmp'?
.../strndup-1.c: In function 'void test_3(const char*)':
.../strndup-1.c:21:13: error: 'strndup' was not declared in this scope; did you 
mean 'strncmp'?

Patch has been verified on Linux.

gcc/testsuite/ChangeLog:

* c-c++-common/analyzer/strndup-1.c: Define _POSIX_C_SOURCE.

Signed-off-by: Torbjörn SVENSSON 
---
  gcc/testsuite/c-c++-common/analyzer/strndup-1.c | 1 +
  1 file changed, 1 insertion(+)

diff --git a/gcc/testsuite/c-c++-common/analyzer/strndup-1.c 
b/gcc/testsuite/c-c++-common/analyzer/strndup-1.c
index 85ccae85d83..577ece0cfba 100644
--- a/gcc/testsuite/c-c++-common/analyzer/strndup-1.c
+++ b/gcc/testsuite/c-c++-common/analyzer/strndup-1.c
@@ -1,4 +1,5 @@
  /* { dg-skip-if "no strndup in libc" { *-*-darwin[789]* *-*-darwin10* 
hppa*-*-hpux* *-*-mingw* *-*-vxworks* } } */
+/* { dg-additional-options "-D_POSIX_C_SOURCE=200809L" } */
  
  #include 

  #include 


[PING^3] Re: [PATCH] analyzer: deal with -fshort-enums

2024-03-15 Thread Torbjorn SVENSSON

Ping!

Kind regards,
Torbjörn

On 2024-03-08 10:14, Torbjorn SVENSSON wrote:

Ping!

Kind regards,
Torbjörn

On 2024-02-22 09:51, Torbjorn SVENSSON wrote:

Ping!

Kind regards,
Torbjörn

On 2024-02-07 17:21, Torbjorn SVENSSON wrote:

Hi,

Is it okay to backport 3cbab07b08d2f3a3ed34b6ec12e67727c59d285c to 
releases/gcc-13?


Without this backport, I see these failures on arm-none-eabi:

FAIL: gcc.dg/analyzer/switch-enum-1.c  (test for bogus messages, line 
26)
FAIL: gcc.dg/analyzer/switch-enum-1.c  (test for bogus messages, line 
44)
FAIL: gcc.dg/analyzer/switch-enum-2.c  (test for bogus messages, line 
34)
FAIL: gcc.dg/analyzer/switch-enum-2.c  (test for bogus messages, line 
52)
FAIL: gcc.dg/analyzer/torture/switch-enum-pr105273-doom-p_floor.c -O0 
  (test for bogus messages, line 82)
FAIL: gcc.dg/analyzer/torture/switch-enum-pr105273-doom-p_maputl.c 
-O0    (test for bogus messages, line 83)


Kind regards,
Torbjörn


On 2023-12-06 23:22, David Malcolm wrote:

On Wed, 2023-12-06 at 02:31 -0300, Alexandre Oliva wrote:

On Nov 22, 2023, Alexandre Oliva  wrote:


Ah, nice, that's a great idea, I wish I'd thought of that!  Will
do.


Sorry it took me so long, here it is.  I added two tests, so that,
regardless of the defaults, we get both circumstances tested, without
repetition.

Regstrapped on x86_64-linux-gnu.  Also tested on arm-eabi.  Ok to
install?


Thanks for the updated patch.

Looks good to me.

Dave




analyzer: deal with -fshort-enums

On platforms that enable -fshort-enums by default, various switch-
enum
analyzer tests fail, because apply_constraints_for_gswitch doesn't
expect the integral promotion type cast.  I've arranged for the code
to cope with those casts.


for  gcc/analyzer/ChangeLog

 * region-model.cc (has_nondefault_case_for_value_p): Take
 enumerate type as a parameter.
 (region_model::apply_constraints_for_gswitch): Cope with
 integral promotion type casts.

for  gcc/testsuite/ChangeLog

 * gcc.dg/analyzer/switch-short-enum-1.c: New.
 * gcc.dg/analyzer/switch-no-short-enum-1.c: New.
---
  gcc/analyzer/region-model.cc   |   27 +++-
  .../gcc.dg/analyzer/switch-no-short-enum-1.c   |  141

  .../gcc.dg/analyzer/switch-short-enum-1.c  |  140

  3 files changed, 304 insertions(+), 4 deletions(-)
  create mode 100644 gcc/testsuite/gcc.dg/analyzer/switch-no-short-
enum-1.c
  create mode 100644 gcc/testsuite/gcc.dg/analyzer/switch-short-enum-
1.c

diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-
model.cc
index 2157ad2578b85..6a7a8bc9f4884 100644
--- a/gcc/analyzer/region-model.cc
+++ b/gcc/analyzer/region-model.cc
@@ -5387,10 +5387,10 @@ has_nondefault_case_for_value_p (const
gswitch *switch_stmt, tree int_cst)
 has nondefault cases handling all values in the enum.  */
  static bool
-has_nondefault_cases_for_all_enum_values_p (const gswitch
*switch_stmt)
+has_nondefault_cases_for_all_enum_values_p (const gswitch
*switch_stmt,
+   tree type)
  {
    gcc_assert (switch_stmt);
-  tree type = TREE_TYPE (gimple_switch_index (switch_stmt));
    gcc_assert (TREE_CODE (type) == ENUMERAL_TYPE);
    for (tree enum_val_iter = TYPE_VALUES (type);
@@ -5426,6 +5426,23 @@ apply_constraints_for_gswitch (const
switch_cfg_superedge ,
  {
    tree index  = gimple_switch_index (switch_stmt);
    const svalue *index_sval = get_rvalue (index, ctxt);
+  bool check_index_type = true;
+
+  /* With -fshort-enum, there may be a type cast.  */
+  if (ctxt && index_sval->get_kind () == SK_UNARYOP
+  && TREE_CODE (index_sval->get_type ()) == INTEGER_TYPE)
+    {
+  const unaryop_svalue *unaryop = as_a 
(index_sval);
+  if (unaryop->get_op () == NOP_EXPR
+ && is_a  (unaryop->get_arg ()))
+   if (const initial_svalue *initvalop = (as_a 
+  (unaryop->get_arg
(
+ if (TREE_CODE (initvalop->get_type ()) == ENUMERAL_TYPE)
+   {
+ index_sval = initvalop;
+ check_index_type = false;
+   }
+    }
    /* If we're switching based on an enum type, assume that the user
is only
   working with values from the enum.  Hence if this is an
@@ -5437,12 +5454,14 @@ apply_constraints_for_gswitch (const
switch_cfg_superedge ,
    ctxt
    /* Must be an enum value.  */
    && index_sval->get_type ()
-  && TREE_CODE (TREE_TYPE (index)) == ENUMERAL_TYPE
+  && (!check_index_type
+ || TREE_CODE (TREE_TYPE (index)) == ENUMERAL_TYPE)
    && TREE_CODE (index_sval->get_type ()) == ENUMERAL_TYPE
    /* If we have a constant, then we can check it directly.  */
    && index_sval->get_kind () != SK_CONSTANT
    && edge.implicitly_created_default_p ()
-  && has_nondefault_

Re: [PATCH v2] testsuite: xfail test for short_enums

2024-03-13 Thread Torbjorn SVENSSON




On 2024-03-12 14:21, Jason Merrill wrote:

On 3/11/24 06:23, Torbjörn SVENSSON wrote:

Changes compared to v1:
- Added reference to r14-6517-gb7e4a4c626e in dg-bogus comment
- Changed arm-*-* to short_enums in target selector
- Updated commit message to align with above changes


As the entire block generating the warning was removed in
r14-6517-gb7e4a4c626e, does it still make sense to add something to
trunk for the same line?
Do you want me to add the dg-bogus, but change "xfail" to "target" for
trunk?


Sounds good.


Pushed as basepoints/gcc-14-9452-g5a44e14eb4f




Is this patch ok for releases/gcc-13?


OK.


Pushed as releases/gcc-13.2.0-824-g1277f69b9b0

Kind regards,
Torbjörn


[PING^2] Re: [PATCH] analyzer: deal with -fshort-enums

2024-03-08 Thread Torbjorn SVENSSON

Ping!

Kind regards,
Torbjörn

On 2024-02-22 09:51, Torbjorn SVENSSON wrote:

Ping!

Kind regards,
Torbjörn

On 2024-02-07 17:21, Torbjorn SVENSSON wrote:

Hi,

Is it okay to backport 3cbab07b08d2f3a3ed34b6ec12e67727c59d285c to 
releases/gcc-13?


Without this backport, I see these failures on arm-none-eabi:

FAIL: gcc.dg/analyzer/switch-enum-1.c  (test for bogus messages, line 26)
FAIL: gcc.dg/analyzer/switch-enum-1.c  (test for bogus messages, line 44)
FAIL: gcc.dg/analyzer/switch-enum-2.c  (test for bogus messages, line 34)
FAIL: gcc.dg/analyzer/switch-enum-2.c  (test for bogus messages, line 52)
FAIL: gcc.dg/analyzer/torture/switch-enum-pr105273-doom-p_floor.c   
-O0   (test for bogus messages, line 82)
FAIL: gcc.dg/analyzer/torture/switch-enum-pr105273-doom-p_maputl.c   
-O0    (test for bogus messages, line 83)


Kind regards,
Torbjörn


On 2023-12-06 23:22, David Malcolm wrote:

On Wed, 2023-12-06 at 02:31 -0300, Alexandre Oliva wrote:

On Nov 22, 2023, Alexandre Oliva  wrote:


Ah, nice, that's a great idea, I wish I'd thought of that!  Will
do.


Sorry it took me so long, here it is.  I added two tests, so that,
regardless of the defaults, we get both circumstances tested, without
repetition.

Regstrapped on x86_64-linux-gnu.  Also tested on arm-eabi.  Ok to
install?


Thanks for the updated patch.

Looks good to me.

Dave




analyzer: deal with -fshort-enums

On platforms that enable -fshort-enums by default, various switch-
enum
analyzer tests fail, because apply_constraints_for_gswitch doesn't
expect the integral promotion type cast.  I've arranged for the code
to cope with those casts.


for  gcc/analyzer/ChangeLog

 * region-model.cc (has_nondefault_case_for_value_p): Take
 enumerate type as a parameter.
 (region_model::apply_constraints_for_gswitch): Cope with
 integral promotion type casts.

for  gcc/testsuite/ChangeLog

 * gcc.dg/analyzer/switch-short-enum-1.c: New.
 * gcc.dg/analyzer/switch-no-short-enum-1.c: New.
---
  gcc/analyzer/region-model.cc   |   27 +++-
  .../gcc.dg/analyzer/switch-no-short-enum-1.c   |  141

  .../gcc.dg/analyzer/switch-short-enum-1.c  |  140

  3 files changed, 304 insertions(+), 4 deletions(-)
  create mode 100644 gcc/testsuite/gcc.dg/analyzer/switch-no-short-
enum-1.c
  create mode 100644 gcc/testsuite/gcc.dg/analyzer/switch-short-enum-
1.c

diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-
model.cc
index 2157ad2578b85..6a7a8bc9f4884 100644
--- a/gcc/analyzer/region-model.cc
+++ b/gcc/analyzer/region-model.cc
@@ -5387,10 +5387,10 @@ has_nondefault_case_for_value_p (const
gswitch *switch_stmt, tree int_cst)
 has nondefault cases handling all values in the enum.  */
  static bool
-has_nondefault_cases_for_all_enum_values_p (const gswitch
*switch_stmt)
+has_nondefault_cases_for_all_enum_values_p (const gswitch
*switch_stmt,
+   tree type)
  {
    gcc_assert (switch_stmt);
-  tree type = TREE_TYPE (gimple_switch_index (switch_stmt));
    gcc_assert (TREE_CODE (type) == ENUMERAL_TYPE);
    for (tree enum_val_iter = TYPE_VALUES (type);
@@ -5426,6 +5426,23 @@ apply_constraints_for_gswitch (const
switch_cfg_superedge ,
  {
    tree index  = gimple_switch_index (switch_stmt);
    const svalue *index_sval = get_rvalue (index, ctxt);
+  bool check_index_type = true;
+
+  /* With -fshort-enum, there may be a type cast.  */
+  if (ctxt && index_sval->get_kind () == SK_UNARYOP
+  && TREE_CODE (index_sval->get_type ()) == INTEGER_TYPE)
+    {
+  const unaryop_svalue *unaryop = as_a 
(index_sval);
+  if (unaryop->get_op () == NOP_EXPR
+ && is_a  (unaryop->get_arg ()))
+   if (const initial_svalue *initvalop = (as_a 
+  (unaryop->get_arg
(
+ if (TREE_CODE (initvalop->get_type ()) == ENUMERAL_TYPE)
+   {
+ index_sval = initvalop;
+ check_index_type = false;
+   }
+    }
    /* If we're switching based on an enum type, assume that the user
is only
   working with values from the enum.  Hence if this is an
@@ -5437,12 +5454,14 @@ apply_constraints_for_gswitch (const
switch_cfg_superedge ,
    ctxt
    /* Must be an enum value.  */
    && index_sval->get_type ()
-  && TREE_CODE (TREE_TYPE (index)) == ENUMERAL_TYPE
+  && (!check_index_type
+ || TREE_CODE (TREE_TYPE (index)) == ENUMERAL_TYPE)
    && TREE_CODE (index_sval->get_type ()) == ENUMERAL_TYPE
    /* If we have a constant, then we can check it directly.  */
    && index_sval->get_kind () != SK_CONSTANT
    && edge.implicitly_created_default_p ()
-  && has_nondefault_cases_for_all_enum_values_p (switch_stmt)
+  && has_nondefault_cases_for_all_enum_values_

Re: [PATCH] arm: Fixed C23 call compatibility with arm-none-eabi

2024-03-04 Thread Torbjorn SVENSSON




On 2024-03-01 15:58, Richard Earnshaw (lists) wrote:

On 19/02/2024 09:13, Torbjörn SVENSSON wrote:

Ok for trunk and releases/gcc-13?
Regtested on top of 945cb8490cb for arm-none-eabi, without any regression.

Backporting to releases/gcc-13 will change -std=c23 to -std=c2x.


Jakub has just pushed a different fix for this, so I don't think we need this 
now.

R.


Would it still be benificial to have the 2 test cases for the AAPCS 
validation?


Kind regards,
Torbjörn






--

In commit 4fe34cdcc80ac225b80670eabc38ac5e31ce8a5a, -std=c23 support was
introduced to support functions without any named arguments.  For
arm-none-eabi, this is not as simple as placing all arguments on the
stack.  Align the caller to use r0, r1, r2 and r3 for arguments even for
functions without any named arguments, as specified in the AAPCS.

Verify that the generic test case have the arguments are in the right
order and add ARM specific test cases.

gcc/ChangeLog:

* calls.h: Added the type of the function to function_arg_info.
* calls.cc: Save the type of the function.
* config/arm/arm.cc: Check in the AAPCS layout function if
function has no named args.

gcc/testsuite/ChangeLog:

* gcc.dg/torture/c23-stdarg-split-1a.c: Detect out of order
arguments.
* gcc.dg/torture/c23-stdarg-split-1b.c: Likewise.
* gcc.target/arm/aapcs/align_vaarg3.c: New test.
* gcc.target/arm/aapcs/align_vaarg4.c: New test.

Signed-off-by: Torbjörn SVENSSON 
Co-authored-by: Yvan ROUX 
---
  gcc/calls.cc  |  2 +-
  gcc/calls.h   | 20 --
  gcc/config/arm/arm.cc | 13 ---
  .../gcc.dg/torture/c23-stdarg-split-1a.c  |  4 +-
  .../gcc.dg/torture/c23-stdarg-split-1b.c  | 15 +---
  .../gcc.target/arm/aapcs/align_vaarg3.c   | 37 +++
  .../gcc.target/arm/aapcs/align_vaarg4.c   | 31 
  7 files changed, 102 insertions(+), 20 deletions(-)
  create mode 100644 gcc/testsuite/gcc.target/arm/aapcs/align_vaarg3.c
  create mode 100644 gcc/testsuite/gcc.target/arm/aapcs/align_vaarg4.c

diff --git a/gcc/calls.cc b/gcc/calls.cc
index 01f44734743..a1cc283b952 100644
--- a/gcc/calls.cc
+++ b/gcc/calls.cc
@@ -1376,7 +1376,7 @@ initialize_argument_information (int num_actuals 
ATTRIBUTE_UNUSED,
 with those made by function.cc.  */
  
/* See if this argument should be passed by invisible reference.  */

-  function_arg_info arg (type, argpos < n_named_args);
+  function_arg_info arg (type, fntype, argpos < n_named_args);
if (pass_by_reference (args_so_far_pnt, arg))
{
  const bool callee_copies
diff --git a/gcc/calls.h b/gcc/calls.h
index 464a4e34e33..88836559ebe 100644
--- a/gcc/calls.h
+++ b/gcc/calls.h
@@ -35,24 +35,33 @@ class function_arg_info
  {
  public:
function_arg_info ()
-: type (NULL_TREE), mode (VOIDmode), named (false),
+: type (NULL_TREE), fntype (NULL_TREE), mode (VOIDmode), named (false),
pass_by_reference (false)
{}
  
/* Initialize an argument of mode MODE, either before or after promotion.  */

function_arg_info (machine_mode mode, bool named)
-: type (NULL_TREE), mode (mode), named (named), pass_by_reference (false)
+: type (NULL_TREE), fntype (NULL_TREE), mode (mode), named (named),
+pass_by_reference (false)
{}
  
/* Initialize an unpromoted argument of type TYPE.  */

function_arg_info (tree type, bool named)
-: type (type), mode (TYPE_MODE (type)), named (named),
+: type (type), fntype (NULL_TREE), mode (TYPE_MODE (type)), named (named),
pass_by_reference (false)
{}
  
+  /* Initialize an unpromoted argument of type TYPE with a known function type

+ FNTYPE.  */
+  function_arg_info (tree type, tree fntype, bool named)
+: type (type), fntype (fntype), mode (TYPE_MODE (type)), named (named),
+pass_by_reference (false)
+  {}
+
/* Initialize an argument with explicit properties.  */
function_arg_info (tree type, machine_mode mode, bool named)
-: type (type), mode (mode), named (named), pass_by_reference (false)
+: type (type), fntype (NULL_TREE), mode (mode), named (named),
+pass_by_reference (false)
{}
  
/* Return true if the gimple-level type is an aggregate.  */

@@ -96,6 +105,9 @@ public:
   libgcc support functions).  */
tree type;
  
+  /* The type of the function that has this argument, or null if not known.  */

+  tree fntype;
+
/* The mode of the argument.  Depending on context, this might be
   the mode of the argument type or the mode after promotion.  */
machine_mode mode;
diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc
index 1cd69268ee9..98e149e5b7e 100644
--- a/gcc/config/arm/arm.cc
+++ b/gcc/config/arm/arm.cc
@@ -7006,7 +7006,7 @@ aapcs_libcall_value (machine_mode mode)
 numbers referred to here are those in the AAPCS.  */

[PING] Re: [PATCH 1/2] c-family: -Waddress-of-packed-member and casts

2024-02-22 Thread Torbjorn SVENSSON

Ping!

Kind regards,
Torbjörn


On 2024-02-07 17:19, Torbjorn SVENSSON wrote:

Hi,

Is it okay to backport b7e4a4c626eeeb32c291d5bbbaa148c5081b6bfd to 
releases/gcc-13?


Without this backport, I see these failures on arm-none-eabi:

FAIL: 
gcc.dg/analyzer/null-deref-pr108251-smp_fetch_ssl_fc_has_early-O2.c 
(test for excess errors)
FAIL: gcc.dg/analyzer/null-deref-pr108251-smp_fetch_ssl_fc_has_early.c 
(test for excess errors)


Kind regards,
Torbjörn

On 2023-12-11 08:28, Richard Biener wrote:

On Wed, Nov 22, 2023 at 11:45 PM Jason Merrill  wrote:


Tested x86_64-pc-linux-gnu, OK for trunk?


OK


-- 8< --

-Waddress-of-packed-member, in addition to the documented warning about
taking the address of a packed member, also warns about casting from
a pointer to a TYPE_PACKED type to a pointer to a type with greater
alignment.

This wrongly warns if the source is a pointer to enum when -fshort-enums
is on, since that is also represented by TYPE_PACKED.

And there's already -Wcast-align to catch casting from pointer to less
aligned type (packed or otherwise) to pointer to more aligned type; even
apart from the enum problem, this seems like a somewhat arbitrary 
subset of

that warning.  Though that isn't currently on by default.

So, this patch removes the undocumented type-based warning from
-Waddress-of-packed-member.  Some of the tests where the warning is
desirable I changed to use -Wcast-align=strict instead.  The ones that
require -Wno-incompatible-pointer-types, I just removed.

gcc/c-family/ChangeLog:

 * c-warn.cc (check_address_or_pointer_of_packed_member):
 Remove warning based on TYPE_PACKED.

gcc/testsuite/ChangeLog:

 * c-c++-common/Waddress-of-packed-member-1.c: Don't expect
 a warning on the cast cases.
 * c-c++-common/pr51628-35.c: Use -Wcast-align=strict.
 * g++.dg/warn/Waddress-of-packed-member3.C: Likewise.
 * gcc.dg/pr88928.c: Likewise.
 * gcc.dg/pr51628-20.c: Removed.
 * gcc.dg/pr51628-21.c: Removed.
 * gcc.dg/pr51628-25.c: Removed.
---
  gcc/c-family/c-warn.cc    | 58 +--
  .../Waddress-of-packed-member-1.c | 12 ++--
  gcc/testsuite/c-c++-common/pr51628-35.c   |  6 +-
  .../g++.dg/warn/Waddress-of-packed-member3.C  |  8 +--
  gcc/testsuite/gcc.dg/pr51628-20.c | 11 
  gcc/testsuite/gcc.dg/pr51628-21.c | 11 
  gcc/testsuite/gcc.dg/pr51628-25.c |  9 ---
  gcc/testsuite/gcc.dg/pr88928.c    |  6 +-
  8 files changed, 19 insertions(+), 102 deletions(-)
  delete mode 100644 gcc/testsuite/gcc.dg/pr51628-20.c
  delete mode 100644 gcc/testsuite/gcc.dg/pr51628-21.c
  delete mode 100644 gcc/testsuite/gcc.dg/pr51628-25.c

diff --git a/gcc/c-family/c-warn.cc b/gcc/c-family/c-warn.cc
index d2938b91043..2a399ba6d14 100644
--- a/gcc/c-family/c-warn.cc
+++ b/gcc/c-family/c-warn.cc
@@ -2991,10 +2991,9 @@ check_alignment_of_packed_member (tree type, 
tree field, bool rvalue)

    return NULL_TREE;
  }

-/* Return struct or union type if the right hand value, RHS:
-   1. Is a pointer value which isn't aligned to a pointer type TYPE.
-   2. Is an address which takes the unaligned address of packed member
-  of struct or union when assigning to TYPE.
+/* Return struct or union type if the right hand value, RHS
+   is an address which takes the unaligned address of packed member
+   of struct or union when assigning to TYPE.
 Otherwise, return NULL_TREE.  */

  static tree
@@ -3021,57 +3020,6 @@ check_address_or_pointer_of_packed_member 
(tree type, tree rhs)


    type = TREE_TYPE (type);

-  if (TREE_CODE (rhs) == PARM_DECL
-  || VAR_P (rhs)
-  || TREE_CODE (rhs) == CALL_EXPR)
-    {
-  tree rhstype = TREE_TYPE (rhs);
-  if (TREE_CODE (rhs) == CALL_EXPR)
-   {
- rhs = CALL_EXPR_FN (rhs); /* Pointer expression.  */
- if (rhs == NULL_TREE)
-   return NULL_TREE;
- rhs = TREE_TYPE (rhs);    /* Pointer type.  */
- /* We could be called while processing a template and RHS 
could be

-    a functor.  In that case it's a class, not a pointer.  */
- if (!rhs || !POINTER_TYPE_P (rhs))
-   return NULL_TREE;
- rhs = TREE_TYPE (rhs);    /* Function type.  */
- rhstype = TREE_TYPE (rhs);
- if (!rhstype || !POINTER_TYPE_P (rhstype))
-   return NULL_TREE;
- rvalue = true;
-   }
-  if (rvalue && POINTER_TYPE_P (rhstype))
-   rhstype = TREE_TYPE (rhstype);
-  while (TREE_CODE (rhstype) == ARRAY_TYPE)
-   rhstype = TREE_TYPE (rhstype);
-  if (TYPE_PACKED (rhstype))
-   {
- unsigned int type_align = min_align_of_type (type);
- unsigned int rhs_align = min_align_of_type (rhstype);
- if (rhs_align < type_align)
-   {
- auto_diagnostic_group d;
- location_t location = EXPR_LOC_OR_LOC (rhs, 

[PING] Re: [PATCH] analyzer: deal with -fshort-enums

2024-02-22 Thread Torbjorn SVENSSON

Ping!

Kind regards,
Torbjörn

On 2024-02-07 17:21, Torbjorn SVENSSON wrote:

Hi,

Is it okay to backport 3cbab07b08d2f3a3ed34b6ec12e67727c59d285c to 
releases/gcc-13?


Without this backport, I see these failures on arm-none-eabi:

FAIL: gcc.dg/analyzer/switch-enum-1.c  (test for bogus messages, line 26)
FAIL: gcc.dg/analyzer/switch-enum-1.c  (test for bogus messages, line 44)
FAIL: gcc.dg/analyzer/switch-enum-2.c  (test for bogus messages, line 34)
FAIL: gcc.dg/analyzer/switch-enum-2.c  (test for bogus messages, line 52)
FAIL: gcc.dg/analyzer/torture/switch-enum-pr105273-doom-p_floor.c   -O0 
  (test for bogus messages, line 82)
FAIL: gcc.dg/analyzer/torture/switch-enum-pr105273-doom-p_maputl.c   -O0 
   (test for bogus messages, line 83)


Kind regards,
Torbjörn


On 2023-12-06 23:22, David Malcolm wrote:

On Wed, 2023-12-06 at 02:31 -0300, Alexandre Oliva wrote:

On Nov 22, 2023, Alexandre Oliva  wrote:


Ah, nice, that's a great idea, I wish I'd thought of that!  Will
do.


Sorry it took me so long, here it is.  I added two tests, so that,
regardless of the defaults, we get both circumstances tested, without
repetition.

Regstrapped on x86_64-linux-gnu.  Also tested on arm-eabi.  Ok to
install?


Thanks for the updated patch.

Looks good to me.

Dave




analyzer: deal with -fshort-enums

On platforms that enable -fshort-enums by default, various switch-
enum
analyzer tests fail, because apply_constraints_for_gswitch doesn't
expect the integral promotion type cast.  I've arranged for the code
to cope with those casts.


for  gcc/analyzer/ChangeLog

 * region-model.cc (has_nondefault_case_for_value_p): Take
 enumerate type as a parameter.
 (region_model::apply_constraints_for_gswitch): Cope with
 integral promotion type casts.

for  gcc/testsuite/ChangeLog

 * gcc.dg/analyzer/switch-short-enum-1.c: New.
 * gcc.dg/analyzer/switch-no-short-enum-1.c: New.
---
  gcc/analyzer/region-model.cc   |   27 +++-
  .../gcc.dg/analyzer/switch-no-short-enum-1.c   |  141

  .../gcc.dg/analyzer/switch-short-enum-1.c  |  140

  3 files changed, 304 insertions(+), 4 deletions(-)
  create mode 100644 gcc/testsuite/gcc.dg/analyzer/switch-no-short-
enum-1.c
  create mode 100644 gcc/testsuite/gcc.dg/analyzer/switch-short-enum-
1.c

diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-
model.cc
index 2157ad2578b85..6a7a8bc9f4884 100644
--- a/gcc/analyzer/region-model.cc
+++ b/gcc/analyzer/region-model.cc
@@ -5387,10 +5387,10 @@ has_nondefault_case_for_value_p (const
gswitch *switch_stmt, tree int_cst)
 has nondefault cases handling all values in the enum.  */
  static bool
-has_nondefault_cases_for_all_enum_values_p (const gswitch
*switch_stmt)
+has_nondefault_cases_for_all_enum_values_p (const gswitch
*switch_stmt,
+   tree type)
  {
    gcc_assert (switch_stmt);
-  tree type = TREE_TYPE (gimple_switch_index (switch_stmt));
    gcc_assert (TREE_CODE (type) == ENUMERAL_TYPE);
    for (tree enum_val_iter = TYPE_VALUES (type);
@@ -5426,6 +5426,23 @@ apply_constraints_for_gswitch (const
switch_cfg_superedge ,
  {
    tree index  = gimple_switch_index (switch_stmt);
    const svalue *index_sval = get_rvalue (index, ctxt);
+  bool check_index_type = true;
+
+  /* With -fshort-enum, there may be a type cast.  */
+  if (ctxt && index_sval->get_kind () == SK_UNARYOP
+  && TREE_CODE (index_sval->get_type ()) == INTEGER_TYPE)
+    {
+  const unaryop_svalue *unaryop = as_a 
(index_sval);
+  if (unaryop->get_op () == NOP_EXPR
+ && is_a  (unaryop->get_arg ()))
+   if (const initial_svalue *initvalop = (as_a 
+  (unaryop->get_arg
(
+ if (TREE_CODE (initvalop->get_type ()) == ENUMERAL_TYPE)
+   {
+ index_sval = initvalop;
+ check_index_type = false;
+   }
+    }
    /* If we're switching based on an enum type, assume that the user
is only
   working with values from the enum.  Hence if this is an
@@ -5437,12 +5454,14 @@ apply_constraints_for_gswitch (const
switch_cfg_superedge ,
    ctxt
    /* Must be an enum value.  */
    && index_sval->get_type ()
-  && TREE_CODE (TREE_TYPE (index)) == ENUMERAL_TYPE
+  && (!check_index_type
+ || TREE_CODE (TREE_TYPE (index)) == ENUMERAL_TYPE)
    && TREE_CODE (index_sval->get_type ()) == ENUMERAL_TYPE
    /* If we have a constant, then we can check it directly.  */
    && index_sval->get_kind () != SK_CONSTANT
    && edge.implicitly_created_default_p ()
-  && has_nondefault_cases_for_all_enum_values_p (switch_stmt)
+  && has_nondefault_cases_for_all_enum_values_p (switch_stmt,
+    inde

Re: [PATCH] testsuite: Define _POSIX_SOURCE for tests [PR113278]

2024-02-15 Thread Torbjorn SVENSSON




On 2024-02-15 18:18, Mike Stump wrote:

On Feb 15, 2024, at 9:03 AM, Torbjörn SVENSSON  
wrote:


Ok for trunk?


Ok.


Pushed as 8e8c2d2b34971bb29e74341a3efc625f1db06639.




gcc/testsuite/ChangeLog:
PR113278
* c-c++-common/analyzer/fileno-1.c: Define _POSIX_SOURCE.
* c-c++-common/analyzer/flex-with-call-summaries.c: Same.
* c-c++-common/analyzer/flex-without-call-summaries.c: Same.


Re: [PATCH] testsuite: Update test case to comply with GCC14 changes

2024-02-11 Thread Torbjorn SVENSSON




On 2024-02-11 20:01, Mike Stump wrote:

On Feb 10, 2024, at 7:21 AM, Torbjörn SVENSSON  
wrote:


I have confirmed that this updated pr97969.c file still hangs with
gcc-arm-none-eabi-9-2020-q2-update as mentioned in comment 2 of PR97969.

Ok for trunk?


Ok.


Pushed as f85450819414700a7883a7de128b03f655f43d44.


Re: [PATCH] call maybe_return_this in build_clone

2024-02-09 Thread Torbjorn SVENSSON




On 2024-02-09 19:57, Jason Merrill wrote:

On 2/7/24 11:24, Torbjorn SVENSSON wrote:

Hi,

Is it okay to backport 0d24289d129639efdc79338a64188d6d404375e8 to 
releases/gcc-13?


OK.


Pushed as 583bd84075d23cde5fd489ab726093060870d773.


Re: [PATCH] [testsuite] tsvc: skip include malloc.h when unavailable

2024-02-09 Thread Torbjorn SVENSSON




On 2024-02-09 11:34, Richard Biener wrote:

On Fri, Feb 9, 2024 at 11:33 AM Torbjorn SVENSSON
 wrote:


Hi,

Is it okay to backport 2f20d6296087cae51f55eeecb3efefe786191fd6 to
releases/gcc-13?


Yes.


Pushed as 5b3dcff46780192a2e526bc434d61c8626898050.


Re: [PATCH] [testsuite] tsvc: skip include malloc.h when unavailable

2024-02-09 Thread Torbjorn SVENSSON

Hi,

Is it okay to backport 2f20d6296087cae51f55eeecb3efefe786191fd6 to 
releases/gcc-13?


Without this backport, I see about 150 failures on arm-none-eabi, an 
example of them is:


FAIL: gcc.dg/vect/tsvc/vect-tsvc-s000.c (test for excess errors)


Kind regards,
Torbjörn

On 2023-05-24 11:02, Richard Biener via Gcc-patches wrote:

On Wed, May 24, 2023 at 7:17 AM Alexandre Oliva via Gcc-patches
 wrote:



tsvc tests all fail on systems that don't offer a malloc.h, other than
those that explicitly rule that out.  Use the preprocessor to test for
malloc.h's availability.

tsvc.h also expects a definition for struct timeval, but it doesn't
include sys/time.h.  Add a conditional include thereof.

Bootstrapped on x86_64-linux-gnu.  Also tested on ppc- and x86-vx7r2
with gcc-12.


OK.



for  gcc/testsuite/ChangeLog

 * gcc.dg/vect/tsvc/tsvc.h: Test for and conditionally include
 malloc.h and sys/time.h.

---
  gcc/testsuite/gcc.dg/vect/tsvc/tsvc.h |5 -
  1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/vect/tsvc/tsvc.h 
b/gcc/testsuite/gcc.dg/vect/tsvc/tsvc.h
index 75494c24cfa62..cd39c041903dd 100644
--- a/gcc/testsuite/gcc.dg/vect/tsvc/tsvc.h
+++ b/gcc/testsuite/gcc.dg/vect/tsvc/tsvc.h
@@ -11,9 +11,12 @@

  #include 
  #include 
-#if !defined(__APPLE__) && !defined(__DragonFly__)
+#if __has_include()
  #include 
  #endif
+#if __has_include()
+#include 
+#endif
  #include 
  #include 


--
Alexandre Oliva, happy hackerhttps://FSFLA.org/blogs/lxo/
Free Software Activist   GNU Toolchain Engineer
Disinformation flourishes because many people care deeply about injustice
but very few check the facts.  Ask me about 


Re: [PATCH v2] libstdc++: optimize bit iterators assuming normalization [PR110807]

2024-02-09 Thread Torbjorn SVENSSON




On 2024-02-07 17:36, Jonathan Wakely wrote:



On Wed, 7 Feb 2024 at 16:25, Torbjorn SVENSSON 
mailto:torbjorn.svens...@foss.st.com>> 
wrote:


Hi,

Is it okay to backport e39b3e02c27bd771a07e385f9672ecf1a45ced77 to
releases/gcc-13?


It would also need 807f47497f17ed50be91f0f879308cb6fa063966

Please test with that as well, and OK for both if all goes well.


Test was passed on arm-none-eabi for both these.
Pushed as 5d684a5f7f82b1425cac5eaa11dccc3b51a62d44 and 
adef1e0ebeb5055ed4e8776fd3f73c9d84821eaa.


Re: [PATCH v2] testsuite: Pattern does not match when using --specs=nano.specs

2024-02-09 Thread Torbjorn SVENSSON




On 2024-02-09 01:07, Mike Stump wrote:

On Feb 8, 2024, at 9:44 AM, Torbjörn SVENSSON  
wrote:


Changes since v1:
- Replaced .* with [^\r\n]* to avoid matching newline.

Ok for trunk and releases/gcc-13?


Ok.


Pushed as 1175d1b35ce7bf8ee7c9b37b334370f01eb95335 and 
810b0b3f75c454da3f6b5722870716796d2d7a83.


Re: [PATCH] c++: for contracts, cdtors never return this

2024-02-09 Thread Torbjorn SVENSSON




On 2024-02-07 20:46, Jason Merrill wrote:

On 2/7/24 11:22, Torbjorn SVENSSON wrote:

Hi,

Is it okay to backport 71804526d3a71a8c0f189a89ce3aa615784bfd8b to 
releases/gcc-13?


OK.


Pushed as eae51472f68d9f922aa3a1a636f81467bfdae87a.


Re: Ping: [PATCH v2 1/2] testsuite: Add dg-require-atomic-cmpxchg-word

2024-02-07 Thread Torbjorn SVENSSON




On 2024-02-07 17:33, Jonathan Wakely wrote:



On Wed, 7 Feb 2024 at 16:31, Torbjorn SVENSSON 
mailto:torbjorn.svens...@foss.st.com>> 
wrote:


Hi,

Is it okay to backport 62b29347c38394ae32858f2301aa9aa65205984e,
2a4d9e4f533c77870cc0eb60fbbd8047da4c7386 and
ba0cde8ba2d93b7193050eb5ef3cc6f7a2cdfe61 to releases/gcc-13?

Without this backport, I see these failures on arm-none-eabi:

FAIL: 29_atomics/atomic/compare_exchange_padding.cc (test for excess
errors)
FAIL: 29_atomics/atomic_ref/compare_exchange_padding.cc (test for
excess
errors)


Yes, OK


Pushed as b937b1189069b24f8d1a5c25d8f062029784fb0c, 
fa0e0c28ee8f6ca2f8d5c50737647bef734dc898 and 
18fd8d29b27ec9ace70098b4a451f5296276812e.


Re: [PATCH 1/2] Fix contracts-tmpl-spec2.C on targets where plain char is unsigned by default

2024-02-07 Thread Torbjorn SVENSSON




On 2024-02-07 18:13, Andrew Pinski (QUIC) wrote:

-Original Message-
From: Torbjorn SVENSSON 
Sent: Wednesday, February 7, 2024 8:23 AM
To: Andrew Pinski (QUIC) ; gcc-
patc...@gcc.gnu.org
Cc: Yvan Roux 
Subject: Re: [PATCH 1/2] Fix contracts-tmpl-spec2.C on targets where plain
char is unsigned by default

Hi,

Is it okay to backport 6e15e4e1abed02443a27a69455f4bfa49457c99e to
releases/gcc-13?


 From my point of view, this is ok to backport. It is just a testsuite change 
so I didn't think it was important enough to backport from an user of GCC point 
of view.


Pushed as 0cdb04629641c51498f099db04021e8de51adedb.


Re: Ping: [PATCH v2 1/2] testsuite: Add dg-require-atomic-cmpxchg-word

2024-02-07 Thread Torbjorn SVENSSON

Hi,

Is it okay to backport 62b29347c38394ae32858f2301aa9aa65205984e, 
2a4d9e4f533c77870cc0eb60fbbd8047da4c7386 and 
ba0cde8ba2d93b7193050eb5ef3cc6f7a2cdfe61 to releases/gcc-13?


Without this backport, I see these failures on arm-none-eabi:

FAIL: 29_atomics/atomic/compare_exchange_padding.cc (test for excess errors)
FAIL: 29_atomics/atomic_ref/compare_exchange_padding.cc (test for excess 
errors)


Kind regards,
Torbjörn

On 2023-10-13 00:23, Jonathan Wakely wrote:



On Thu, 12 Oct 2023, 17:11 Jeff Law, > wrote:




On 10/12/23 08:38, Christophe Lyon wrote:
 > LGTM but I'm not a maintainer ;-)
LGTM to as well -- I usually try to stay out of libstdc++, but this
looks simple enough.  Both patches in this series are OK.


Thanks for stepping in, Jeff. The patches are indeed fine, I'm just 
offline due to circumstances beyond my control. I hope normal service 
will resume soon.





Re: [PATCH v2] libstdc++: optimize bit iterators assuming normalization [PR110807]

2024-02-07 Thread Torbjorn SVENSSON

Hi,

Is it okay to backport e39b3e02c27bd771a07e385f9672ecf1a45ced77 to 
releases/gcc-13?


Without this backport, I see this failure on arm-none-eabi:

FAIL: 23_containers/vector/bool/110807.cc (test for excess errors)

Kind regards,
Torbjörn


On 2023-11-09 02:22, Jonathan Wakely wrote:



On Thu, 9 Nov 2023, 01:17 Alexandre Oliva, > wrote:


On Nov  8, 2023, Jonathan Wakely mailto:jwak...@redhat.com>> wrote:

 > A single underscore prefix on __GLIBCXX_BUILTIN_ASSUME and
 > __GLIBCXX_DISABLE_ASSUMPTIONS please.

That's entirely gone now.

 >> +    do                                              \
 >> +      if (std::is_constant_evaluated ())    \
 >> +    static_assert(expr);                    \

 > This can never be valid.

*nod*

 > This already works fine in constant evaluation anyway.

Yeah, that's what I figured.

 > But what's the null dereference for?

The idea was to clearly trigger undefined behavior.  Maybe it wasn't
needed, it didn't occur to me that __builtin_unreachable() would be
enough.  I realize I was really trying to emulate attribute assume, even
without knowing it existed ;-)

 >> +#define __GLIBCXX_BUILTIN_ASSUME(expr)              \
 >> +    (void)(false && (expr))

 > What's the point of this, just to verify that (expr) is contextually
 > convertible to bool?

I'd have phrased it as "avoid the case in which something compiles with
-O0 but not with -O", but yeah ;-)

 > We don't use the _p suffix for predicates in the library.
 > Please use just _M_normalized or _M_is_normalized.

ACK.  It's also gone now.

 > But do we even need this function? It's not used anywhere else,
can we
 > just inline the condition into _M_assume_normalized() ?

I had other uses for it in earlier versions of the patch, but it makes
no sense any more indeed.

 >> +    _GLIBCXX20_CONSTEXPR
 >> +    void
 >> +    _M_assume_normalized() const

 > I think this should use _GLIBCXX_ALWAYS_INLINE

*nod*, thanks

 >> +    {
 >> +      __GLIBCXX_BUILTIN_ASSUME (_M_normalized_p ());

 > Is there even any benefit to this macro?

I just thought it could have other uses, without being aware that the
entire concept was available as a statement attribute.  Funny, I'd even
searched for it among the existing attributes and builtins, but somehow
I managed to miss it.  Thanks for getting me back down that path.

 >        __attribute__((__assume__(_M_offset <
unsigned(_S_word_bit;

That unfortunately doesn't work, because the assume lowering doesn't go
as far as dereferencing the implicit this and making an SSA_NAME out of
the loaded _M_offset, which we'd need to be able to optimize based on
it.  But that only took me a while to figure out and massage into
something that had the desired effect.  Now, maybe the above *should*
have that effect already, but unfortunately it doesn't.

 > Maybe even get rid of _M_assume_normalized() as a function and just
 > put that attribute everywhere you currently use _M_assume_normalized.

Because of the slight kludge required to make the attribute have the
desired effect (namely ensuring the _M_offset reference is evaluated),
I've retained it as an inline function.

Here's what I'm retesting now.  WDYT?


ofst needs to be __ofst but OK for trunk with that change.

We probably want this on the gcc-13 branch too, but let's give it some 
time on trunk in case the assume attribute isn't quite ready for prime time.


Re: [PATCH] call maybe_return_this in build_clone

2024-02-07 Thread Torbjorn SVENSSON

Hi,

Is it okay to backport 0d24289d129639efdc79338a64188d6d404375e8 to 
releases/gcc-13?


Without this backport, I see these failures on arm-none-eabi:

FAIL: g++.dg/warn/Wuse-after-free3.C  -std=gnu++14 (test for excess errors)
FAIL: g++.dg/warn/Wuse-after-free3.C  -std=gnu++17 (test for excess errors)
FAIL: g++.dg/warn/Wuse-after-free3.C  -std=gnu++20 (test for excess errors)

Kind regards,
Torbjörn

On 2023-11-22 09:26, Alexandre Oliva wrote:

On Nov 20, 2023, Jason Merrill  wrote:


So it only passed on that platform before because of the bug?


I'm not sure it passed (we've had patches for that testcase before), but
I didn't look closely enough into their history to tell.  I suspected
the warning suppression machinery changed, or details on cloning did, or
something.  It's been fragile historically.  But yeah, recently, the
test for the warning was only passing because of the bug.  But we were
also getting excess warnings, so it wasn't fully passing.


Thanks for the reviews!



Re: [PATCH 1/2] Fix contracts-tmpl-spec2.C on targets where plain char is unsigned by default

2024-02-07 Thread Torbjorn SVENSSON

Hi,

Is it okay to backport 6e15e4e1abed02443a27a69455f4bfa49457c99e to 
releases/gcc-13?


Without this backport, I see this failure on arm-none-eabi:

FAIL: g++.dg/contracts/contracts-tmpl-spec2.C   output pattern test

Kind regards,
Torbjörn


On 2023-11-26 03:57, Andrew Pinski wrote:

Since contracts-tmpl-spec2.C is just testing contracts, I thought it would be 
better
to just add `-fsigned-char` to the options rather than change the testcase to 
support
both cases.

Committed after testing on aarch64-linux-gnu.

gcc/testsuite/ChangeLog:

PR testsuite/108321
* g++.dg/contracts/contracts-tmpl-spec2.C: Add -fsigned-char
to options.
---
  gcc/testsuite/g++.dg/contracts/contracts-tmpl-spec2.C | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/g++.dg/contracts/contracts-tmpl-spec2.C 
b/gcc/testsuite/g++.dg/contracts/contracts-tmpl-spec2.C
index 82117671b2d..fd3a25bd051 100644
--- a/gcc/testsuite/g++.dg/contracts/contracts-tmpl-spec2.C
+++ b/gcc/testsuite/g++.dg/contracts/contracts-tmpl-spec2.C
@@ -1,6 +1,6 @@
  // basic test to ensure contracts work for class and member specializations
  // { dg-do run }
-// { dg-options "-std=c++2a -fcontracts -fcontract-continuation-mode=on" }
+// { dg-options "-std=c++2a -fcontracts -fcontract-continuation-mode=on 
-fsigned-char" }
  #include 
  
  // template specializations can have differing contracts


Re: [PATCH] c++: for contracts, cdtors never return this

2024-02-07 Thread Torbjorn SVENSSON

Hi,

Is it okay to backport 71804526d3a71a8c0f189a89ce3aa615784bfd8b to 
releases/gcc-13?


Without this backport, I see these failures on arm-none-eabi:

FAIL: g++.dg/contracts/contracts-ctor-dtor2.C(test for errors, line 23)
FAIL: g++.dg/contracts/contracts-ctor-dtor2.C(test for errors, line 27

Kind regards,
Torbjörn

On 2023-11-20 16:40, Jason Merrill wrote:

On 11/19/23 02:28, Alexandre Oliva wrote:


When targetm.cxx.cdtor_return_this() holds, cdtors have a
non-VOID_TYPE_P result, but IMHO this ABI implementation detail
shouldn't leak to the abstract language conceptual framework, in which
cdtors don't have return values.  For contracts, specifically those
that establish postconditions on results, such a leakage is present,
and the present patch puts an end to it: with it, cdtors get an error
for result postconditions regardless of the ABI.  This fixes
g++.dg/contracts/contracts-ctor-dtor2.C on arm-eabi.

Regstrapped on x86_64-linux-gnu, also tested on arm-eabi with default
cpu on trunk, and with tms570 on gcc-13.  Ok to install?


OK.



for  gcc/cp/ChangeLog

* contracts.cc (check_postcondition_result): Cope with
cdtor_return_this.
---
  gcc/cp/contracts.cc |    6 +-
  1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/contracts.cc b/gcc/cp/contracts.cc
index 66d2298a9bfac..035ca4827e758 100644
--- a/gcc/cp/contracts.cc
+++ b/gcc/cp/contracts.cc
@@ -636,7 +636,11 @@ make_postcondition_variable (cp_expr id)
  bool
  check_postcondition_result (tree decl, tree type, location_t loc)
  {
-  if (VOID_TYPE_P (type))
+  /* Do not be confused by targetm.cxx.cdtor_return_this ();
+ conceptually, cdtors have no return value.  */
+  if (VOID_TYPE_P (type)
+  || DECL_CONSTRUCTOR_P (decl)
+  || DECL_DESTRUCTOR_P (decl))
  {
    error_at (loc,
  DECL_CONSTRUCTOR_P (decl)






Re: [PATCH] analyzer: deal with -fshort-enums

2024-02-07 Thread Torbjorn SVENSSON

Hi,

Is it okay to backport 3cbab07b08d2f3a3ed34b6ec12e67727c59d285c to 
releases/gcc-13?


Without this backport, I see these failures on arm-none-eabi:

FAIL: gcc.dg/analyzer/switch-enum-1.c  (test for bogus messages, line 26)
FAIL: gcc.dg/analyzer/switch-enum-1.c  (test for bogus messages, line 44)
FAIL: gcc.dg/analyzer/switch-enum-2.c  (test for bogus messages, line 34)
FAIL: gcc.dg/analyzer/switch-enum-2.c  (test for bogus messages, line 52)
FAIL: gcc.dg/analyzer/torture/switch-enum-pr105273-doom-p_floor.c   -O0 
 (test for bogus messages, line 82)
FAIL: gcc.dg/analyzer/torture/switch-enum-pr105273-doom-p_maputl.c   -O0 
  (test for bogus messages, line 83)


Kind regards,
Torbjörn


On 2023-12-06 23:22, David Malcolm wrote:

On Wed, 2023-12-06 at 02:31 -0300, Alexandre Oliva wrote:

On Nov 22, 2023, Alexandre Oliva  wrote:


Ah, nice, that's a great idea, I wish I'd thought of that!  Will
do.


Sorry it took me so long, here it is.  I added two tests, so that,
regardless of the defaults, we get both circumstances tested, without
repetition.

Regstrapped on x86_64-linux-gnu.  Also tested on arm-eabi.  Ok to
install?


Thanks for the updated patch.

Looks good to me.

Dave




analyzer: deal with -fshort-enums

On platforms that enable -fshort-enums by default, various switch-
enum
analyzer tests fail, because apply_constraints_for_gswitch doesn't
expect the integral promotion type cast.  I've arranged for the code
to cope with those casts.


for  gcc/analyzer/ChangeLog

 * region-model.cc (has_nondefault_case_for_value_p): Take
 enumerate type as a parameter.
 (region_model::apply_constraints_for_gswitch): Cope with
 integral promotion type casts.

for  gcc/testsuite/ChangeLog

 * gcc.dg/analyzer/switch-short-enum-1.c: New.
 * gcc.dg/analyzer/switch-no-short-enum-1.c: New.
---
  gcc/analyzer/region-model.cc   |   27 +++-
  .../gcc.dg/analyzer/switch-no-short-enum-1.c   |  141

  .../gcc.dg/analyzer/switch-short-enum-1.c  |  140

  3 files changed, 304 insertions(+), 4 deletions(-)
  create mode 100644 gcc/testsuite/gcc.dg/analyzer/switch-no-short-
enum-1.c
  create mode 100644 gcc/testsuite/gcc.dg/analyzer/switch-short-enum-
1.c

diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-
model.cc
index 2157ad2578b85..6a7a8bc9f4884 100644
--- a/gcc/analyzer/region-model.cc
+++ b/gcc/analyzer/region-model.cc
@@ -5387,10 +5387,10 @@ has_nondefault_case_for_value_p (const
gswitch *switch_stmt, tree int_cst)
     has nondefault cases handling all values in the enum.  */
  
  static bool

-has_nondefault_cases_for_all_enum_values_p (const gswitch
*switch_stmt)
+has_nondefault_cases_for_all_enum_values_p (const gswitch
*switch_stmt,
+   tree type)
  {
    gcc_assert (switch_stmt);
-  tree type = TREE_TYPE (gimple_switch_index (switch_stmt));
    gcc_assert (TREE_CODE (type) == ENUMERAL_TYPE);
  
    for (tree enum_val_iter = TYPE_VALUES (type);

@@ -5426,6 +5426,23 @@ apply_constraints_for_gswitch (const
switch_cfg_superedge ,
  {
    tree index  = gimple_switch_index (switch_stmt);
    const svalue *index_sval = get_rvalue (index, ctxt);
+  bool check_index_type = true;
+
+  /* With -fshort-enum, there may be a type cast.  */
+  if (ctxt && index_sval->get_kind () == SK_UNARYOP
+  && TREE_CODE (index_sval->get_type ()) == INTEGER_TYPE)
+    {
+  const unaryop_svalue *unaryop = as_a 
(index_sval);
+  if (unaryop->get_op () == NOP_EXPR
+ && is_a  (unaryop->get_arg ()))
+   if (const initial_svalue *initvalop = (as_a 
+  (unaryop->get_arg
(
+ if (TREE_CODE (initvalop->get_type ()) == ENUMERAL_TYPE)
+   {
+ index_sval = initvalop;
+ check_index_type = false;
+   }
+    }
  
    /* If we're switching based on an enum type, assume that the user

is only
   working with values from the enum.  Hence if this is an
@@ -5437,12 +5454,14 @@ apply_constraints_for_gswitch (const
switch_cfg_superedge ,
    ctxt
    /* Must be an enum value.  */
    && index_sval->get_type ()
-  && TREE_CODE (TREE_TYPE (index)) == ENUMERAL_TYPE
+  && (!check_index_type
+ || TREE_CODE (TREE_TYPE (index)) == ENUMERAL_TYPE)
    && TREE_CODE (index_sval->get_type ()) == ENUMERAL_TYPE
    /* If we have a constant, then we can check it directly.  */
    && index_sval->get_kind () != SK_CONSTANT
    && edge.implicitly_created_default_p ()
-  && has_nondefault_cases_for_all_enum_values_p (switch_stmt)
+  && has_nondefault_cases_for_all_enum_values_p (switch_stmt,
+    index_sval-

get_type ())

    /* Don't do this if there's a chance that the index is
  attacker-controlled.  */
    && !ctxt->possibly_tainted_p (index_sval))
diff --git 

Re: [PATCH 1/2] c-family: -Waddress-of-packed-member and casts

2024-02-07 Thread Torbjorn SVENSSON

Hi,

Is it okay to backport b7e4a4c626eeeb32c291d5bbbaa148c5081b6bfd to 
releases/gcc-13?


Without this backport, I see these failures on arm-none-eabi:

FAIL: 
gcc.dg/analyzer/null-deref-pr108251-smp_fetch_ssl_fc_has_early-O2.c 
(test for excess errors)
FAIL: gcc.dg/analyzer/null-deref-pr108251-smp_fetch_ssl_fc_has_early.c 
(test for excess errors)


Kind regards,
Torbjörn

On 2023-12-11 08:28, Richard Biener wrote:

On Wed, Nov 22, 2023 at 11:45 PM Jason Merrill  wrote:


Tested x86_64-pc-linux-gnu, OK for trunk?


OK


-- 8< --

-Waddress-of-packed-member, in addition to the documented warning about
taking the address of a packed member, also warns about casting from
a pointer to a TYPE_PACKED type to a pointer to a type with greater
alignment.

This wrongly warns if the source is a pointer to enum when -fshort-enums
is on, since that is also represented by TYPE_PACKED.

And there's already -Wcast-align to catch casting from pointer to less
aligned type (packed or otherwise) to pointer to more aligned type; even
apart from the enum problem, this seems like a somewhat arbitrary subset of
that warning.  Though that isn't currently on by default.

So, this patch removes the undocumented type-based warning from
-Waddress-of-packed-member.  Some of the tests where the warning is
desirable I changed to use -Wcast-align=strict instead.  The ones that
require -Wno-incompatible-pointer-types, I just removed.

gcc/c-family/ChangeLog:

 * c-warn.cc (check_address_or_pointer_of_packed_member):
 Remove warning based on TYPE_PACKED.

gcc/testsuite/ChangeLog:

 * c-c++-common/Waddress-of-packed-member-1.c: Don't expect
 a warning on the cast cases.
 * c-c++-common/pr51628-35.c: Use -Wcast-align=strict.
 * g++.dg/warn/Waddress-of-packed-member3.C: Likewise.
 * gcc.dg/pr88928.c: Likewise.
 * gcc.dg/pr51628-20.c: Removed.
 * gcc.dg/pr51628-21.c: Removed.
 * gcc.dg/pr51628-25.c: Removed.
---
  gcc/c-family/c-warn.cc| 58 +--
  .../Waddress-of-packed-member-1.c | 12 ++--
  gcc/testsuite/c-c++-common/pr51628-35.c   |  6 +-
  .../g++.dg/warn/Waddress-of-packed-member3.C  |  8 +--
  gcc/testsuite/gcc.dg/pr51628-20.c | 11 
  gcc/testsuite/gcc.dg/pr51628-21.c | 11 
  gcc/testsuite/gcc.dg/pr51628-25.c |  9 ---
  gcc/testsuite/gcc.dg/pr88928.c|  6 +-
  8 files changed, 19 insertions(+), 102 deletions(-)
  delete mode 100644 gcc/testsuite/gcc.dg/pr51628-20.c
  delete mode 100644 gcc/testsuite/gcc.dg/pr51628-21.c
  delete mode 100644 gcc/testsuite/gcc.dg/pr51628-25.c

diff --git a/gcc/c-family/c-warn.cc b/gcc/c-family/c-warn.cc
index d2938b91043..2a399ba6d14 100644
--- a/gcc/c-family/c-warn.cc
+++ b/gcc/c-family/c-warn.cc
@@ -2991,10 +2991,9 @@ check_alignment_of_packed_member (tree type, tree field, 
bool rvalue)
return NULL_TREE;
  }

-/* Return struct or union type if the right hand value, RHS:
-   1. Is a pointer value which isn't aligned to a pointer type TYPE.
-   2. Is an address which takes the unaligned address of packed member
-  of struct or union when assigning to TYPE.
+/* Return struct or union type if the right hand value, RHS
+   is an address which takes the unaligned address of packed member
+   of struct or union when assigning to TYPE.
 Otherwise, return NULL_TREE.  */

  static tree
@@ -3021,57 +3020,6 @@ check_address_or_pointer_of_packed_member (tree type, 
tree rhs)

type = TREE_TYPE (type);

-  if (TREE_CODE (rhs) == PARM_DECL
-  || VAR_P (rhs)
-  || TREE_CODE (rhs) == CALL_EXPR)
-{
-  tree rhstype = TREE_TYPE (rhs);
-  if (TREE_CODE (rhs) == CALL_EXPR)
-   {
- rhs = CALL_EXPR_FN (rhs); /* Pointer expression.  */
- if (rhs == NULL_TREE)
-   return NULL_TREE;
- rhs = TREE_TYPE (rhs);/* Pointer type.  */
- /* We could be called while processing a template and RHS could be
-a functor.  In that case it's a class, not a pointer.  */
- if (!rhs || !POINTER_TYPE_P (rhs))
-   return NULL_TREE;
- rhs = TREE_TYPE (rhs);/* Function type.  */
- rhstype = TREE_TYPE (rhs);
- if (!rhstype || !POINTER_TYPE_P (rhstype))
-   return NULL_TREE;
- rvalue = true;
-   }
-  if (rvalue && POINTER_TYPE_P (rhstype))
-   rhstype = TREE_TYPE (rhstype);
-  while (TREE_CODE (rhstype) == ARRAY_TYPE)
-   rhstype = TREE_TYPE (rhstype);
-  if (TYPE_PACKED (rhstype))
-   {
- unsigned int type_align = min_align_of_type (type);
- unsigned int rhs_align = min_align_of_type (rhstype);
- if (rhs_align < type_align)
-   {
- auto_diagnostic_group d;
- location_t location = EXPR_LOC_OR_LOC (rhs, input_location);
- if (warning_at (location, OPT_Waddress_of_packed_member,
-   

Re: [PATCH] testsuite: Skip intrinsics test if arm

2023-01-15 Thread Torbjorn SVENSSON via Gcc-patches



On 2023-01-12 16:03, Richard Earnshaw wrote:



On 19/09/2022 17:16, Torbjörn SVENSSON via Gcc-patches wrote:

In the test case, it's clearly written that intrinsics is not
implemented on arm*. A simple xfail does not help since there are
link error and that would cause an UNRESOLVED testcase rather than
XFAIL.
By chaning to dg-skip-if, the entire test case is omitted.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/advsimd-intrinsics/vld1x2.c: Replace
dg-xfail-if with gd-skip-if.


Sorry for the delay reviewing this, I missed it at the time.

My problem with your suggested solution is that if these intrinsics are 
ever added this test will not automatically pick this up as it will have 
been disabled.  I presume from the comment (and the body of the test 
that contains an #ifdef for aarch64) that this is expected to be a 
temporary issue rather than something permanent.


So IMO I think it is correct to leave this as unresolved because the 
test cannot be built due to an issue with the compiler.


This patch has already been merged after Kyrill reviewed it back in 
September.


Without this change, the log would be filled with warnings about missing 
types. Maybe we could add some check that will enable the test only if 
the types are known?

Would that mitigate your concern?

Attached is the log from vld1x2.c on Cortex-A7 with -mfloat-abi=hard 
-mfpu=neon.


When I look at the result of a run, I only look at the test cases that 
are either FAIL (obviously), XPASS and UNRESOLVED. All other test cases 
are in a "good" state from what I can tell. If there are a lot of test 
cases in the UNRESOLVED state, that are not yet implemented year after 
year, it makes it harder to identify those test cases that are of 
interest. Right or wrong, that's why I suggested to remove it for the 
list of test cases that should be working.


Let me know what you think.

Kind regards,
Torbjörn



R.



Co-Authored-By: Yvan ROUX  
Signed-off-by: Torbjörn SVENSSON  
---
  gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vld1x2.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vld1x2.c 
b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vld1x2.c

index 92a139bc523..f933102be47 100644
--- a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vld1x2.c
+++ b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vld1x2.c
@@ -1,6 +1,6 @@
  /* We haven't implemented these intrinsics for arm yet.  */
-/* { dg-xfail-if "" { arm*-*-* } } */
  /* { dg-do run } */
+/* { dg-skip-if "unsupported" { arm*-*-* } } */
  /* { dg-options "-O3" } */
  #include Testing advsimd-intrinsics/vld1x2.c,   -O1
doing compile
Executing on host: /build/bin/arm-none-eabi-gcc  
/src/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vld1x2.c  -mthumb 
-march=armv7ve -mcpu=cortex-a7 -mfloat-abi=hard -mfpu=neon   -dumpbase "" 
-fdiagnostics-plain-output-O1  -O3   -Wl,gcc_tg.o -lm -T 
/qemu/qemu-cortex-a7.ld -o ./vld1x2.exe(timeout = 800)
spawn -ignore SIGHUP /build/bin/arm-none-eabi-gcc 
/src/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vld1x2.c -mthumb 
-march=armv7ve -mcpu=cortex-a7 -mfloat-abi=hard -mfpu=neon -dumpbase  
-fdiagnostics-plain-output -O1 -O3 -Wl,gcc_tg.o -lm -T /qemu/qemu-cortex-a7.ld 
-o ./vld1x2.exe
pid is 22433 -22433
/src/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vld1x2.c: In function 
'test_vld_u8_x2':
/src/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vld1x2.c:21:13: 
warning: implicit declaration of function 'vld1_u8_x2'; did you mean 
'vld1_u32'? [-Wimplicit-function-declaration]
/src/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vld1x2.c:32:1: note: 
in expansion of macro 'TESTMETH'
/src/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vld1x2.c:62:27: note: 
in expansion of macro 'VARIANTS_1'
/src/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vld1x2.c:66:1: note: 
in expansion of macro 'VARIANTS'
/src/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vld1x2.c:21:13: error: 
incompatible types when assigning to type 'uint8x8x2_t' from type 'int'
/src/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vld1x2.c:32:1: note: 
in expansion of macro 'TESTMETH'
/src/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vld1x2.c:62:27: note: 
in expansion of macro 'VARIANTS_1'
/src/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vld1x2.c:66:1: note: 
in expansion of macro 'VARIANTS'
/src/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vld1x2.c: In function 
'test_vld_u16_x2':
/src/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vld1x2.c:21:13: 
warning: implicit declaration of function 'vld1_u16_x2'; did you mean 
'vld1_u16'? [-Wimplicit-function-declaration]
/src/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vld1x2.c:33:1: note: 
in expansion of macro 'TESTMETH'
/src/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vld1x2.c:62:27: note: 
in expansion of macro 'VARIANTS_1'

Re: PING [PATCH v3] c++: Allow module name to be a single letter on Windows

2022-11-28 Thread Torbjorn SVENSSON via Gcc-patches




On 2022-11-28 12:21, Nathan Sidwell wrote:

On 11/25/22 14:03, Torbjorn SVENSSON wrote:

Hi,

Ping, https://gcc.gnu.org/pipermail/gcc-patches/2022-November/606528.html


ok, thanks!


Pushed.





Kind regards,
Torbjörn

On 2022-11-17 14:20, Torbjörn SVENSSON wrote:

v1 -> v2:
Paths without "C:" part can still be absolute if they start with / or
\ on Windows.

v2 -> v3:
Use alternative approach by having platform specific code in module.cc.

Truth table for the new expression:
c:\foo -> true
c:/foo -> true
/foo   -> true
\foo   -> true
c:foo  -> false
foo    -> false
./foo  -> true
.\foo  -> true


Ok for trunk?

---

On Windows, the ':' character is special and when the module name is
a single character, like 'A', then the flatname would be (for
example) 'A:Foo'. On Windows, 'A:Foo' is treated as an absolute
path by the module loader and is likely not found.

Without this patch, the test case pr98944_c.C fails with:

In module imported at /src/gcc/testsuite/g++.dg/modules/pr98944_b.C:7:1,
of module A:Foo, imported at 
/src/gcc/testsuite/g++.dg/modules/pr98944_c.C:7:

A:Internals: error: header module expected, module 'A:Internals' found
A:Internals: error: failed to read compiled module: Bad file data
A:Internals: note: compiled module file is 'gcm.cache/A-Internals.gcm'
In module imported at /src/gcc/testsuite/g++.dg/modules/pr98944_c.C:7:8:
A:Foo: error: failed to read compiled module: Bad import dependency
A:Foo: note: compiled module file is 'gcm.cache/A-Foo.gcm'
A:Foo: fatal error: returning to the gate for a mechanical issue
compilation terminated.

gcc/cp/ChangeLog:

* module.cc: On Windows, 'A:Foo' is supposed to be a module
and not a path.

Tested on Windows with arm-none-eabi for Cortex-M3 in gcc-11 tree.

Co-Authored-By: Yvan ROUX 
Signed-off-by: Torbjörn SVENSSON 
---
  gcc/cp/module.cc | 10 +-
  1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 0e9af318ba4..fa41a86213f 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -13960,7 +13960,15 @@ get_module (tree name, module_state *parent, 
bool partition)

  static module_state *
  get_module (const char *ptr)
  {
-  if (ptr[0] == '.' ? IS_DIR_SEPARATOR (ptr[1]) : IS_ABSOLUTE_PATH 
(ptr))
+  /* On DOS based file systems, there is an ambiguity with A:B which 
can be
+ interpreted as a module Module:Partition or Drive:PATH.  
Interpret strings
+ which clearly starts as pathnames as header-names and 
everything else is

+ treated as a (possibly malformed) named moduled.  */
+  if (IS_DIR_SEPARATOR (ptr[ptr[0] == '.']) // ./FOO or /FOO
+#if HAVE_DOS_BASED_FILE_SYSTEM
+  || (HAS_DRIVE_SPEC (ptr) && IS_DIR_SEPARATOR (ptr[2])) // A:/FOO
+#endif
+  || false)
  /* A header name.  */
  return get_module (build_string (strlen (ptr), ptr));




PING [PATCH v3] c++: Allow module name to be a single letter on Windows

2022-11-25 Thread Torbjorn SVENSSON via Gcc-patches

Hi,

Ping, https://gcc.gnu.org/pipermail/gcc-patches/2022-November/606528.html

Kind regards,
Torbjörn

On 2022-11-17 14:20, Torbjörn SVENSSON wrote:

v1 -> v2:
Paths without "C:" part can still be absolute if they start with / or
\ on Windows.

v2 -> v3:
Use alternative approach by having platform specific code in module.cc.

Truth table for the new expression:
c:\foo -> true
c:/foo -> true
/foo   -> true
\foo   -> true
c:foo  -> false
foo-> false
./foo  -> true
.\foo  -> true


Ok for trunk?

---

On Windows, the ':' character is special and when the module name is
a single character, like 'A', then the flatname would be (for
example) 'A:Foo'. On Windows, 'A:Foo' is treated as an absolute
path by the module loader and is likely not found.

Without this patch, the test case pr98944_c.C fails with:

In module imported at /src/gcc/testsuite/g++.dg/modules/pr98944_b.C:7:1,
of module A:Foo, imported at /src/gcc/testsuite/g++.dg/modules/pr98944_c.C:7:
A:Internals: error: header module expected, module 'A:Internals' found
A:Internals: error: failed to read compiled module: Bad file data
A:Internals: note: compiled module file is 'gcm.cache/A-Internals.gcm'
In module imported at /src/gcc/testsuite/g++.dg/modules/pr98944_c.C:7:8:
A:Foo: error: failed to read compiled module: Bad import dependency
A:Foo: note: compiled module file is 'gcm.cache/A-Foo.gcm'
A:Foo: fatal error: returning to the gate for a mechanical issue
compilation terminated.

gcc/cp/ChangeLog:

* module.cc: On Windows, 'A:Foo' is supposed to be a module
and not a path.

Tested on Windows with arm-none-eabi for Cortex-M3 in gcc-11 tree.

Co-Authored-By: Yvan ROUX 
Signed-off-by: Torbjörn SVENSSON 
---
  gcc/cp/module.cc | 10 +-
  1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 0e9af318ba4..fa41a86213f 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -13960,7 +13960,15 @@ get_module (tree name, module_state *parent, bool 
partition)
  static module_state *
  get_module (const char *ptr)
  {
-  if (ptr[0] == '.' ? IS_DIR_SEPARATOR (ptr[1]) : IS_ABSOLUTE_PATH (ptr))
+  /* On DOS based file systems, there is an ambiguity with A:B which can be
+ interpreted as a module Module:Partition or Drive:PATH.  Interpret strings
+ which clearly starts as pathnames as header-names and everything else is
+ treated as a (possibly malformed) named moduled.  */
+  if (IS_DIR_SEPARATOR (ptr[ptr[0] == '.']) // ./FOO or /FOO
+#if HAVE_DOS_BASED_FILE_SYSTEM
+  || (HAS_DRIVE_SPEC (ptr) && IS_DIR_SEPARATOR (ptr[2])) // A:/FOO
+#endif
+  || false)
  /* A header name.  */
  return get_module (build_string (strlen (ptr), ptr));
  


Re: PING^2 [PATCH] testsuite: Windows paths use \ and not /

2022-11-21 Thread Torbjorn SVENSSON via Gcc-patches

Pushed after off-list approval from Jeff Law.

On 2022-11-17 17:44, Torbjorn SVENSSON via Gcc-patches wrote:

Hi,

Ping, https://gcc.gnu.org/pipermail/gcc-patches/2022-November/604896.html

Ok for trunk?

Kind regards,
Torbjörn

On 2022-11-02 19:16, Torbjorn SVENSSON wrote:

Hi,

Ping, https://gcc.gnu.org/pipermail/gcc-patches/2022-October/604312.html

Ok for trunk?

Kind regards,
Torbjörn

On 2022-10-25 17:15, Torbjörn SVENSSON wrote:

Without this patch, the following error is reported on Windows:

In file included from 
t:\build\arm-none-eabi\include\c++\11.3.1\string:54,
   from 
t:\build\arm-none-eabi\include\c++\11.3.1\bits\locale_classes.h:40,
   from 
t:\build\arm-none-eabi\include\c++\11.3.1\bits\ios_base.h:41,
   from 
t:\build\arm-none-eabi\include\c++\11.3.1\ios:42,
   from 
t:\build\arm-none-eabi\include\c++\11.3.1\ostream:38,
   from 
t:\build\arm-none-eabi\include\c++\11.3.1\iostream:39:
t:\build\arm-none-eabi\include\c++\11.3.1\bits\range_access.h:36:10: 
note: include 
't:\build\arm-none-eabi\include\c++\11.3.1\initializer_list' 
translated to import
arm-none-eabi-g++.exe: warning: 
.../gcc/testsuite/g++.dg/modules/pr99023_b.X: linker input file 
unused because linking not done
FAIL: g++.dg/modules/pr99023_b.X -std=c++2a  dg-regexp 6 not found: 
"[^\n]*: note: include '[^\n]*/initializer_list' translated to import\n"


gcc/testsuite/ChangeLog:

* g++.dg/modules/pr99023_b.X: Match Windows paths too.

Co-Authored-By: Yvan ROUX 
Signed-off-by: Torbjörn SVENSSON 
---
  gcc/testsuite/g++.dg/modules/pr99023_b.X | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/g++.dg/modules/pr99023_b.X 
b/gcc/testsuite/g++.dg/modules/pr99023_b.X

index 3d82f34868b..ca5f32e5bcc 100644
--- a/gcc/testsuite/g++.dg/modules/pr99023_b.X
+++ b/gcc/testsuite/g++.dg/modules/pr99023_b.X
@@ -3,5 +3,5 @@
  // { dg-prune-output {linker input file unused} }
-// { dg-regexp {[^\n]*: note: include '[^\n]*/initializer_list' 
translated to import\n} }
+// { dg-regexp {[^\n]*: note: include '[^\n]*[/\\]initializer_list' 
translated to import\n} }

  NO DO NOT COMPILE


Re: PING^1 [PATCH] cpp/remap: Only override if string matched

2022-11-21 Thread Torbjorn SVENSSON via Gcc-patches

Hi,

On 2022-11-20 21:31, Jeff Law wrote:


On 11/2/22 12:21, Torbjorn SVENSSON via Gcc-patches wrote:

Hi,

Ping, https://gcc.gnu.org/pipermail/gcc-patches/2022-October/604062.html

Ok for trunk?


OK.  Sorry for the delay.


Thanks for the review.
Pushed.

Kind regards,
Torbjörn



jeff




Re: PING^5 [PATCH] testsuite: Verify that module-mapper is available

2022-11-18 Thread Torbjorn SVENSSON via Gcc-patches




On 2022-11-18 09:14, Richard Biener wrote:

On Thu, Nov 17, 2022 at 6:09 PM Torbjorn SVENSSON via Gcc-patches
 wrote:


Hi,

Ping, https://gcc.gnu.org/pipermail/gcc-patches/2022-November/604895.html

Ok for trunk?


OK.


Pushed.




Kind regards,
Torbjörn

On 2022-11-02 19:13, Torbjorn SVENSSON wrote:

Hi,

Ping, https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602844.html

Ok for trunk?

Kind regards,
Torbjörn

On 2022-10-25 16:24, Torbjorn SVENSSON via Gcc-patches wrote:

Hi,

Ping, https://gcc.gnu.org/pipermail/gcc-patches/2022-October/603544.html

Kind regards,
Torbjörn

On 2022-10-14 09:42, Torbjorn SVENSSON wrote:

Hi,

Ping, https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602843.html

Kind regards,
Torbjörn

On 2022-10-05 11:17, Torbjorn SVENSSON wrote:

Hi,

Ping,
https://gcc.gnu.org/pipermail/gcc-patches/2022-September/602111.html

Kind regards,
Torbjörn

On 2022-09-23 14:03, Torbjörn SVENSSON wrote:

For some test cases, it's required that the optional module mapper
"g++-mapper-server" is built. As the server is not required, the
test cases will fail if it can't be found.

gcc/testsuite/ChangeLog:

 * lib/target-supports.exp (check_is_prog_name_available):
 New.
 * lib/target-supports-dg.exp
 (dg-require-prog-name-available): New.
 * g++.dg/modules/modules.exp: Verify avilability of module
 mapper.

Signed-off-by: Torbjörn SVENSSON  
---
   gcc/testsuite/g++.dg/modules/modules.exp | 31

   gcc/testsuite/lib/target-supports-dg.exp | 15 
   gcc/testsuite/lib/target-supports.exp| 15 
   3 files changed, 61 insertions(+)

diff --git a/gcc/testsuite/g++.dg/modules/modules.exp
b/gcc/testsuite/g++.dg/modules/modules.exp
index afb323d0efd..4784803742a 100644
--- a/gcc/testsuite/g++.dg/modules/modules.exp
+++ b/gcc/testsuite/g++.dg/modules/modules.exp
@@ -279,6 +279,29 @@ proc module-init { src } {
   return $option_list
   }
+# Return 1 if requirements are met
+proc module-check-requirements { tests } {
+foreach test $tests {
+set tmp [dg-get-options $test]
+foreach op $tmp {
+switch [lindex $op 0] {
+"dg-additional-options" {
+# Example strings to match:
+# -fmodules-ts -fmodule-mapper=|@g++-mapper-server\\
-t\\ [srcdir]/inc-xlate-1.map
+# -fmodules-ts -fmodule-mapper=|@g++-mapper-server
+if [regexp -- {(^| )-fmodule-mapper=\|@([^\\ ]*)}
[lindex $op 2] dummy dummy2 prog] {
+verbose "Checking that mapper exist: $prog"
+if { ![ check_is_prog_name_available $prog ] } {
+return 0
+}
+}
+}
+}
+}
+}
+return 1
+}
+
   # cleanup any detritus from previous run
   cleanup_module_files [find $DEFAULT_REPO *.gcm]
@@ -307,6 +330,14 @@ foreach src [lsort [find $srcdir/$subdir
{*_a.[CHX}]] {
   set tests [lsort [find [file dirname $src] \
 [regsub {_a.[CHX]$} [file tail $src]
{_[a-z].[CHX]}]]]
+if { ![module-check-requirements $tests] } {
+set testcase [regsub {_a.[CH]} $src {}]
+set testcase \
+[string range $testcase [string length "$srcdir/"] end]
+unsupported $testcase
+continue
+}
+
   set std_list [module-init $src]
   foreach std $std_list {
   set mod_files {}
diff --git a/gcc/testsuite/lib/target-supports-dg.exp
b/gcc/testsuite/lib/target-supports-dg.exp
index aa2164bc789..6ce3b2b1a1b 100644
--- a/gcc/testsuite/lib/target-supports-dg.exp
+++ b/gcc/testsuite/lib/target-supports-dg.exp
@@ -683,3 +683,18 @@ proc dg-require-symver { args } {
   set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
   }
   }
+
+# If this target does not provide prog named "$args", skip this test.
+
+proc dg-require-prog-name-available { args } {
+# The args are within another list; pull them out.
+set args [lindex $args 0]
+
+set prog [lindex $args 1]
+
+if { ![ check_is_prog_name_available $prog ] } {
+upvar dg-do-what dg-do-what
+set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
+}
+}
+
diff --git a/gcc/testsuite/lib/target-supports.exp
b/gcc/testsuite/lib/target-supports.exp
index 703aba412a6..c3b7a6c17b3 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -11928,3 +11928,18 @@ main:
   .byte 0
 } ""]
   }
+
+# Return 1 if this target has prog named "$prog", 0 otherwise.
+
+proc check_is_prog_name_available { prog } {
+global tool
+
+set options [list "additional_flags=-print-prog-name=$prog"]
+set output [lindex [${tool}_target_compile "" "" "none"
$options] 0]
+
+if { $output == $prog } {
+return 0
+}
+
+return 1
+}


PING^5 [PATCH] testsuite: Verify that module-mapper is available

2022-11-17 Thread Torbjorn SVENSSON via Gcc-patches

Hi,

Ping, https://gcc.gnu.org/pipermail/gcc-patches/2022-November/604895.html

Ok for trunk?

Kind regards,
Torbjörn

On 2022-11-02 19:13, Torbjorn SVENSSON wrote:

Hi,

Ping, https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602844.html

Ok for trunk?

Kind regards,
Torbjörn

On 2022-10-25 16:24, Torbjorn SVENSSON via Gcc-patches wrote:

Hi,

Ping, https://gcc.gnu.org/pipermail/gcc-patches/2022-October/603544.html

Kind regards,
Torbjörn

On 2022-10-14 09:42, Torbjorn SVENSSON wrote:

Hi,

Ping, https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602843.html

Kind regards,
Torbjörn

On 2022-10-05 11:17, Torbjorn SVENSSON wrote:

Hi,

Ping, 
https://gcc.gnu.org/pipermail/gcc-patches/2022-September/602111.html


Kind regards,
Torbjörn

On 2022-09-23 14:03, Torbjörn SVENSSON wrote:

For some test cases, it's required that the optional module mapper
"g++-mapper-server" is built. As the server is not required, the
test cases will fail if it can't be found.

gcc/testsuite/ChangeLog:

* lib/target-supports.exp (check_is_prog_name_available):
New.
* lib/target-supports-dg.exp
(dg-require-prog-name-available): New.
* g++.dg/modules/modules.exp: Verify avilability of module
mapper.

Signed-off-by: Torbjörn SVENSSON  
---
  gcc/testsuite/g++.dg/modules/modules.exp | 31 


  gcc/testsuite/lib/target-supports-dg.exp | 15 
  gcc/testsuite/lib/target-supports.exp    | 15 
  3 files changed, 61 insertions(+)

diff --git a/gcc/testsuite/g++.dg/modules/modules.exp 
b/gcc/testsuite/g++.dg/modules/modules.exp

index afb323d0efd..4784803742a 100644
--- a/gcc/testsuite/g++.dg/modules/modules.exp
+++ b/gcc/testsuite/g++.dg/modules/modules.exp
@@ -279,6 +279,29 @@ proc module-init { src } {
  return $option_list
  }
+# Return 1 if requirements are met
+proc module-check-requirements { tests } {
+    foreach test $tests {
+    set tmp [dg-get-options $test]
+    foreach op $tmp {
+    switch [lindex $op 0] {
+    "dg-additional-options" {
+    # Example strings to match:
+    # -fmodules-ts -fmodule-mapper=|@g++-mapper-server\\ 
-t\\ [srcdir]/inc-xlate-1.map

+    # -fmodules-ts -fmodule-mapper=|@g++-mapper-server
+    if [regexp -- {(^| )-fmodule-mapper=\|@([^\\ ]*)} 
[lindex $op 2] dummy dummy2 prog] {

+    verbose "Checking that mapper exist: $prog"
+    if { ![ check_is_prog_name_available $prog ] } {
+    return 0
+    }
+    }
+    }
+    }
+    }
+    }
+    return 1
+}
+
  # cleanup any detritus from previous run
  cleanup_module_files [find $DEFAULT_REPO *.gcm]
@@ -307,6 +330,14 @@ foreach src [lsort [find $srcdir/$subdir 
{*_a.[CHX}]] {

  set tests [lsort [find [file dirname $src] \
    [regsub {_a.[CHX]$} [file tail $src] 
{_[a-z].[CHX]}]]]

+    if { ![module-check-requirements $tests] } {
+    set testcase [regsub {_a.[CH]} $src {}]
+    set testcase \
+    [string range $testcase [string length "$srcdir/"] end]
+    unsupported $testcase
+    continue
+    }
+
  set std_list [module-init $src]
  foreach std $std_list {
  set mod_files {}
diff --git a/gcc/testsuite/lib/target-supports-dg.exp 
b/gcc/testsuite/lib/target-supports-dg.exp

index aa2164bc789..6ce3b2b1a1b 100644
--- a/gcc/testsuite/lib/target-supports-dg.exp
+++ b/gcc/testsuite/lib/target-supports-dg.exp
@@ -683,3 +683,18 @@ proc dg-require-symver { args } {
  set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
  }
  }
+
+# If this target does not provide prog named "$args", skip this test.
+
+proc dg-require-prog-name-available { args } {
+    # The args are within another list; pull them out.
+    set args [lindex $args 0]
+
+    set prog [lindex $args 1]
+
+    if { ![ check_is_prog_name_available $prog ] } {
+    upvar dg-do-what dg-do-what
+    set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
+    }
+}
+
diff --git a/gcc/testsuite/lib/target-supports.exp 
b/gcc/testsuite/lib/target-supports.exp

index 703aba412a6..c3b7a6c17b3 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -11928,3 +11928,18 @@ main:
  .byte 0
    } ""]
  }
+
+# Return 1 if this target has prog named "$prog", 0 otherwise.
+
+proc check_is_prog_name_available { prog } {
+    global tool
+
+    set options [list "additional_flags=-print-prog-name=$prog"]
+    set output [lindex [${tool}_target_compile "" "" "none" 
$options] 0]

+
+    if { $output == $prog } {
+    return 0
+    }
+
+    return 1
+}


PING^2 [PATCH] cpp/remap: Only override if string matched

2022-11-17 Thread Torbjorn SVENSSON via Gcc-patches

Hi,

Ping, https://gcc.gnu.org/pipermail/gcc-patches/2022-November/604898.html

Ok for trunk?

Kind regards,
Torbjörn

On 2022-11-02 19:21, Torbjorn SVENSSON wrote:

Hi,

Ping, https://gcc.gnu.org/pipermail/gcc-patches/2022-October/604062.html

Ok for trunk?

Kind regards,
Torbjörn

On 2022-10-20 22:48, Torbjörn SVENSSON wrote:

For systems with HAVE_DOS_BASED_FILE_SYSTEM set, only override the
pointer if the backslash pattern matches.

Output without this patch:
.../gcc/testsuite/gcc.dg/cpp/pr71681-2.c:5:10: fatal error: a/t2.h: No 
such file or directory


With patch applied, no output and the test case succeeds.

libcpp/ChangeLog

* files.cc: Ensure pattern matches before use.

Signed-off-by: Torbjörn SVENSSON 
---
  libcpp/files.cc | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcpp/files.cc b/libcpp/files.cc
index 24208f7b0f8..a18b1caf48d 100644
--- a/libcpp/files.cc
+++ b/libcpp/files.cc
@@ -1833,7 +1833,7 @@ remap_filename (cpp_reader *pfile, _cpp_file *file)
  #ifdef HAVE_DOS_BASED_FILE_SYSTEM
    {
  const char *p2 = strchr (fname, '\\');
-    if (!p || (p > p2))
+    if (!p || (p2 && p > p2))
    p = p2;
    }
  #endif


PING^2 [PATCH] testsuite: Windows paths use \ and not /

2022-11-17 Thread Torbjorn SVENSSON via Gcc-patches

Hi,

Ping, https://gcc.gnu.org/pipermail/gcc-patches/2022-November/604896.html

Ok for trunk?

Kind regards,
Torbjörn

On 2022-11-02 19:16, Torbjorn SVENSSON wrote:

Hi,

Ping, https://gcc.gnu.org/pipermail/gcc-patches/2022-October/604312.html

Ok for trunk?

Kind regards,
Torbjörn

On 2022-10-25 17:15, Torbjörn SVENSSON wrote:

Without this patch, the following error is reported on Windows:

In file included from 
t:\build\arm-none-eabi\include\c++\11.3.1\string:54,
   from 
t:\build\arm-none-eabi\include\c++\11.3.1\bits\locale_classes.h:40,
   from 
t:\build\arm-none-eabi\include\c++\11.3.1\bits\ios_base.h:41,

   from t:\build\arm-none-eabi\include\c++\11.3.1\ios:42,
   from 
t:\build\arm-none-eabi\include\c++\11.3.1\ostream:38,
   from 
t:\build\arm-none-eabi\include\c++\11.3.1\iostream:39:
t:\build\arm-none-eabi\include\c++\11.3.1\bits\range_access.h:36:10: 
note: include 
't:\build\arm-none-eabi\include\c++\11.3.1\initializer_list' 
translated to import
arm-none-eabi-g++.exe: warning: 
.../gcc/testsuite/g++.dg/modules/pr99023_b.X: linker input file unused 
because linking not done
FAIL: g++.dg/modules/pr99023_b.X -std=c++2a  dg-regexp 6 not found: 
"[^\n]*: note: include '[^\n]*/initializer_list' translated to import\n"


gcc/testsuite/ChangeLog:

* g++.dg/modules/pr99023_b.X: Match Windows paths too.

Co-Authored-By: Yvan ROUX 
Signed-off-by: Torbjörn SVENSSON 
---
  gcc/testsuite/g++.dg/modules/pr99023_b.X | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/g++.dg/modules/pr99023_b.X 
b/gcc/testsuite/g++.dg/modules/pr99023_b.X

index 3d82f34868b..ca5f32e5bcc 100644
--- a/gcc/testsuite/g++.dg/modules/pr99023_b.X
+++ b/gcc/testsuite/g++.dg/modules/pr99023_b.X
@@ -3,5 +3,5 @@
  // { dg-prune-output {linker input file unused} }
-// { dg-regexp {[^\n]*: note: include '[^\n]*/initializer_list' 
translated to import\n} }
+// { dg-regexp {[^\n]*: note: include '[^\n]*[/\\]initializer_list' 
translated to import\n} }

  NO DO NOT COMPILE


Re: [PATCH] testsuite: Fix mistransformed gcov

2022-11-15 Thread Torbjorn SVENSSON via Gcc-patches

Hi,

On 2022-11-16 03:11, Hans-Peter Nilsson wrote:

How was r13-2619-g34b9a03353d3fd "gcov: Respect triplet when looking
for gcov" tested?  I'm having a hard time believing it was tested with
a *cross-compiler* *in-build-tree*.  I think it was only tested for
the special-case of an installed cross-compiler; not even with a
native build exercising the false branch (see patch), considering that
a breaking typo ("}" vs "]") snuck by in the first revision, before
commit.


I was testing this in out-of-tree test with a cross-compiler (built for 
arm-none-eabi) running on Windows and Linux and just noticed the failure 
and (wrongly) assumed that all of the cases needed the transformation 
call as that's how other tools were handled.
The test systems used is are hosts that does not have any internet 
connection, so that's why I got a typo in the first patch when moving 
the fix to a system that did have an internet connection.

Sorry for the mess I caused!

Regarding the patch you propose; it looks good to me, but I'm not able 
to approve it.


Kind regards,
Torbjörn


I guess reviewers forgot to ask that, but it's really on the
submitter; it's a general requirement for patches to say how it was
tested.  Usually no more is needed than "tested with a cross-compiler
for ..., no regressions" (implying running twice and comparing results
before and after the patch).

In this case, when adjusting test-framework bits, a little more care
and mentioned details about how it was tested, would have been in
order.  It's likely it'd have shown that an uninstalled in-tree cross
(an IMHO more expected case) wasn't tested, which that patch broke for
the one gcov invocation that the testsuite does for cross-builds
(IIUC).

It can be said like this: I tested *this* patch as follows (all
directory names below manually redacted), showing no regressions and
fixing the regression for the in-tree cross build;

For a native build (x86_64, Debian 11):
- In the gcc build directory:
  make check RUNTESTFLAGS=gcov.exp

- In an empty new directory after native installation in /pre.
/gccsrc/top/contrib/test_installed --prefix=/pre gcov.exp

- Also, for good measure (mentioned somewhere in the installation
documentation) native:
for tool in gcc g++ ; do env PATH=/pre/bin:$PATH runtest \
  --tool $tool --srcdir=/gccsrc/top/gcc/testsuite gcov.exp; done

For a cris-elf cross:
- In the gcc build directory:
make check 'RUNTESTFLAGS=--target_board=cris-sim gcov.exp'

- In an empty new directory after installation in /pre.
/gccsrc/top/contrib/test_installed --with-gcc=/pre/bin/cris-elf-gcc \
  --with-g++=/pre/bin/cris-elf-g++ --with-gfortran=/pre/bin/cris-elf-gfortran \
  --target=cris-elf --target_board=cris-sim gcov.exp

Ok to commit?

brgds, H-P
PS. Beware that the proc name may be up for bikeshedding.

 8<  8<  8<  8< 

In commit r13-2619-g34b9a03353d3fd, [transform] was applied to all
invocations of gcov, for both out-of-tree and in-tree testing.
For in-tree cross builds, this means gcov was called as
"/path/to/gccobj/gcc/target-tuple-gcov" gcov-pr94029.c which is
incorrect, as it's there "/path/to/gccobj/gcc/gcov" until it's
installed.  This caused a testsuite failure, like:

Running /x/gcc/gcc/testsuite/gcc.misc-tests/gcov.exp ...
FAIL: gcc.misc-tests/gcov-pr94029.c gcov failed: spawn failed

To avoid cumbersome conditionals, use a dedicated new helper function.

gcc/testsuite:
* lib/gcc-dg.exp (gcc-transform-out-of-tree): New proc.
* g++.dg/gcov/gcov.exp, gcc.misc-tests/gcov.exp: Call
gcc-transform-out-of-tree instead of transform.
---
  gcc/testsuite/g++.dg/gcov/gcov.exp|  4 ++--
  gcc/testsuite/gcc.misc-tests/gcov.exp |  4 ++--
  gcc/testsuite/lib/gcc-dg.exp  | 13 +
  3 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/g++.dg/gcov/gcov.exp 
b/gcc/testsuite/g++.dg/gcov/gcov.exp
index 04e7a0164865..c9f20958836b 100644
--- a/gcc/testsuite/g++.dg/gcov/gcov.exp
+++ b/gcc/testsuite/g++.dg/gcov/gcov.exp
@@ -24,9 +24,9 @@ global GXX_UNDER_TEST
  
  # Find gcov in the same directory as $GXX_UNDER_TEST.

  if { ![is_remote host] && [string match "*/*" [lindex $GXX_UNDER_TEST 0]] } {
-set GCOV [file dirname [lindex $GXX_UNDER_TEST 0]]/[transform gcov]
+set GCOV [file dirname [lindex $GXX_UNDER_TEST 
0]]/[gcc-transform-out-of-tree gcov]
  } else {
-set GCOV [transform gcov]
+set GCOV [gcc-transform-out-of-tree gcov]
  }
  
  # Initialize harness.

diff --git a/gcc/testsuite/gcc.misc-tests/gcov.exp 
b/gcc/testsuite/gcc.misc-tests/gcov.exp
index b8e9661aa537..90ceec46e0f0 100644
--- a/gcc/testsuite/gcc.misc-tests/gcov.exp
+++ b/gcc/testsuite/gcc.misc-tests/gcov.exp
@@ -24,9 +24,9 @@ global GCC_UNDER_TEST
  
  # For now find gcov in the same directory as $GCC_UNDER_TEST.

  if { ![is_remote host] && [string match "*/*" [lindex $GCC_UNDER_TEST 0]] } {
-set GCOV [file dirname [lindex $GCC_UNDER_TEST 0]]/[transform gcov]
+set 

Re: [PATCH] c++: Allow module name to be a single letter on Windows

2022-11-08 Thread Torbjorn SVENSSON via Gcc-patches

Hi Nathan,

On 2022-11-08 00:03, Nathan Sidwell wrote:

On 11/3/22 11:06, Torbjorn SVENSSON wrote:



On 2022-11-03 15:17, Nathan Sidwell wrote:

On 10/28/22 05:15, Torbjörn SVENSSON wrote:

On Windows, the ':' character is special and when the module name is
a single character, like 'A', then the flatname would be (for
example) 'A:Foo'. On Windows, 'A:Foo' is treated as an absolute
path by the module loader and is likely not found.

Without this patch, the test case pr98944_c.C fails with:

In module imported at 
/src/gcc/testsuite/g++.dg/modules/pr98944_b.C:7:1,
of module A:Foo, imported at 
/src/gcc/testsuite/g++.dg/modules/pr98944_c.C:7:

A:Internals: error: header module expected, module 'A:Internals' found
A:Internals: error: failed to read compiled module: Bad file data
A:Internals: note: compiled module file is 'gcm.cache/A-Internals.gcm'
In module imported at 
/src/gcc/testsuite/g++.dg/modules/pr98944_c.C:7:8:

A:Foo: error: failed to read compiled module: Bad import dependency
A:Foo: note: compiled module file is 'gcm.cache/A-Foo.gcm'
A:Foo: fatal error: returning to the gate for a mechanical issue
compilation terminated.

include/ChangeLog:

* filenames.h: Added IS_REAL_ABSOLUTE_PATH macro to check if
path is absolute and not semi-absolute on Windows.


Hm, this is unfortunate.  The current IS_ABSOLUTE_PATH, is really 
'not relative to cwd', and even then that's untrue if the drive 
letter there is the drive letter of cwd, right?


It's awkward to have a new macro for just this purpose and the new 
name isn't very indicative of the difference to the current 
IS_ABSOLUTE_PATH.


Would it be better to not deal with drive letters here?  How 
prevalent are they these days in windows?  Would something like


    if (IS_DIR_SEPARATOR (ptr[ptr[0] == '.'])

suffice?


I don't think you can ignore the drive letter part... see below.


#include 
#include "include/filenames.h"
#define TF(x) ((x) ? "true" : "false")
int main(int argc, char *argv[]) {
   const char *test[] = {
   /* absolute */  "c:\\foo", "c:/foo", "/foo", "\\foo",
   /* semi-absolute */ "c:foo",
   /* relative */  "foo", "./foo", ".\\foo",
   };
   for (int i = 0; i < sizeof(test) / sizeof(test[0]); i++) {
 const char *ptr = test[i];
 printf("\nptr: %s\n", ptr);
 printf("  IS_DOS_ABSOLUTE_PATH: %s\n",
    TF(IS_DOS_ABSOLUTE_PATH(ptr)));
 printf("  IS_DOS_REAL_ABSOLUTE_PATH: %s\n",
    TF(IS_DOS_REAL_ABSOLUTE_PATH(ptr)));
 printf("  IS_DIR_SEPARATOR: %s\n",
    TF(IS_DIR_SEPARATOR(ptr[ptr[0] == '.'])));
   }
   return 0;
}


The output is:

ptr: c:\foo
   IS_DOS_ABSOLUTE_PATH: true
   IS_DOS_REAL_ABSOLUTE_PATH: true
   IS_DIR_SEPARATOR: false

ptr: c:/foo
   IS_DOS_ABSOLUTE_PATH: true
   IS_DOS_REAL_ABSOLUTE_PATH: true
   IS_DIR_SEPARATOR: false

ptr: /foo
   IS_DOS_ABSOLUTE_PATH: true
   IS_DOS_REAL_ABSOLUTE_PATH: true
   IS_DIR_SEPARATOR: true

ptr: \foo
   IS_DOS_ABSOLUTE_PATH: true
   IS_DOS_REAL_ABSOLUTE_PATH: true
   IS_DIR_SEPARATOR: false

ptr: c:foo
   IS_DOS_ABSOLUTE_PATH: true
   IS_DOS_REAL_ABSOLUTE_PATH: false
   IS_DIR_SEPARATOR: false

ptr: foo
   IS_DOS_ABSOLUTE_PATH: false
   IS_DOS_REAL_ABSOLUTE_PATH: false
   IS_DIR_SEPARATOR: false

ptr: ./foo
   IS_DOS_ABSOLUTE_PATH: false
   IS_DOS_REAL_ABSOLUTE_PATH: false
   IS_DIR_SEPARATOR: true

ptr: .\foo
   IS_DOS_ABSOLUTE_PATH: false
   IS_DOS_REAL_ABSOLUTE_PATH: false
   IS_DIR_SEPARATOR: false




or, failing that perhaps put some explicit WINDOWS-specific #ifdef'd 
code there?  It's a real corner case.


Would you rather have something like this in module.cc?

if (ptr[0] == '.')
   {
 if IS_DIR_SEPARATOR (ptr[1]))
   return get_module (build_string (strlen (ptr), ptr));
   }
else
   {
#if HAVE_DOS_BASED_FILE_SYSTEM
 if (HAS_DRIVE_SPEC (ptr) && IS_DIR_SEPARATOR (ptr[2]))
#else
 if (IS_ABSOLUTE_PATH (ptr))
#endif
   return get_module (build_string (strlen (ptr), ptr));
   }


Yes, something like the above, but I think you're missing "/bob' in the 
DOS_BASED case?  shouldn't that also be a pathname?


if (IS_DIR_SEPARATOR (ptr[ptr[0] == '.']) // ./FOO or /FOO
#if HAVE_DOS_BASED_FILE_SYSTEM
     // DOS-FS IS_ABSOLUTE_PATH thinks 'A:B' is absolute, but we need to 
consider

     // that as a module:partition.
     || (HAS_DRIVE_SPEC (ptr) && IS_DIR_SEPARATOR (ptr[2])) // A:/FOO
#endif
     || false)
    return 

Does (something like) that work?


I tested it and your solution appears to work.
Are you okay with me pushing that solution or do you want me to send a 
v2 with it first?


Kind regards,
Torbjörn



nathan




Let me know what you prefer.

Kind regards,
Torbjörn



nathan



gcc/cp/ChangeLog:

* module.cc: Use IS_REAL_ABSOLUTE_PATH macro.

Co-Authored-By: Yvan ROUX 
Signed-off-by: Torbjörn SVENS

Re: PING^1 [PATCH] arm: Allow to override location of .gnu.sgstubs section

2022-11-04 Thread Torbjorn SVENSSON via Gcc-patches




On 2022-11-03 10:44, Kyrylo Tkachov wrote:




-Original Message-
From: Torbjorn SVENSSON 
Sent: Wednesday, November 2, 2022 6:19 PM
To: gcc-patches@gcc.gnu.org
Cc: Kyrylo Tkachov 
Subject: PING^1 [PATCH] arm: Allow to override location of .gnu.sgstubs
section

Hi,

Ping, https://gcc.gnu.org/pipermail/gcc-patches/2022-October/603878.html



Ok, thanks for pinging it.
Kyrill


Pushed.


Re: [PATCH v2] c++: Use in-process client when networking is disabled

2022-11-04 Thread Torbjorn SVENSSON via Gcc-patches




On 2022-11-03 15:09, Nathan Sidwell wrote:

On 11/3/22 09:48, Torbjorn SVENSSON wrote:

Hello Nathan,

On 2022-11-03 14:13, Nathan Sidwell wrote:

On 11/3/22 05:37, Torbjörn SVENSSON wrote:

v1 -> v2:
Updated expression in bad-mapper-3.C

Ok for trunk?

---

Without the patch, the output for bad-mapper-3.C would be:

/src/gcc/gcc/testsuite/g++.dg/modules/bad-mapper-3.C:2:1: error: 
unknown Compiled Module Interface: no such module


As this line is unexpected, the test case would fail.
The same problem can also be seen for g++.dg/modules/bad-mapper-2.C.

gcc/cp/ChangeLog:

* mapper-client.cc: Use in-process client when networking is
disabled.

gcc/testsuite/ChangeLog:

* g++.dg/modules/bad-mapper-3.C: Update dg-error pattern.

Tested on Windows with arm-none-eabi for Cortex-M3 in gcc-11 tree.

Co-Authored-By: Yvan ROUX 
Signed-off-by: Torbjörn SVENSSON 
---
  gcc/cp/mapper-client.cc | 4 
  gcc/testsuite/g++.dg/modules/bad-mapper-3.C | 2 +-
  2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/mapper-client.cc b/gcc/cp/mapper-client.cc
index fe9544b5ba4..4dcb3a03660 100644
--- a/gcc/cp/mapper-client.cc
+++ b/gcc/cp/mapper-client.cc
@@ -227,6 +227,8 @@ module_client::open_module_client (location_t 
loc, const char *o,

  int fd = -1;
  #if CODY_NETWORKING
  fd = Cody::OpenLocal (, name.c_str () + 1);
+#else
+    errmsg = "CODY_NETWORKING disabled";


CODY_NETWORKING is implementor speak. I think just "disabled" is 
sufficient here?


Ok for trunk if I change to just "disabled" here and in the other 
places below?


yes, thanks


Kind regards,
Torbjörn




  #endif
  if (fd >= 0)
    c = new module_client (fd, fd);
@@ -254,6 +256,8 @@ module_client::open_module_client (location_t 
loc, const char *o,

  int fd = -1;
  #if CODY_NETWORKING
  fd = Cody::OpenInet6 (, name.c_str (), port);
+#else
+    errmsg = "CODY_NETWORKING disabled";
  #endif
  name[colon] = ':';
diff --git a/gcc/testsuite/g++.dg/modules/bad-mapper-3.C 
b/gcc/testsuite/g++.dg/modules/bad-mapper-3.C

index 9dab332ccb2..c91bb4e260c 100644
--- a/gcc/testsuite/g++.dg/modules/bad-mapper-3.C
+++ b/gcc/testsuite/g++.dg/modules/bad-mapper-3.C
@@ -1,6 +1,6 @@
  //  { dg-additional-options "-fmodules-ts 
-fmodule-mapper=localhost:172477262" }

  import unique3.bob;
-// { dg-error {failed connecting mapper 'localhost:172477262'} "" { 
target *-*-* } 0 }
+// { dg-error {failed (connecting|CODY_NETWORKING disabled) mapper 
'localhost:172477262'} "" { target *-*-* } 0 }

  // { dg-prune-output "fatal error:" }
  // { dg-prune-output "failed to read" }
  // { dg-prune-output "compilation terminated" }






Pushed.


Re: [PATCH] c++: Allow module name to be a single letter on Windows

2022-11-03 Thread Torbjorn SVENSSON via Gcc-patches




On 2022-11-03 15:17, Nathan Sidwell wrote:

On 10/28/22 05:15, Torbjörn SVENSSON wrote:

On Windows, the ':' character is special and when the module name is
a single character, like 'A', then the flatname would be (for
example) 'A:Foo'. On Windows, 'A:Foo' is treated as an absolute
path by the module loader and is likely not found.

Without this patch, the test case pr98944_c.C fails with:

In module imported at /src/gcc/testsuite/g++.dg/modules/pr98944_b.C:7:1,
of module A:Foo, imported at 
/src/gcc/testsuite/g++.dg/modules/pr98944_c.C:7:

A:Internals: error: header module expected, module 'A:Internals' found
A:Internals: error: failed to read compiled module: Bad file data
A:Internals: note: compiled module file is 'gcm.cache/A-Internals.gcm'
In module imported at /src/gcc/testsuite/g++.dg/modules/pr98944_c.C:7:8:
A:Foo: error: failed to read compiled module: Bad import dependency
A:Foo: note: compiled module file is 'gcm.cache/A-Foo.gcm'
A:Foo: fatal error: returning to the gate for a mechanical issue
compilation terminated.

include/ChangeLog:

* filenames.h: Added IS_REAL_ABSOLUTE_PATH macro to check if
path is absolute and not semi-absolute on Windows.


Hm, this is unfortunate.  The current IS_ABSOLUTE_PATH, is really 'not 
relative to cwd', and even then that's untrue if the drive letter there 
is the drive letter of cwd, right?


It's awkward to have a new macro for just this purpose and the new name 
isn't very indicative of the difference to the current IS_ABSOLUTE_PATH.


Would it be better to not deal with drive letters here?  How prevalent 
are they these days in windows?  Would something like


    if (IS_DIR_SEPARATOR (ptr[ptr[0] == '.'])

suffice?


I don't think you can ignore the drive letter part... see below.


#include 
#include "include/filenames.h"
#define TF(x) ((x) ? "true" : "false")
int main(int argc, char *argv[]) {
  const char *test[] = {
  /* absolute */  "c:\\foo", "c:/foo", "/foo", "\\foo",
  /* semi-absolute */ "c:foo",
  /* relative */  "foo", "./foo", ".\\foo",
  };
  for (int i = 0; i < sizeof(test) / sizeof(test[0]); i++) {
const char *ptr = test[i];
printf("\nptr: %s\n", ptr);
printf("  IS_DOS_ABSOLUTE_PATH: %s\n",
   TF(IS_DOS_ABSOLUTE_PATH(ptr)));
printf("  IS_DOS_REAL_ABSOLUTE_PATH: %s\n",
   TF(IS_DOS_REAL_ABSOLUTE_PATH(ptr)));
printf("  IS_DIR_SEPARATOR: %s\n",
   TF(IS_DIR_SEPARATOR(ptr[ptr[0] == '.'])));
  }
  return 0;
}


The output is:

ptr: c:\foo
  IS_DOS_ABSOLUTE_PATH: true
  IS_DOS_REAL_ABSOLUTE_PATH: true
  IS_DIR_SEPARATOR: false

ptr: c:/foo
  IS_DOS_ABSOLUTE_PATH: true
  IS_DOS_REAL_ABSOLUTE_PATH: true
  IS_DIR_SEPARATOR: false

ptr: /foo
  IS_DOS_ABSOLUTE_PATH: true
  IS_DOS_REAL_ABSOLUTE_PATH: true
  IS_DIR_SEPARATOR: true

ptr: \foo
  IS_DOS_ABSOLUTE_PATH: true
  IS_DOS_REAL_ABSOLUTE_PATH: true
  IS_DIR_SEPARATOR: false

ptr: c:foo
  IS_DOS_ABSOLUTE_PATH: true
  IS_DOS_REAL_ABSOLUTE_PATH: false
  IS_DIR_SEPARATOR: false

ptr: foo
  IS_DOS_ABSOLUTE_PATH: false
  IS_DOS_REAL_ABSOLUTE_PATH: false
  IS_DIR_SEPARATOR: false

ptr: ./foo
  IS_DOS_ABSOLUTE_PATH: false
  IS_DOS_REAL_ABSOLUTE_PATH: false
  IS_DIR_SEPARATOR: true

ptr: .\foo
  IS_DOS_ABSOLUTE_PATH: false
  IS_DOS_REAL_ABSOLUTE_PATH: false
  IS_DIR_SEPARATOR: false




or, failing that perhaps put some explicit WINDOWS-specific #ifdef'd 
code there?  It's a real corner case.


Would you rather have something like this in module.cc?

if (ptr[0] == '.')
  {
if IS_DIR_SEPARATOR (ptr[1]))
  return get_module (build_string (strlen (ptr), ptr));
  }
else
  {
#if HAVE_DOS_BASED_FILE_SYSTEM
if (HAS_DRIVE_SPEC (ptr) && IS_DIR_SEPARATOR (ptr[2]))
#else
if (IS_ABSOLUTE_PATH (ptr))
#endif
  return get_module (build_string (strlen (ptr), ptr));
  }


Let me know what you prefer.

Kind regards,
Torbjörn



nathan



gcc/cp/ChangeLog:

* module.cc: Use IS_REAL_ABSOLUTE_PATH macro.

Co-Authored-By: Yvan ROUX 
Signed-off-by: Torbjörn SVENSSON 
---
  gcc/cp/module.cc    | 2 +-
  include/filenames.h | 4 
  2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 9957df510e6..84680e183b7 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -13958,7 +13958,7 @@ get_module (tree name, module_state *parent, 
bool partition)

  static module_state *
  get_module (const char *ptr)
  {
-  if (ptr[0] == '.' ? IS_DIR_SEPARATOR (ptr[1]) : IS_ABSOLUTE_PATH 
(ptr))
+  if (ptr[0] == '.' ? IS_DIR_SEPARATOR (ptr[1]) : 
IS_REAL_ABSOLUTE_PATH (ptr))

  /* A header name.  */
  return get_module (build_string (strlen (ptr), ptr));
diff --git a/include/filenames.h b/include/filenames.h
index 6c72c422edd..d04fccfed64 100644
--- a/include/filenames.h
+++ b/include/filenames.h
@@ -43,6 +43,7 @@ extern "C" {
  #  define HAS_DRIVE_SPEC(f) HAS_DOS_DRIVE_SPEC (f)
  #  define IS_DIR_SEPARATOR(c) IS_DOS_DIR_SEPARATOR (c)
  #  define IS_ABSOLUTE_PATH(f) IS_DOS_ABSOLUTE_PATH (f)

Re: [PATCH v2] c++: Use in-process client when networking is disabled

2022-11-03 Thread Torbjorn SVENSSON via Gcc-patches

Hello Nathan,

On 2022-11-03 14:13, Nathan Sidwell wrote:

On 11/3/22 05:37, Torbjörn SVENSSON wrote:

v1 -> v2:
Updated expression in bad-mapper-3.C

Ok for trunk?

---

Without the patch, the output for bad-mapper-3.C would be:

/src/gcc/gcc/testsuite/g++.dg/modules/bad-mapper-3.C:2:1: error: 
unknown Compiled Module Interface: no such module


As this line is unexpected, the test case would fail.
The same problem can also be seen for g++.dg/modules/bad-mapper-2.C.

gcc/cp/ChangeLog:

* mapper-client.cc: Use in-process client when networking is
disabled.

gcc/testsuite/ChangeLog:

* g++.dg/modules/bad-mapper-3.C: Update dg-error pattern.

Tested on Windows with arm-none-eabi for Cortex-M3 in gcc-11 tree.

Co-Authored-By: Yvan ROUX 
Signed-off-by: Torbjörn SVENSSON 
---
  gcc/cp/mapper-client.cc | 4 
  gcc/testsuite/g++.dg/modules/bad-mapper-3.C | 2 +-
  2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/mapper-client.cc b/gcc/cp/mapper-client.cc
index fe9544b5ba4..4dcb3a03660 100644
--- a/gcc/cp/mapper-client.cc
+++ b/gcc/cp/mapper-client.cc
@@ -227,6 +227,8 @@ module_client::open_module_client (location_t loc, 
const char *o,

  int fd = -1;
  #if CODY_NETWORKING
  fd = Cody::OpenLocal (, name.c_str () + 1);
+#else
+    errmsg = "CODY_NETWORKING disabled";


CODY_NETWORKING is implementor speak. I think just "disabled" is 
sufficient here?


Ok for trunk if I change to just "disabled" here and in the other places 
below?


Kind regards,
Torbjörn




  #endif
  if (fd >= 0)
    c = new module_client (fd, fd);
@@ -254,6 +256,8 @@ module_client::open_module_client (location_t loc, 
const char *o,

  int fd = -1;
  #if CODY_NETWORKING
  fd = Cody::OpenInet6 (, name.c_str (), port);
+#else
+    errmsg = "CODY_NETWORKING disabled";
  #endif
  name[colon] = ':';
diff --git a/gcc/testsuite/g++.dg/modules/bad-mapper-3.C 
b/gcc/testsuite/g++.dg/modules/bad-mapper-3.C

index 9dab332ccb2..c91bb4e260c 100644
--- a/gcc/testsuite/g++.dg/modules/bad-mapper-3.C
+++ b/gcc/testsuite/g++.dg/modules/bad-mapper-3.C
@@ -1,6 +1,6 @@
  //  { dg-additional-options "-fmodules-ts 
-fmodule-mapper=localhost:172477262" }

  import unique3.bob;
-// { dg-error {failed connecting mapper 'localhost:172477262'} "" { 
target *-*-* } 0 }
+// { dg-error {failed (connecting|CODY_NETWORKING disabled) mapper 
'localhost:172477262'} "" { target *-*-* } 0 }

  // { dg-prune-output "fatal error:" }
  // { dg-prune-output "failed to read" }
  // { dg-prune-output "compilation terminated" }




PING^1 [PATCH] cpp/remap: Only override if string matched

2022-11-02 Thread Torbjorn SVENSSON via Gcc-patches

Hi,

Ping, https://gcc.gnu.org/pipermail/gcc-patches/2022-October/604062.html

Ok for trunk?

Kind regards,
Torbjörn

On 2022-10-20 22:48, Torbjörn SVENSSON wrote:

For systems with HAVE_DOS_BASED_FILE_SYSTEM set, only override the
pointer if the backslash pattern matches.

Output without this patch:
.../gcc/testsuite/gcc.dg/cpp/pr71681-2.c:5:10: fatal error: a/t2.h: No such 
file or directory

With patch applied, no output and the test case succeeds.

libcpp/ChangeLog

* files.cc: Ensure pattern matches before use.

Signed-off-by: Torbjörn SVENSSON 
---
  libcpp/files.cc | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcpp/files.cc b/libcpp/files.cc
index 24208f7b0f8..a18b1caf48d 100644
--- a/libcpp/files.cc
+++ b/libcpp/files.cc
@@ -1833,7 +1833,7 @@ remap_filename (cpp_reader *pfile, _cpp_file *file)
  #ifdef HAVE_DOS_BASED_FILE_SYSTEM
{
const char *p2 = strchr (fname, '\\');
-   if (!p || (p > p2))
+   if (!p || (p2 && p > p2))
  p = p2;
}
  #endif


PING^1 [PATCH] arm: Allow to override location of .gnu.sgstubs section

2022-11-02 Thread Torbjorn SVENSSON via Gcc-patches

Hi,

Ping, https://gcc.gnu.org/pipermail/gcc-patches/2022-October/603878.html

Kind regards,
Torbjörn

On 2022-10-19 11:42, Torbjörn SVENSSON wrote:

Depending on the DejaGNU board definition, the .gnu.sgstubs section
might be placed on different locations in order to suite the target.
With this patch, the start location of the section is overrideable
from the board definition with the fallback of the previously
hardcoded location.

gcc/testsuite/ChangeLog:

* gcc.target/arm/cmse/bitfield-1.c: Use overridable location.
* gcc.target/arm/cmse/bitfield-2.c: Likewise.
* gcc.target/arm/cmse/bitfield-3.c: Likewise.
* gcc.target/arm/cmse/cmse-20.c: Likewise.
* gcc.target/arm/cmse/struct-1.c: Likewise.
* gcc.target/arm/cmse/cmse.exp (cmse_sgstubs): New.

Signed-off-by: Torbjörn SVENSSON 
---
  gcc/testsuite/gcc.target/arm/cmse/bitfield-1.c |  2 +-
  gcc/testsuite/gcc.target/arm/cmse/bitfield-2.c |  2 +-
  gcc/testsuite/gcc.target/arm/cmse/bitfield-3.c |  2 +-
  gcc/testsuite/gcc.target/arm/cmse/cmse-20.c|  2 +-
  gcc/testsuite/gcc.target/arm/cmse/cmse.exp | 11 +++
  gcc/testsuite/gcc.target/arm/cmse/struct-1.c   |  2 +-
  6 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/gcc/testsuite/gcc.target/arm/cmse/bitfield-1.c 
b/gcc/testsuite/gcc.target/arm/cmse/bitfield-1.c
index 5685f744435..c1221bef29f 100644
--- a/gcc/testsuite/gcc.target/arm/cmse/bitfield-1.c
+++ b/gcc/testsuite/gcc.target/arm/cmse/bitfield-1.c
@@ -1,5 +1,5 @@
  /* This test is executed only if the execution engine supports CMSE 
instructions.  */
-/* { dg-options "--save-temps -mcmse 
-Wl,--section-start,.gnu.sgstubs=0x0040" } */
+/* { dg-options "--save-temps -mcmse 
-Wl,--section-start,.gnu.sgstubs=[cmse_sgstubs]" } */
  
  typedef struct

  {
diff --git a/gcc/testsuite/gcc.target/arm/cmse/bitfield-2.c 
b/gcc/testsuite/gcc.target/arm/cmse/bitfield-2.c
index 7a794d44644..79e9a3efc93 100644
--- a/gcc/testsuite/gcc.target/arm/cmse/bitfield-2.c
+++ b/gcc/testsuite/gcc.target/arm/cmse/bitfield-2.c
@@ -1,5 +1,5 @@
  /* This test is executed only if the execution engine supports CMSE 
instructions.  */
-/* { dg-options "--save-temps -mcmse 
-Wl,--section-start,.gnu.sgstubs=0x0040" } */
+/* { dg-options "--save-temps -mcmse 
-Wl,--section-start,.gnu.sgstubs=[cmse_sgstubs]" } */
  
  typedef struct

  {
diff --git a/gcc/testsuite/gcc.target/arm/cmse/bitfield-3.c 
b/gcc/testsuite/gcc.target/arm/cmse/bitfield-3.c
index 5875f8dff48..d621a802ee1 100644
--- a/gcc/testsuite/gcc.target/arm/cmse/bitfield-3.c
+++ b/gcc/testsuite/gcc.target/arm/cmse/bitfield-3.c
@@ -1,5 +1,5 @@
  /* This test is executed only if the execution engine supports CMSE 
instructions.  */
-/* { dg-options "--save-temps -mcmse 
-Wl,--section-start,.gnu.sgstubs=0x0040" } */
+/* { dg-options "--save-temps -mcmse 
-Wl,--section-start,.gnu.sgstubs=[cmse_sgstubs]" } */
  
  typedef struct

  {
diff --git a/gcc/testsuite/gcc.target/arm/cmse/cmse-20.c 
b/gcc/testsuite/gcc.target/arm/cmse/cmse-20.c
index 08e89bff637..bbea9358870 100644
--- a/gcc/testsuite/gcc.target/arm/cmse/cmse-20.c
+++ b/gcc/testsuite/gcc.target/arm/cmse/cmse-20.c
@@ -1,5 +1,5 @@
  /* This test is executed only if the execution engine supports CMSE 
instructions.  */
-/* { dg-options "--save-temps -mcmse 
-Wl,--section-start,.gnu.sgstubs=0x0040" } */
+/* { dg-options "--save-temps -mcmse 
-Wl,--section-start,.gnu.sgstubs=[cmse_sgstubs]" } */
  
  #include 

  #include 
diff --git a/gcc/testsuite/gcc.target/arm/cmse/cmse.exp 
b/gcc/testsuite/gcc.target/arm/cmse/cmse.exp
index 436dd71ef89..1df5d56c6d5 100644
--- a/gcc/testsuite/gcc.target/arm/cmse/cmse.exp
+++ b/gcc/testsuite/gcc.target/arm/cmse/cmse.exp
@@ -44,6 +44,17 @@ if {[is-effective-target arm_cmse_hw]} then {
  set saved-lto_torture_options ${LTO_TORTURE_OPTIONS}
  set LTO_TORTURE_OPTIONS ""
  
+# Return the start address of the .gnu.sgstubs section.

+proc cmse_sgstubs {} {
+# Allow to override the location of .gnu.sgstubs section.
+set tboard [target_info name]
+if {[board_info $tboard exists cmse_sgstubs]} {
+   return [board_info $tboard cmse_sgstubs]
+}
+
+return "0x0040"
+}
+
  # These are for both baseline and mainline.
  gcc-dg-runtest [lsort [glob $srcdir/$subdir/*.c]] \
"" $DEFAULT_CFLAGS
diff --git a/gcc/testsuite/gcc.target/arm/cmse/struct-1.c 
b/gcc/testsuite/gcc.target/arm/cmse/struct-1.c
index 75a99f487e7..bebd059b13f 100644
--- a/gcc/testsuite/gcc.target/arm/cmse/struct-1.c
+++ b/gcc/testsuite/gcc.target/arm/cmse/struct-1.c
@@ -1,5 +1,5 @@
  /* This test is executed only if the execution engine supports CMSE 
instructions.  */
-/* { dg-options "--save-temps -mcmse 
-Wl,--section-start,.gnu.sgstubs=0x0040" } */
+/* { dg-options "--save-temps -mcmse 
-Wl,--section-start,.gnu.sgstubs=[cmse_sgstubs]" } */
  
  typedef struct

  {


PING^1 [PATCH] testsuite: Windows paths use \ and not /

2022-11-02 Thread Torbjorn SVENSSON via Gcc-patches

Hi,

Ping, https://gcc.gnu.org/pipermail/gcc-patches/2022-October/604312.html

Ok for trunk?

Kind regards,
Torbjörn

On 2022-10-25 17:15, Torbjörn SVENSSON wrote:

Without this patch, the following error is reported on Windows:

In file included from t:\build\arm-none-eabi\include\c++\11.3.1\string:54,
   from 
t:\build\arm-none-eabi\include\c++\11.3.1\bits\locale_classes.h:40,
   from 
t:\build\arm-none-eabi\include\c++\11.3.1\bits\ios_base.h:41,
   from t:\build\arm-none-eabi\include\c++\11.3.1\ios:42,
   from t:\build\arm-none-eabi\include\c++\11.3.1\ostream:38,
   from t:\build\arm-none-eabi\include\c++\11.3.1\iostream:39:
t:\build\arm-none-eabi\include\c++\11.3.1\bits\range_access.h:36:10: note: 
include 't:\build\arm-none-eabi\include\c++\11.3.1\initializer_list' translated 
to import
arm-none-eabi-g++.exe: warning: .../gcc/testsuite/g++.dg/modules/pr99023_b.X: 
linker input file unused because linking not done
FAIL: g++.dg/modules/pr99023_b.X -std=c++2a  dg-regexp 6 not found: "[^\n]*: note: 
include '[^\n]*/initializer_list' translated to import\n"

gcc/testsuite/ChangeLog:

* g++.dg/modules/pr99023_b.X: Match Windows paths too.

Co-Authored-By: Yvan ROUX 
Signed-off-by: Torbjörn SVENSSON 
---
  gcc/testsuite/g++.dg/modules/pr99023_b.X | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/g++.dg/modules/pr99023_b.X 
b/gcc/testsuite/g++.dg/modules/pr99023_b.X
index 3d82f34868b..ca5f32e5bcc 100644
--- a/gcc/testsuite/g++.dg/modules/pr99023_b.X
+++ b/gcc/testsuite/g++.dg/modules/pr99023_b.X
@@ -3,5 +3,5 @@
  
  // { dg-prune-output {linker input file unused} }
  
-// { dg-regexp {[^\n]*: note: include '[^\n]*/initializer_list' translated to import\n} }

+// { dg-regexp {[^\n]*: note: include '[^\n]*[/\\]initializer_list' translated 
to import\n} }
  NO DO NOT COMPILE


Re: PING^4 [PATCH] testsuite: Verify that module-mapper is available

2022-11-02 Thread Torbjorn SVENSSON via Gcc-patches

Hi,

Ping, https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602844.html

Ok for trunk?

Kind regards,
Torbjörn

On 2022-10-25 16:24, Torbjorn SVENSSON via Gcc-patches wrote:

Hi,

Ping, https://gcc.gnu.org/pipermail/gcc-patches/2022-October/603544.html

Kind regards,
Torbjörn

On 2022-10-14 09:42, Torbjorn SVENSSON wrote:

Hi,

Ping, https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602843.html

Kind regards,
Torbjörn

On 2022-10-05 11:17, Torbjorn SVENSSON wrote:

Hi,

Ping, 
https://gcc.gnu.org/pipermail/gcc-patches/2022-September/602111.html


Kind regards,
Torbjörn

On 2022-09-23 14:03, Torbjörn SVENSSON wrote:

For some test cases, it's required that the optional module mapper
"g++-mapper-server" is built. As the server is not required, the
test cases will fail if it can't be found.

gcc/testsuite/ChangeLog:

* lib/target-supports.exp (check_is_prog_name_available):
New.
* lib/target-supports-dg.exp
(dg-require-prog-name-available): New.
* g++.dg/modules/modules.exp: Verify avilability of module
mapper.

Signed-off-by: Torbjörn SVENSSON  
---
  gcc/testsuite/g++.dg/modules/modules.exp | 31 


  gcc/testsuite/lib/target-supports-dg.exp | 15 
  gcc/testsuite/lib/target-supports.exp    | 15 
  3 files changed, 61 insertions(+)

diff --git a/gcc/testsuite/g++.dg/modules/modules.exp 
b/gcc/testsuite/g++.dg/modules/modules.exp

index afb323d0efd..4784803742a 100644
--- a/gcc/testsuite/g++.dg/modules/modules.exp
+++ b/gcc/testsuite/g++.dg/modules/modules.exp
@@ -279,6 +279,29 @@ proc module-init { src } {
  return $option_list
  }
+# Return 1 if requirements are met
+proc module-check-requirements { tests } {
+    foreach test $tests {
+    set tmp [dg-get-options $test]
+    foreach op $tmp {
+    switch [lindex $op 0] {
+    "dg-additional-options" {
+    # Example strings to match:
+    # -fmodules-ts -fmodule-mapper=|@g++-mapper-server\\ 
-t\\ [srcdir]/inc-xlate-1.map

+    # -fmodules-ts -fmodule-mapper=|@g++-mapper-server
+    if [regexp -- {(^| )-fmodule-mapper=\|@([^\\ ]*)} 
[lindex $op 2] dummy dummy2 prog] {

+    verbose "Checking that mapper exist: $prog"
+    if { ![ check_is_prog_name_available $prog ] } {
+    return 0
+    }
+    }
+    }
+    }
+    }
+    }
+    return 1
+}
+
  # cleanup any detritus from previous run
  cleanup_module_files [find $DEFAULT_REPO *.gcm]
@@ -307,6 +330,14 @@ foreach src [lsort [find $srcdir/$subdir 
{*_a.[CHX}]] {

  set tests [lsort [find [file dirname $src] \
    [regsub {_a.[CHX]$} [file tail $src] 
{_[a-z].[CHX]}]]]

+    if { ![module-check-requirements $tests] } {
+    set testcase [regsub {_a.[CH]} $src {}]
+    set testcase \
+    [string range $testcase [string length "$srcdir/"] end]
+    unsupported $testcase
+    continue
+    }
+
  set std_list [module-init $src]
  foreach std $std_list {
  set mod_files {}
diff --git a/gcc/testsuite/lib/target-supports-dg.exp 
b/gcc/testsuite/lib/target-supports-dg.exp

index aa2164bc789..6ce3b2b1a1b 100644
--- a/gcc/testsuite/lib/target-supports-dg.exp
+++ b/gcc/testsuite/lib/target-supports-dg.exp
@@ -683,3 +683,18 @@ proc dg-require-symver { args } {
  set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
  }
  }
+
+# If this target does not provide prog named "$args", skip this test.
+
+proc dg-require-prog-name-available { args } {
+    # The args are within another list; pull them out.
+    set args [lindex $args 0]
+
+    set prog [lindex $args 1]
+
+    if { ![ check_is_prog_name_available $prog ] } {
+    upvar dg-do-what dg-do-what
+    set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
+    }
+}
+
diff --git a/gcc/testsuite/lib/target-supports.exp 
b/gcc/testsuite/lib/target-supports.exp

index 703aba412a6..c3b7a6c17b3 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -11928,3 +11928,18 @@ main:
  .byte 0
    } ""]
  }
+
+# Return 1 if this target has prog named "$prog", 0 otherwise.
+
+proc check_is_prog_name_available { prog } {
+    global tool
+
+    set options [list "additional_flags=-print-prog-name=$prog"]
+    set output [lindex [${tool}_target_compile "" "" "none" 
$options] 0]

+
+    if { $output == $prog } {
+    return 0
+    }
+
+    return 1
+}


Re: [PATCH] IRA: Make sure array is big enough

2022-10-27 Thread Torbjorn SVENSSON via Gcc-patches




On 2022-10-26 22:26, Vladimir Makarov wrote:


On 2022-10-25 06:01, Torbjörn SVENSSON wrote:

In commit 081c96621da, the call to resize_reg_info() was moved before
the call to remove_scratches() and the latter one can increase the
number of regs and that would cause an out of bounds usage on the
reg_renumber global array.

Without this patch, the following testcase randomly fails with:
during RTL pass: ira
In file included from 
/src/gcc/testsuite/gcc.dg/compat//struct-by-value-5b_y.c:13:
/src/gcc/testsuite/gcc.dg/compat//struct-by-value-5b_y.c: In function 
'checkgSf13':
/src/gcc/testsuite/gcc.dg/compat//fp-struct-test-by-value-y.h:28:1: 
internal compiler error: Segmentation fault
/src/gcc/testsuite/gcc.dg/compat//struct-by-value-5b_y.c:22:1: note: 
in expansion of macro 'TEST'


gcc/ChangeLog:

* ira.c: Resize array after reg number increased.


The patch is ok to commit it into gcc-11,12 branches and master.


Thank you for the review!
Pushed to gcc-11, gcc-12 and master.



Thank you for fixing this.


Co-Authored-By: Yvan ROUX 
Signed-off-by: Torbjörn SVENSSON 
---
  gcc/ira.cc | 1 +
  1 file changed, 1 insertion(+)

diff --git a/gcc/ira.cc b/gcc/ira.cc
index 42c9cead9f8..d28a67b2546 100644
--- a/gcc/ira.cc
+++ b/gcc/ira.cc
@@ -5718,6 +5718,7 @@ ira (FILE *f)
  regstat_free_ri ();
  regstat_init_n_sets_and_refs ();
  regstat_compute_ri ();
+    resize_reg_info ();
    };
    int max_regno_before_rm = max_reg_num ();




PING^3 [PATCH] testsuite: Verify that module-mapper is available

2022-10-25 Thread Torbjorn SVENSSON via Gcc-patches

Hi,

Ping, https://gcc.gnu.org/pipermail/gcc-patches/2022-October/603544.html

Kind regards,
Torbjörn

On 2022-10-14 09:42, Torbjorn SVENSSON wrote:

Hi,

Ping, https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602843.html

Kind regards,
Torbjörn

On 2022-10-05 11:17, Torbjorn SVENSSON wrote:

Hi,

Ping, 
https://gcc.gnu.org/pipermail/gcc-patches/2022-September/602111.html


Kind regards,
Torbjörn

On 2022-09-23 14:03, Torbjörn SVENSSON wrote:

For some test cases, it's required that the optional module mapper
"g++-mapper-server" is built. As the server is not required, the
test cases will fail if it can't be found.

gcc/testsuite/ChangeLog:

* lib/target-supports.exp (check_is_prog_name_available):
New.
* lib/target-supports-dg.exp
(dg-require-prog-name-available): New.
* g++.dg/modules/modules.exp: Verify avilability of module
mapper.

Signed-off-by: Torbjörn SVENSSON  
---
  gcc/testsuite/g++.dg/modules/modules.exp | 31 
  gcc/testsuite/lib/target-supports-dg.exp | 15 
  gcc/testsuite/lib/target-supports.exp    | 15 
  3 files changed, 61 insertions(+)

diff --git a/gcc/testsuite/g++.dg/modules/modules.exp 
b/gcc/testsuite/g++.dg/modules/modules.exp

index afb323d0efd..4784803742a 100644
--- a/gcc/testsuite/g++.dg/modules/modules.exp
+++ b/gcc/testsuite/g++.dg/modules/modules.exp
@@ -279,6 +279,29 @@ proc module-init { src } {
  return $option_list
  }
+# Return 1 if requirements are met
+proc module-check-requirements { tests } {
+    foreach test $tests {
+    set tmp [dg-get-options $test]
+    foreach op $tmp {
+    switch [lindex $op 0] {
+    "dg-additional-options" {
+    # Example strings to match:
+    # -fmodules-ts -fmodule-mapper=|@g++-mapper-server\\ 
-t\\ [srcdir]/inc-xlate-1.map

+    # -fmodules-ts -fmodule-mapper=|@g++-mapper-server
+    if [regexp -- {(^| )-fmodule-mapper=\|@([^\\ ]*)} 
[lindex $op 2] dummy dummy2 prog] {

+    verbose "Checking that mapper exist: $prog"
+    if { ![ check_is_prog_name_available $prog ] } {
+    return 0
+    }
+    }
+    }
+    }
+    }
+    }
+    return 1
+}
+
  # cleanup any detritus from previous run
  cleanup_module_files [find $DEFAULT_REPO *.gcm]
@@ -307,6 +330,14 @@ foreach src [lsort [find $srcdir/$subdir 
{*_a.[CHX}]] {

  set tests [lsort [find [file dirname $src] \
    [regsub {_a.[CHX]$} [file tail $src] 
{_[a-z].[CHX]}]]]

+    if { ![module-check-requirements $tests] } {
+    set testcase [regsub {_a.[CH]} $src {}]
+    set testcase \
+    [string range $testcase [string length "$srcdir/"] end]
+    unsupported $testcase
+    continue
+    }
+
  set std_list [module-init $src]
  foreach std $std_list {
  set mod_files {}
diff --git a/gcc/testsuite/lib/target-supports-dg.exp 
b/gcc/testsuite/lib/target-supports-dg.exp

index aa2164bc789..6ce3b2b1a1b 100644
--- a/gcc/testsuite/lib/target-supports-dg.exp
+++ b/gcc/testsuite/lib/target-supports-dg.exp
@@ -683,3 +683,18 @@ proc dg-require-symver { args } {
  set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
  }
  }
+
+# If this target does not provide prog named "$args", skip this test.
+
+proc dg-require-prog-name-available { args } {
+    # The args are within another list; pull them out.
+    set args [lindex $args 0]
+
+    set prog [lindex $args 1]
+
+    if { ![ check_is_prog_name_available $prog ] } {
+    upvar dg-do-what dg-do-what
+    set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
+    }
+}
+
diff --git a/gcc/testsuite/lib/target-supports.exp 
b/gcc/testsuite/lib/target-supports.exp

index 703aba412a6..c3b7a6c17b3 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -11928,3 +11928,18 @@ main:
  .byte 0
    } ""]
  }
+
+# Return 1 if this target has prog named "$prog", 0 otherwise.
+
+proc check_is_prog_name_available { prog } {
+    global tool
+
+    set options [list "additional_flags=-print-prog-name=$prog"]
+    set output [lindex [${tool}_target_compile "" "" "none" 
$options] 0]

+
+    if { $output == $prog } {
+    return 0
+    }
+
+    return 1
+}


Re: [PATCH] lto: Always quote path to touch

2022-10-24 Thread Torbjorn SVENSSON via Gcc-patches




On 2022-10-24 10:07, Richard Biener wrote:

On Fri, 21 Oct 2022, Torbj?rn SVENSSON wrote:


When generating the makefile, make sure that the paths are quoted so
that a native Windows path works within Cygwin.

Without this patch, this error is reported by the DejaGNU test suite:

make: [T:\ccMf0kI3.mk:3: T:\ccGEvdDp.ltrans0.ltrans.o] Error 1 (ignored)

The generated makefile fragment without the patch:

T:\ccGEvdDp.ltrans0.ltrans.o:
   @T:\build\bin\arm-none-eabi-g++.exe '-xlto' ... '-o' 
'T:\ccGEvdDp.ltrans0.ltrans.o' 'T:\ccGEvdDp.ltrans0.o'
   @-touch -r T:\ccGEvdDp.ltrans0.o T:\ccGEvdDp.ltrans0.o.tem > /dev/null 2>&1 
&& mv T:\ccGEvdDp.ltrans0.o.tem T:\ccGEvdDp.ltrans0.o
.PHONY: all
all: \
   T:\ccGEvdDp.ltrans0.ltrans.o

With the patch, the touch line would be replace with:

   @-touch -r "T:\ccGEvdDp.ltrans0.o" "T:\ccGEvdDp.ltrans0.o.tem" > /dev/null 2>&1 && mv 
"T:\ccGEvdDp.ltrans0.o.tem" "T:\ccGEvdDp.ltrans0.o"

gcc/ChangeLog:


OK.

Thanks,
Richard.


* lto-wrapper.cc: Quote paths in makefile.

Co-Authored-By: Yvan ROUX 
Signed-off-by: Torbj?rn SVENSSON 
---
  gcc/lto-wrapper.cc | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/lto-wrapper.cc b/gcc/lto-wrapper.cc
index 9a764702ffc..b12bcc1ad27 100644
--- a/gcc/lto-wrapper.cc
+++ b/gcc/lto-wrapper.cc
@@ -2010,8 +2010,8 @@ cont:
 truncate them as soon as we have processed it.  This
 reduces temporary disk-space usage.  */
  if (! save_temps)
-   fprintf (mstream, "\t@-touch -r %s %s.tem > /dev/null 2>&1 "
-"&& mv %s.tem %s\n",
+   fprintf (mstream, "\t@-touch -r \"%s\" \"%s.tem\" > /dev/null "
+"2>&1 && mv \"%s.tem\" \"%s\"\n",
 input_name, input_name, input_name, input_name);
}
  else






Pushed.


Re: [PATCH v4] testsuite: Sanitize fails for SP FPU on Arm

2022-10-20 Thread Torbjorn SVENSSON via Gcc-patches




On 2022-10-20 20:19, Joseph Myers wrote:

On Wed, 19 Oct 2022, Torbjörn SVENSSON via Gcc-patches wrote:


This patch stops reporting fails for Arm targets with single
precision floating point unit for types wider than 32 bits (the width
of float on arm-none-eabi).

As reported in PR102017, fenv is reported as supported in recent
versions of newlib. At the same time, for some Arm targets, the
implementation in libgcc does not support exceptions and thus, the
test fails with a call to abort().


This patch is OK.



Thanks Joseph!

Pushed.


Re: [PATCH] arm: Allow to override location of .gnu.sgstubs section

2022-10-19 Thread Torbjorn SVENSSON via Gcc-patches

Hi Christophe,

On 2022-10-19 11:52, Christophe Lyon wrote:

Hi Torbjörn,

This looks like a nice improvement to me ;-)

On 10/19/22 11:42, Torbjörn SVENSSON via Gcc-patches wrote:

Depending on the DejaGNU board definition, the .gnu.sgstubs section
might be placed on different locations in order to suite the target.

typo: suite -> suit


With this patch, the start location of the section is overrideable
from the board definition with the fallback of the previously
hardcoded location.

gcc/testsuite/ChangeLog:

* gcc.target/arm/cmse/bitfield-1.c: Use overridable location.
* gcc.target/arm/cmse/bitfield-2.c: Likewise.
* gcc.target/arm/cmse/bitfield-3.c: Likewise.
* gcc.target/arm/cmse/cmse-20.c: Likewise.
* gcc.target/arm/cmse/struct-1.c: Likewise.
* gcc.target/arm/cmse/cmse.exp (cmse_sgstubs): New.

Signed-off-by: Torbjörn SVENSSON 
---
  gcc/testsuite/gcc.target/arm/cmse/bitfield-1.c |  2 +-
  gcc/testsuite/gcc.target/arm/cmse/bitfield-2.c |  2 +-
  gcc/testsuite/gcc.target/arm/cmse/bitfield-3.c |  2 +-
  gcc/testsuite/gcc.target/arm/cmse/cmse-20.c    |  2 +-
  gcc/testsuite/gcc.target/arm/cmse/cmse.exp | 11 +++
  gcc/testsuite/gcc.target/arm/cmse/struct-1.c   |  2 +-
  6 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/gcc/testsuite/gcc.target/arm/cmse/bitfield-1.c 
b/gcc/testsuite/gcc.target/arm/cmse/bitfield-1.c

index 5685f744435..c1221bef29f 100644
--- a/gcc/testsuite/gcc.target/arm/cmse/bitfield-1.c
+++ b/gcc/testsuite/gcc.target/arm/cmse/bitfield-1.c
@@ -1,5 +1,5 @@
  /* This test is executed only if the execution engine supports CMSE 
instructions.  */
-/* { dg-options "--save-temps -mcmse 
-Wl,--section-start,.gnu.sgstubs=0x0040" } */
+/* { dg-options "--save-temps -mcmse 
-Wl,--section-start,.gnu.sgstubs=[cmse_sgstubs]" } */

  typedef struct
  {
diff --git a/gcc/testsuite/gcc.target/arm/cmse/bitfield-2.c 
b/gcc/testsuite/gcc.target/arm/cmse/bitfield-2.c

index 7a794d44644..79e9a3efc93 100644
--- a/gcc/testsuite/gcc.target/arm/cmse/bitfield-2.c
+++ b/gcc/testsuite/gcc.target/arm/cmse/bitfield-2.c
@@ -1,5 +1,5 @@
  /* This test is executed only if the execution engine supports CMSE 
instructions.  */
-/* { dg-options "--save-temps -mcmse 
-Wl,--section-start,.gnu.sgstubs=0x0040" } */
+/* { dg-options "--save-temps -mcmse 
-Wl,--section-start,.gnu.sgstubs=[cmse_sgstubs]" } */

  typedef struct
  {
diff --git a/gcc/testsuite/gcc.target/arm/cmse/bitfield-3.c 
b/gcc/testsuite/gcc.target/arm/cmse/bitfield-3.c

index 5875f8dff48..d621a802ee1 100644
--- a/gcc/testsuite/gcc.target/arm/cmse/bitfield-3.c
+++ b/gcc/testsuite/gcc.target/arm/cmse/bitfield-3.c
@@ -1,5 +1,5 @@
  /* This test is executed only if the execution engine supports CMSE 
instructions.  */
-/* { dg-options "--save-temps -mcmse 
-Wl,--section-start,.gnu.sgstubs=0x0040" } */
+/* { dg-options "--save-temps -mcmse 
-Wl,--section-start,.gnu.sgstubs=[cmse_sgstubs]" } */

  typedef struct
  {
diff --git a/gcc/testsuite/gcc.target/arm/cmse/cmse-20.c 
b/gcc/testsuite/gcc.target/arm/cmse/cmse-20.c

index 08e89bff637..bbea9358870 100644
--- a/gcc/testsuite/gcc.target/arm/cmse/cmse-20.c
+++ b/gcc/testsuite/gcc.target/arm/cmse/cmse-20.c
@@ -1,5 +1,5 @@
  /* This test is executed only if the execution engine supports CMSE 
instructions.  */
-/* { dg-options "--save-temps -mcmse 
-Wl,--section-start,.gnu.sgstubs=0x0040" } */
+/* { dg-options "--save-temps -mcmse 
-Wl,--section-start,.gnu.sgstubs=[cmse_sgstubs]" } */

  #include 
  #include 
diff --git a/gcc/testsuite/gcc.target/arm/cmse/cmse.exp 
b/gcc/testsuite/gcc.target/arm/cmse/cmse.exp

index 436dd71ef89..1df5d56c6d5 100644
--- a/gcc/testsuite/gcc.target/arm/cmse/cmse.exp
+++ b/gcc/testsuite/gcc.target/arm/cmse/cmse.exp
@@ -44,6 +44,17 @@ if {[is-effective-target arm_cmse_hw]} then {
  set saved-lto_torture_options ${LTO_TORTURE_OPTIONS}
  set LTO_TORTURE_OPTIONS ""
+# Return the start address of the .gnu.sgstubs section.
+proc cmse_sgstubs {} {
+    # Allow to override the location of .gnu.sgstubs section.
+    set tboard [target_info name]
+    if {[board_info $tboard exists cmse_sgstubs]} {
+    return [board_info $tboard cmse_sgstubs]
+    }
+
+    return "0x0040"
+}
+


I am not sure if/where this new cmse_sgstubs target-board property needs 
to be documented?


I'm not sure either. Everytime I need to do something with the 
target-board properties, I just look at other examples in the tree and 
replicate what they do.
I'm also not sure if "cmse_sgstubs" is a good name, but I was unable to 
come up with a more meaningful name that was not a mile long... If there 
is any sugession on a better name, please speak up! :)


Kind regards,
Torbjörn


PING^1 [PATCH v3] testsuite: Sanitize fails for SP FPU on Arm

2022-10-14 Thread Torbjorn SVENSSON via Gcc-patches

Hi,

Ping, https://gcc.gnu.org/pipermail/gcc-patches/2022-October/603054.html

Kind regards,
Torbjörn

On 2022-10-07 15:28, Torbjörn SVENSSON wrote:

This patch stops reporting fails for Arm targets with single
precision floating point unit for types wider than 32 bits (the width
of float on arm-none-eabi).

As reported in PR102017, fenv is reported as supported in recent
versions of newlib. At the same time, for some Arm targets, the
implementation in libgcc does not support exceptions and thus, the
test fails with a call to abort().

gcc/testsuite/ChangeLog:

* lib/target-supports.exp
(check_effective_target_fenv_exceptions_double): New.
(check_effective_target_fenv_exceptions_long_double): New.
* gcc.dg/c2x-float-7.c: Split into 3 tests...
* gcc.dg/c2x-float-7a.c: Float part of c2x-float-7.c.
* gcc.dg/c2x-float-7b.c: Double part of c2x-float-7.c.
* gcc.dg/c2x-float-7c.c: Long double part of c2x-float-7.c.
* gcc.dg/pr95115.c: Switch to fenv_exceptions_double.
* gcc.dg/torture/float32x-nan-floath.c: Likewise.
* gcc.dg/torture/float32x-nan.c: Likewise.
* gcc.dg/torture/float64-nan-floath.c: Likewise.
* gcc.dg/torture/float64-nan.c: Likewise.
* gcc.dg/torture/inf-compare-1.c: Likewise.
* gcc.dg/torture/inf-compare-2.c: Likewise.
* gcc.dg/torture/inf-compare-3.c: Likewise.
* gcc.dg/torture/inf-compare-4.c: Likewise.
* gcc.dg/torture/inf-compare-5.c: Likewise.
* gcc.dg/torture/inf-compare-6.c: Likewise.
* gcc.dg/torture/inf-compare-7.c: Likewise.
* gcc.dg/torture/inf-compare-8.c: Likewise.
* gcc.dg/torture/inf-compare-1-float.c: New test.
* gcc.dg/torture/inf-compare-2-float.c: New test.
* gcc.dg/torture/inf-compare-3-float.c: New test.
* gcc.dg/torture/inf-compare-4-float.c: New test.
* gcc.dg/torture/inf-compare-5-float.c: New test.
* gcc.dg/torture/inf-compare-6-float.c: New test.
* gcc.dg/torture/inf-compare-7-float.c: New test.
* gcc.dg/torture/inf-compare-8-float.c: New test.

Co-Authored-By: Yvan ROUX  
Signed-off-by: Torbjörn SVENSSON  
---
  gcc/testsuite/gcc.dg/c2x-float-7.c| 49 
  gcc/testsuite/gcc.dg/c2x-float-7a.c   | 32 
  gcc/testsuite/gcc.dg/c2x-float-7b.c   | 32 
  gcc/testsuite/gcc.dg/c2x-float-7c.c   | 32 
  gcc/testsuite/gcc.dg/pr95115.c|  2 +-
  .../gcc.dg/torture/float32x-nan-floath.c  |  2 +-
  gcc/testsuite/gcc.dg/torture/float32x-nan.c   |  2 +-
  .../gcc.dg/torture/float64-nan-floath.c   |  2 +-
  gcc/testsuite/gcc.dg/torture/float64-nan.c|  2 +-
  .../gcc.dg/torture/inf-compare-1-float.c  | 21 ++
  gcc/testsuite/gcc.dg/torture/inf-compare-1.c  |  2 +-
  .../gcc.dg/torture/inf-compare-2-float.c  | 21 ++
  gcc/testsuite/gcc.dg/torture/inf-compare-2.c  |  2 +-
  .../gcc.dg/torture/inf-compare-3-float.c  | 21 ++
  gcc/testsuite/gcc.dg/torture/inf-compare-3.c  |  2 +-
  .../gcc.dg/torture/inf-compare-4-float.c  | 21 ++
  gcc/testsuite/gcc.dg/torture/inf-compare-4.c  |  2 +-
  .../gcc.dg/torture/inf-compare-5-float.c  | 19 +
  gcc/testsuite/gcc.dg/torture/inf-compare-5.c  |  2 +-
  .../gcc.dg/torture/inf-compare-6-float.c  | 19 +
  gcc/testsuite/gcc.dg/torture/inf-compare-6.c  |  2 +-
  .../gcc.dg/torture/inf-compare-7-float.c  | 19 +
  gcc/testsuite/gcc.dg/torture/inf-compare-7.c  |  2 +-
  .../gcc.dg/torture/inf-compare-8-float.c  | 19 +
  gcc/testsuite/gcc.dg/torture/inf-compare-8.c  |  2 +-
  gcc/testsuite/lib/target-supports.exp | 74 +++
  26 files changed, 343 insertions(+), 62 deletions(-)
  delete mode 100644 gcc/testsuite/gcc.dg/c2x-float-7.c
  create mode 100644 gcc/testsuite/gcc.dg/c2x-float-7a.c
  create mode 100644 gcc/testsuite/gcc.dg/c2x-float-7b.c
  create mode 100644 gcc/testsuite/gcc.dg/c2x-float-7c.c
  create mode 100644 gcc/testsuite/gcc.dg/torture/inf-compare-1-float.c
  create mode 100644 gcc/testsuite/gcc.dg/torture/inf-compare-2-float.c
  create mode 100644 gcc/testsuite/gcc.dg/torture/inf-compare-3-float.c
  create mode 100644 gcc/testsuite/gcc.dg/torture/inf-compare-4-float.c
  create mode 100644 gcc/testsuite/gcc.dg/torture/inf-compare-5-float.c
  create mode 100644 gcc/testsuite/gcc.dg/torture/inf-compare-6-float.c
  create mode 100644 gcc/testsuite/gcc.dg/torture/inf-compare-7-float.c
  create mode 100644 gcc/testsuite/gcc.dg/torture/inf-compare-8-float.c

diff --git a/gcc/testsuite/gcc.dg/c2x-float-7.c 
b/gcc/testsuite/gcc.dg/c2x-float-7.c
deleted file mode 100644
index 0c90ff24165..000
--- a/gcc/testsuite/gcc.dg/c2x-float-7.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/* Test SNAN macros.  Runtime exceptions test, to verify NaN is
-   signaling.  */
-/* { dg-do run } */
-/* { dg-require-effective-target fenv_exceptions } */
-/* { dg-options "-std=c2x 

PING^2 [PATCH] testsuite: Verify that module-mapper is available

2022-10-14 Thread Torbjorn SVENSSON via Gcc-patches

Hi,

Ping, https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602843.html

Kind regards,
Torbjörn

On 2022-10-05 11:17, Torbjorn SVENSSON wrote:

Hi,

Ping, https://gcc.gnu.org/pipermail/gcc-patches/2022-September/602111.html

Kind regards,
Torbjörn

On 2022-09-23 14:03, Torbjörn SVENSSON wrote:

For some test cases, it's required that the optional module mapper
"g++-mapper-server" is built. As the server is not required, the
test cases will fail if it can't be found.

gcc/testsuite/ChangeLog:

* lib/target-supports.exp (check_is_prog_name_available):
New.
* lib/target-supports-dg.exp
(dg-require-prog-name-available): New.
* g++.dg/modules/modules.exp: Verify avilability of module
mapper.

Signed-off-by: Torbjörn SVENSSON  
---
  gcc/testsuite/g++.dg/modules/modules.exp | 31 
  gcc/testsuite/lib/target-supports-dg.exp | 15 
  gcc/testsuite/lib/target-supports.exp    | 15 
  3 files changed, 61 insertions(+)

diff --git a/gcc/testsuite/g++.dg/modules/modules.exp 
b/gcc/testsuite/g++.dg/modules/modules.exp

index afb323d0efd..4784803742a 100644
--- a/gcc/testsuite/g++.dg/modules/modules.exp
+++ b/gcc/testsuite/g++.dg/modules/modules.exp
@@ -279,6 +279,29 @@ proc module-init { src } {
  return $option_list
  }
+# Return 1 if requirements are met
+proc module-check-requirements { tests } {
+    foreach test $tests {
+    set tmp [dg-get-options $test]
+    foreach op $tmp {
+    switch [lindex $op 0] {
+    "dg-additional-options" {
+    # Example strings to match:
+    # -fmodules-ts -fmodule-mapper=|@g++-mapper-server\\ -t\\ 
[srcdir]/inc-xlate-1.map

+    # -fmodules-ts -fmodule-mapper=|@g++-mapper-server
+    if [regexp -- {(^| )-fmodule-mapper=\|@([^\\ ]*)} [lindex 
$op 2] dummy dummy2 prog] {

+    verbose "Checking that mapper exist: $prog"
+    if { ![ check_is_prog_name_available $prog ] } {
+    return 0
+    }
+    }
+    }
+    }
+    }
+    }
+    return 1
+}
+
  # cleanup any detritus from previous run
  cleanup_module_files [find $DEFAULT_REPO *.gcm]
@@ -307,6 +330,14 @@ foreach src [lsort [find $srcdir/$subdir 
{*_a.[CHX}]] {

  set tests [lsort [find [file dirname $src] \
    [regsub {_a.[CHX]$} [file tail $src] 
{_[a-z].[CHX]}]]]

+    if { ![module-check-requirements $tests] } {
+    set testcase [regsub {_a.[CH]} $src {}]
+    set testcase \
+    [string range $testcase [string length "$srcdir/"] end]
+    unsupported $testcase
+    continue
+    }
+
  set std_list [module-init $src]
  foreach std $std_list {
  set mod_files {}
diff --git a/gcc/testsuite/lib/target-supports-dg.exp 
b/gcc/testsuite/lib/target-supports-dg.exp

index aa2164bc789..6ce3b2b1a1b 100644
--- a/gcc/testsuite/lib/target-supports-dg.exp
+++ b/gcc/testsuite/lib/target-supports-dg.exp
@@ -683,3 +683,18 @@ proc dg-require-symver { args } {
  set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
  }
  }
+
+# If this target does not provide prog named "$args", skip this test.
+
+proc dg-require-prog-name-available { args } {
+    # The args are within another list; pull them out.
+    set args [lindex $args 0]
+
+    set prog [lindex $args 1]
+
+    if { ![ check_is_prog_name_available $prog ] } {
+    upvar dg-do-what dg-do-what
+    set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
+    }
+}
+
diff --git a/gcc/testsuite/lib/target-supports.exp 
b/gcc/testsuite/lib/target-supports.exp

index 703aba412a6..c3b7a6c17b3 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -11928,3 +11928,18 @@ main:
  .byte 0
    } ""]
  }
+
+# Return 1 if this target has prog named "$prog", 0 otherwise.
+
+proc check_is_prog_name_available { prog } {
+    global tool
+
+    set options [list "additional_flags=-print-prog-name=$prog"]
+    set output [lindex [${tool}_target_compile "" "" "none" $options] 0]
+
+    if { $output == $prog } {
+    return 0
+    }
+
+    return 1
+}


Re: PING^1 [PATCH] testsuite: 'b' instruction can't do long enough jumps

2022-10-05 Thread Torbjorn SVENSSON via Gcc-patches




On 2022-10-05 11:51, Kyrylo Tkachov wrote:

Hi Torbjörn,


-Original Message-
From: Torbjorn SVENSSON 
Sent: Wednesday, October 5, 2022 10:28 AM
To: Kyrylo Tkachov 
Cc: Yvan Roux 
Subject: Fwd: PING^1 [PATCH] testsuite: 'b' instruction can't do long enough
jumps

Hi Kyrill,

I checked with Richard Sandiford if he could review this patch, but he
pointed to you.
Do you think that you can take a look it?


This is ok. I don't think it changes any of the things we want to actually test 
for in these cases.
Thanks,
Kyrill


Thank you!
Pushed to master branch 1a46a0a8b30405ea353a758971634dabeee89eaf.

Kind regards,
Torbjörn


Re: [PATCH] testsuite: /dev/null is not accessible on Windows

2022-10-05 Thread Torbjorn SVENSSON via Gcc-patches

Hi,

On 2022-10-05 11:34, Jonathan Yong via Gcc-patches wrote:

On 9/29/22 17:38, Torbjörn SVENSSON via Gcc-patches wrote:

When running the DejaGNU testsuite on a toolchain built for native
Windows, the path /dev/null can't be used to open a stream to void.
On native Windows, the resource is instead named "nul".

The error would look like this:
c:/arm-11.3.rel1/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe:
 cannot find @/dev/null: No such file or directory

Patch has been verified on Windows and Linux.

gcc/testsuite:

* gcc.misc-tests/outputs.exp: Use "@nul" for Windows,
"@/dev/null" for other environments.

Co-Authored-By: Yvan ROUX  
Signed-off-by: Torbjörn SVENSSON  
---
  gcc/testsuite/gcc.misc-tests/outputs.exp | 17 -
  1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/gcc/testsuite/gcc.misc-tests/outputs.exp 
b/gcc/testsuite/gcc.misc-tests/outputs.exp

index ab919db1ccb..3fe7270fa63 100644
--- a/gcc/testsuite/gcc.misc-tests/outputs.exp
+++ b/gcc/testsuite/gcc.misc-tests/outputs.exp
@@ -78,6 +78,13 @@ if {[board_info $dest exists output_format]} {
  append link_options " additional_flags=-Wl,-oformat,[board_info 
$dest output_format]"

  }
+
+set devnull "/dev/null"
+if { [info exists ::env(OS)] && [string match "Windows*" $::env(OS)] } {
+    # Windows uses special file named "nul" as a substitute for 
/dev/null

+    set devnull "nul"
+}
+
  # Avoid possible influence from the make jobserver,
  # otherwise ltrans0.ltrans_args files may be missing.
  if [info exists env(MAKEFLAGS)] {
@@ -353,10 +360,10 @@ outest "$b-21 exe savetmp named2" $mult "-o 
$b.exe -save-temps" {} {{--1.i --1.s

  # Additional files are created when an @file is used
  if !$skip_atsave {
-outest "$b-22 exe savetmp namedb-2" $sing "@/dev/null -o $b.exe 
-save-temps" {} {{--0.i --0.s --0.o .args.0 !!$gld .ld1_args !0 .exe}}
-outest "$b-23 exe savetmp named2-2" $mult "@/dev/null -o $b.exe 
-save-temps" {} {{--1.i --1.s --1.o --2.i --2.s --2.o .args.0 !!$gld 
.ld1_args !0 .exe}}
-outest "$b-24 exe savetmp named2-3" $mult "@/dev/null -I dummy -o 
$b.exe -save-temps" {} {{--1.i --1.s --1.o --2.i --2.s --2.o -args.0 
-args.1 .args.2 !!$gld .ld1_args !0 .exe}}
-outest "$b-25 exe savetmp named2-4" $mult "@/dev/null -I dummy -L 
dummy -o $b.exe -save-temps" {} {{--1.i --1.s --1.o --2.i --2.s --2.o 
-args.0 -args.1 .args.2 .args.3 !!$gld .ld1_args !0 .exe}}
+outest "$b-22 exe savetmp namedb-2" $sing "@$devnull -o $b.exe 
-save-temps" {} {{--0.i --0.s --0.o .args.0 !!$gld .ld1_args !0 .exe}}
+outest "$b-23 exe savetmp named2-2" $mult "@$devnull -o $b.exe 
-save-temps" {} {{--1.i --1.s --1.o --2.i --2.s --2.o .args.0 !!$gld 
.ld1_args !0 .exe}}
+outest "$b-24 exe savetmp named2-3" $mult "@$devnull -I dummy -o 
$b.exe -save-temps" {} {{--1.i --1.s --1.o --2.i --2.s --2.o -args.0 
-args.1 .args.2 !!$gld .ld1_args !0 .exe}}
+outest "$b-25 exe savetmp named2-4" $mult "@$devnull -I dummy -L 
dummy -o $b.exe -save-temps" {} {{--1.i --1.s --1.o --2.i --2.s --2.o 
-args.0 -args.1 .args.2 .args.3 !!$gld .ld1_args !0 .exe}}

  }
  # Setting the main output to a dir selects it as the default aux
@@ -714,7 +721,7 @@ outest "$b-291 lto mult named-2" $mult "-o $b.exe 
-O2 -flto -fno-use-linker-plug
  outest "$b-292 lto sing nameddir-2" $sing "-o dir/$b.exe -O2 -flto 
-fno-use-linker-plugin -flto-partition=one -fdump-ipa-icf-optimized 
-fdump-rtl-final -fstack-usage" {dir/} {{--0.c.???i.icf 
--0.c.???r.final .wpa.???i.icf .ltrans0.ltrans.???r.final 
.ltrans0.ltrans.su .exe} {}}
  outest "$b-293 lto mult nameddir-2" $mult "-o dir/$b.exe -O2 -flto 
-fno-use-linker-plugin -flto-partition=one -fdump-ipa-icf-optimized 
-fdump-rtl-final -fstack-usage" {dir/} {{--1.c.???i.icf 
--1.c.???r.final --2.c.???i.icf --2.c.???r.final .wpa.???i.icf 
.ltrans0.ltrans.???r.final .ltrans0.ltrans.su .exe} {}}

  if !$skip_atsave {
-outest "$b-294 lto sing unnamed-3" $sing "@/dev/null -O2 -flto 
-fno-use-linker-plugin -flto-partition=one -fdump-ipa-icf-optimized 
-fdump-rtl-final -fstack-usage -save-temps $oaout" {} 
{{a--0.c.???i.icf a--0.c.???r.final a.wpa.???i.icf 
a.ltrans0.ltrans.???r.final a.ltrans0.ltrans.su a--0.o a--0.s a--0.i 
a.ltrans0.o a.ltrans.out a.ltrans0.ltrans.o a.ltrans0.ltrans_args 
a.args.0 a.ltrans0.ltrans.s a.wpa.args.0 a.lto_args a.ld1_args 
a.ltrans_args a.ltrans0.ltrans.args.0 a.ld_args $aout}}
+outest "$b-294 lto sing unnamed-3" $sing "@$devnull -O2 -flto 
-fno-use-linker-plugin -flto-partition=one -fdump-ipa-icf-optimized 
-fdump-rtl-final -fstack-usage -save-temps $oaout" {} 
{{a--0.c.???i.icf a--0.c.???r.final a.wpa.???i.icf 
a.ltrans0.ltrans.???r.final a.ltrans0.ltrans.su a--0.o a--0.s a--0.i 
a.ltrans0.o a.ltrans.out a.ltrans0.ltrans.o a.ltrans0.ltrans_args 
a.args.0 a.ltrans0.ltrans.s a.wpa.args.0 a.lto_args a.ld1_args 
a.ltrans_args a.ltrans0.ltrans.args.0 a.ld_args $aout}}

  }
  }


Thanks, looks good to me, will push to master soon.


Thanks for the review. I can push 

PING^1 [PATCH] testsuite: /dev/null is not accessible on Windows

2022-10-05 Thread Torbjorn SVENSSON via Gcc-patches

Hi,

Ping, https://gcc.gnu.org/pipermail/gcc-patches/2022-September/602534.html

Kind regards,
Torbjörn

On 2022-09-29 19:38, Torbjörn SVENSSON wrote:

When running the DejaGNU testsuite on a toolchain built for native
Windows, the path /dev/null can't be used to open a stream to void.
On native Windows, the resource is instead named "nul".

The error would look like this:
c:/arm-11.3.rel1/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe:
 cannot find @/dev/null: No such file or directory

Patch has been verified on Windows and Linux.

gcc/testsuite:

* gcc.misc-tests/outputs.exp: Use "@nul" for Windows,
"@/dev/null" for other environments.

Co-Authored-By: Yvan ROUX  
Signed-off-by: Torbjörn SVENSSON  
---
  gcc/testsuite/gcc.misc-tests/outputs.exp | 17 -
  1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/gcc/testsuite/gcc.misc-tests/outputs.exp 
b/gcc/testsuite/gcc.misc-tests/outputs.exp
index ab919db1ccb..3fe7270fa63 100644
--- a/gcc/testsuite/gcc.misc-tests/outputs.exp
+++ b/gcc/testsuite/gcc.misc-tests/outputs.exp
@@ -78,6 +78,13 @@ if {[board_info $dest exists output_format]} {
  append link_options " additional_flags=-Wl,-oformat,[board_info $dest 
output_format]"
  }
  
+

+set devnull "/dev/null"
+if { [info exists ::env(OS)] && [string match "Windows*" $::env(OS)] } {
+# Windows uses special file named "nul" as a substitute for /dev/null
+set devnull "nul"
+}
+
  # Avoid possible influence from the make jobserver,
  # otherwise ltrans0.ltrans_args files may be missing.
  if [info exists env(MAKEFLAGS)] {
@@ -353,10 +360,10 @@ outest "$b-21 exe savetmp named2" $mult "-o $b.exe 
-save-temps" {} {{--1.i --1.s
  
  # Additional files are created when an @file is used

  if !$skip_atsave {
-outest "$b-22 exe savetmp namedb-2" $sing "@/dev/null -o $b.exe -save-temps" 
{} {{--0.i --0.s --0.o .args.0 !!$gld .ld1_args !0 .exe}}
-outest "$b-23 exe savetmp named2-2" $mult "@/dev/null -o $b.exe -save-temps" 
{} {{--1.i --1.s --1.o --2.i --2.s --2.o .args.0 !!$gld .ld1_args !0 .exe}}
-outest "$b-24 exe savetmp named2-3" $mult "@/dev/null -I dummy -o $b.exe 
-save-temps" {} {{--1.i --1.s --1.o --2.i --2.s --2.o -args.0 -args.1 .args.2 !!$gld .ld1_args 
!0 .exe}}
-outest "$b-25 exe savetmp named2-4" $mult "@/dev/null -I dummy -L dummy -o $b.exe 
-save-temps" {} {{--1.i --1.s --1.o --2.i --2.s --2.o -args.0 -args.1 .args.2 .args.3 !!$gld 
.ld1_args !0 .exe}}
+outest "$b-22 exe savetmp namedb-2" $sing "@$devnull -o $b.exe -save-temps" {} 
{{--0.i --0.s --0.o .args.0 !!$gld .ld1_args !0 .exe}}
+outest "$b-23 exe savetmp named2-2" $mult "@$devnull -o $b.exe -save-temps" {} 
{{--1.i --1.s --1.o --2.i --2.s --2.o .args.0 !!$gld .ld1_args !0 .exe}}
+outest "$b-24 exe savetmp named2-3" $mult "@$devnull -I dummy -o $b.exe 
-save-temps" {} {{--1.i --1.s --1.o --2.i --2.s --2.o -args.0 -args.1 .args.2 !!$gld .ld1_args 
!0 .exe}}
+outest "$b-25 exe savetmp named2-4" $mult "@$devnull -I dummy -L dummy -o $b.exe 
-save-temps" {} {{--1.i --1.s --1.o --2.i --2.s --2.o -args.0 -args.1 .args.2 .args.3 !!$gld 
.ld1_args !0 .exe}}
  }
  
  # Setting the main output to a dir selects it as the default aux

@@ -714,7 +721,7 @@ outest "$b-291 lto mult named-2" $mult "-o $b.exe -O2 -flto 
-fno-use-linker-plug
  outest "$b-292 lto sing nameddir-2" $sing "-o dir/$b.exe -O2 -flto 
-fno-use-linker-plugin -flto-partition=one -fdump-ipa-icf-optimized -fdump-rtl-final 
-fstack-usage" {dir/} {{--0.c.???i.icf --0.c.???r.final .wpa.???i.icf 
.ltrans0.ltrans.???r.final .ltrans0.ltrans.su .exe} {}}
  outest "$b-293 lto mult nameddir-2" $mult "-o dir/$b.exe -O2 -flto 
-fno-use-linker-plugin -flto-partition=one -fdump-ipa-icf-optimized -fdump-rtl-final 
-fstack-usage" {dir/} {{--1.c.???i.icf --1.c.???r.final --2.c.???i.icf --2.c.???r.final 
.wpa.???i.icf .ltrans0.ltrans.???r.final .ltrans0.ltrans.su .exe} {}}
  if !$skip_atsave {
-outest "$b-294 lto sing unnamed-3" $sing "@/dev/null -O2 -flto 
-fno-use-linker-plugin -flto-partition=one -fdump-ipa-icf-optimized -fdump-rtl-final -fstack-usage 
-save-temps $oaout" {} {{a--0.c.???i.icf a--0.c.???r.final a.wpa.???i.icf 
a.ltrans0.ltrans.???r.final a.ltrans0.ltrans.su a--0.o a--0.s a--0.i a.ltrans0.o a.ltrans.out 
a.ltrans0.ltrans.o a.ltrans0.ltrans_args a.args.0 a.ltrans0.ltrans.s a.wpa.args.0 a.lto_args 
a.ld1_args a.ltrans_args a.ltrans0.ltrans.args.0 a.ld_args $aout}}
+outest "$b-294 lto sing unnamed-3" $sing "@$devnull -O2 -flto 
-fno-use-linker-plugin -flto-partition=one -fdump-ipa-icf-optimized -fdump-rtl-final -fstack-usage 
-save-temps $oaout" {} {{a--0.c.???i.icf a--0.c.???r.final a.wpa.???i.icf 
a.ltrans0.ltrans.???r.final a.ltrans0.ltrans.su a--0.o a--0.s a--0.i a.ltrans0.o a.ltrans.out 
a.ltrans0.ltrans.o a.ltrans0.ltrans_args a.args.0 a.ltrans0.ltrans.s a.wpa.args.0 a.lto_args 
a.ld1_args a.ltrans_args a.ltrans0.ltrans.args.0 a.ld_args $aout}}
  }
  }
  


PING^1 [PATCH] testsuite: Verify that module-mapper is available

2022-10-05 Thread Torbjorn SVENSSON via Gcc-patches

Hi,

Ping, https://gcc.gnu.org/pipermail/gcc-patches/2022-September/602111.html

Kind regards,
Torbjörn

On 2022-09-23 14:03, Torbjörn SVENSSON wrote:

For some test cases, it's required that the optional module mapper
"g++-mapper-server" is built. As the server is not required, the
test cases will fail if it can't be found.

gcc/testsuite/ChangeLog:

* lib/target-supports.exp (check_is_prog_name_available):
New.
* lib/target-supports-dg.exp
(dg-require-prog-name-available): New.
* g++.dg/modules/modules.exp: Verify avilability of module
mapper.

Signed-off-by: Torbjörn SVENSSON  
---
  gcc/testsuite/g++.dg/modules/modules.exp | 31 
  gcc/testsuite/lib/target-supports-dg.exp | 15 
  gcc/testsuite/lib/target-supports.exp| 15 
  3 files changed, 61 insertions(+)

diff --git a/gcc/testsuite/g++.dg/modules/modules.exp 
b/gcc/testsuite/g++.dg/modules/modules.exp
index afb323d0efd..4784803742a 100644
--- a/gcc/testsuite/g++.dg/modules/modules.exp
+++ b/gcc/testsuite/g++.dg/modules/modules.exp
@@ -279,6 +279,29 @@ proc module-init { src } {
  return $option_list
  }
  
+# Return 1 if requirements are met

+proc module-check-requirements { tests } {
+foreach test $tests {
+   set tmp [dg-get-options $test]
+   foreach op $tmp {
+   switch [lindex $op 0] {
+   "dg-additional-options" {
+   # Example strings to match:
+   # -fmodules-ts -fmodule-mapper=|@g++-mapper-server\\ -t\\ 
[srcdir]/inc-xlate-1.map
+   # -fmodules-ts -fmodule-mapper=|@g++-mapper-server
+   if [regexp -- {(^| )-fmodule-mapper=\|@([^\\ ]*)} [lindex 
$op 2] dummy dummy2 prog] {
+   verbose "Checking that mapper exist: $prog"
+   if { ![ check_is_prog_name_available $prog ] } {
+   return 0
+   }
+   }
+   }
+   }
+   }
+}
+return 1
+}
+
  # cleanup any detritus from previous run
  cleanup_module_files [find $DEFAULT_REPO *.gcm]
  
@@ -307,6 +330,14 @@ foreach src [lsort [find $srcdir/$subdir {*_a.[CHX}]] {

set tests [lsort [find [file dirname $src] \
  [regsub {_a.[CHX]$} [file tail $src] 
{_[a-z].[CHX]}]]]
  
+	if { ![module-check-requirements $tests] } {

+   set testcase [regsub {_a.[CH]} $src {}]
+   set testcase \
+   [string range $testcase [string length "$srcdir/"] end]
+   unsupported $testcase
+   continue
+   }
+
set std_list [module-init $src]
foreach std $std_list {
set mod_files {}
diff --git a/gcc/testsuite/lib/target-supports-dg.exp 
b/gcc/testsuite/lib/target-supports-dg.exp
index aa2164bc789..6ce3b2b1a1b 100644
--- a/gcc/testsuite/lib/target-supports-dg.exp
+++ b/gcc/testsuite/lib/target-supports-dg.exp
@@ -683,3 +683,18 @@ proc dg-require-symver { args } {
set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
  }
  }
+
+# If this target does not provide prog named "$args", skip this test.
+
+proc dg-require-prog-name-available { args } {
+# The args are within another list; pull them out.
+set args [lindex $args 0]
+
+set prog [lindex $args 1]
+
+if { ![ check_is_prog_name_available $prog ] } {
+upvar dg-do-what dg-do-what
+set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
+}
+}
+
diff --git a/gcc/testsuite/lib/target-supports.exp 
b/gcc/testsuite/lib/target-supports.exp
index 703aba412a6..c3b7a6c17b3 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -11928,3 +11928,18 @@ main:
.byte 0
} ""]
  }
+
+# Return 1 if this target has prog named "$prog", 0 otherwise.
+
+proc check_is_prog_name_available { prog } {
+global tool
+
+set options [list "additional_flags=-print-prog-name=$prog"]
+set output [lindex [${tool}_target_compile "" "" "none" $options] 0]
+
+if { $output == $prog } {
+return 0
+}
+
+return 1
+}


PING^1 [PATCH] testsuite: Windows reports errors with CreateProcess

2022-10-05 Thread Torbjorn SVENSSON via Gcc-patches

Hi,

Ping, https://gcc.gnu.org/pipermail/gcc-patches/2022-September/602541.html

Kind regards,
Torbjörn

On 2022-09-29 20:07, Torbjörn SVENSSON wrote:

When the mapper can't be executed, Windows report the error like:
.../bad-mapper-1.C: error: failed CreateProcess mapper 'this-will-not-work'

On Linux, the same error is reported this way:
.../bad-mapper-1.C: error: failed execvp mapper 'this-will-not-work'

This patch allows both output forms to be accepted.

Patch has been verified on Windows and Linux.

gcc/testsuite:

* g++.dg/modules/bad-mapper-1.C: Also accept CreateProcess.

Co-Authored-By: Yvan ROUX  
Signed-off-by: Torbjörn SVENSSON  
---
  gcc/testsuite/g++.dg/modules/bad-mapper-1.C | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/g++.dg/modules/bad-mapper-1.C 
b/gcc/testsuite/g++.dg/modules/bad-mapper-1.C
index 6d0ed4b5895..4b2312885d8 100644
--- a/gcc/testsuite/g++.dg/modules/bad-mapper-1.C
+++ b/gcc/testsuite/g++.dg/modules/bad-mapper-1.C
@@ -1,6 +1,6 @@
  //  { dg-additional-options "-fmodules-ts 
-fmodule-mapper=|this-will-not-work" }
  import unique1.bob;
-// { dg-error "-:failed exec.*mapper.* .*this-will-not-work" "" { target { ! { 
*-*-darwin[89]* *-*-darwin10* } } } 0 }
+// { dg-error "-:failed (exec|CreateProcess).*mapper.* .*this-will-not-work" 
"" { target { ! { *-*-darwin[89]* *-*-darwin10* } } } 0 }
  // { dg-prune-output "fatal error:" }
  // { dg-prune-output "failed to read" }
  // { dg-prune-output "compilation terminated" }


Re: [PATCH] testsuite: Windows paths use \ and not /

2022-10-01 Thread Torbjorn SVENSSON via Gcc-patches

Hi,

I'm really sorry for the mess.
I did test my patch, but I just looked for the PASS/FAIL for the excess 
errors and missed that there was an error with the pattern.
In the end, the patch that you pushed is much better. Thanks for fixing 
the issue in my absence.


Kind regards,
Torbjörn

On 2022-09-30 23:07, Jonathan Wakely wrote:

On Fri, 30 Sept 2022 at 19:13, Jonathan Wakely via Libstdc++
 wrote:


On Fri, 30 Sept 2022 at 19:07, Jonathan Wakely  wrote:


On Fri, 30 Sept 2022 at 19:04, Jonathan Wakely  wrote:


On Fri, 30 Sept 2022 at 18:55, Jakub Jelinek  wrote:


On Fri, Sep 30, 2022 at 06:47:07PM +0100, Jonathan Wakely via Gcc-patches wrote:

On Fri, 30 Sept 2022 at 17:26, Jonathan Wakely wrote:


On Fri, 30 Sept 2022 at 17:04, Torbjörn SVENSSON
 wrote:


libstdc++-v3/testsuite:

 * 20_util/bind/ref_neg.cc: Prune Windows paths too.


Please CC the libstdc++ for libstdc++ patches.

OK for trunk, thanks.


I'm seeing errors now on x86_64-linux:

ERROR: 20_util/bind/ref_neg.cc: unknown dg option: /\\ for "
dg-prune-output 53 "[/\\](functional|bits/invoke.h):" "

ERROR: 20_util/bind/ref_neg.cc: unknown dg option: /\\ for "
dg-prune-output 53 "[/\\](functional|bits/invoke.h):" "


Bet it should be
// { dg-prune-output "\[/\\](functional|bits\[/\\]invoke.h):" }
or so.  Completely untested.


That fixes the error, but now the regex doesn't match so there are
still excess errors. It needs to be:

// { dg-prune-output ".*\[/\\](functional|bits\[/\\]invoke.h):.*" }

Without any regex special characters, there's an implicit .* before
and after the pattern. But when you use any regex special characters
in the pattern, it stops working. I can't remember why. I figured it
out once.


It looks like just adding .* at the start is enough:

// { dg-prune-output ".*\[/\\](functional|bits\[/\\]invoke.h):" }

But that's so ugly, I'm tempted to replace that prune with something different.


I'll finish testing this and push it.


I committed this instead, with no .* in the pattern.


Re: PING^1 [PATCH] testsuite: 'b' instruction can't do long enough jumps

2022-09-28 Thread Torbjorn SVENSSON via Gcc-patches

Hi Christophe!

On 2022-09-28 13:55, Christophe Lyon wrote:

Hi!


On 9/28/22 11:17, Torbjorn SVENSSON via Gcc-patches wrote:

Hi,

Ping: 
https://gcc.gnu.org/pipermail/gcc-patches/2022-September/601829.html


Kind regards,
Torbjörn

On 2022-09-19 18:30, Torbjörn SVENSSON wrote:

After moving the testglue in commit 9d503515cee, the jump to exit and
abort is too far for the 'b' instruction on Cortex-M0. As most of the
I am not sure I understand why that commit changed the distance between 
'exit' and the branch instruction?


The change was that the gcc_tg.o (the DejaGNU testglue.c object file) is 
now put last on the command line. In the previous versions of GCC, it 
was put before the ldflags flag etc, so now the code is placed in a way 
that the distance might be too big.


This could also be related to that we in ST are using QEMU in system 
mode and not user mode and as a result, our test environment is slightly 
larger and might perhaps be placed in between the code for the test case 
and the testglue.



C code would generate a 'bl' instruction instead of a 'b'
instruction, lets do the same for the inline assembler.

The error seen without this patch:

/tmp/cccCRiCl.o: in function `main':
stack-protector-1.c:(.text+0x4e): relocation truncated to fit: 
R_ARM_THM_JUMP11 against symbol `__wrap_exit' defined in .text 
section in gcc_tg.o
stack-protector-1.c:(.text+0x50): relocation truncated to fit: 
R_ARM_THM_JUMP11 against symbol `__wrap_abort' defined in .text 
section in gcc_tg.o

collect2: error: ld returned 1 exit status

Anyway the change seems sensible to me, I suppose it's not worth adding 
support in the linker to insert long branch stubs for these relocations.


If a simple 'bl' instead of 'b' is enough, I think that this trivial 
change is the right one as the test case is supposed to test the stack 
protection, not branching, right?


Kind regards,
Torbjörn



Christophe


gcc/testsuite/ChangeLog:

 * gcc/testsuite/gcc.target/arm/stack-protector-1.c: Use 'bl'
instead of 'b' instruction.
* gcc/testsuite/gcc.target/arm/stack-protector-3.c: Likewise.

Co-Authored-By: Yvan ROUX  
Signed-off-by: Torbjörn SVENSSON  
---
  gcc/testsuite/gcc.target/arm/stack-protector-1.c | 4 ++--
  gcc/testsuite/gcc.target/arm/stack-protector-3.c | 2 +-
  2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/gcc.target/arm/stack-protector-1.c 
b/gcc/testsuite/gcc.target/arm/stack-protector-1.c

index 8d28b0a847c..3f0ffc9c3f3 100644
--- a/gcc/testsuite/gcc.target/arm/stack-protector-1.c
+++ b/gcc/testsuite/gcc.target/arm/stack-protector-1.c
@@ -56,8 +56,8 @@ asm (
  "    ldr    r1, [sp, #4]\n"
  CHECK (r1)
  "    mov    r0, #0\n"
-"    b    exit\n"
+"    bl    exit\n"
  "1:\n"
-"    b    abort\n"
+"    bl    abort\n"
  "    .size    main, .-main"
  );
diff --git a/gcc/testsuite/gcc.target/arm/stack-protector-3.c 
b/gcc/testsuite/gcc.target/arm/stack-protector-3.c

index b8f77fa2309..2f710529b8f 100644
--- a/gcc/testsuite/gcc.target/arm/stack-protector-3.c
+++ b/gcc/testsuite/gcc.target/arm/stack-protector-3.c
@@ -26,7 +26,7 @@ asm (
  "    .type    __stack_chk_fail, %function\n"
  "__stack_chk_fail:\n"
  "    movs    r0, #0\n"
-"    b    exit\n"
+"    bl    exit\n"
  "    .size    __stack_chk_fail, .-__stack_chk_fail"
  );


PING^1 [PATCH] testsuite: Do not prefix linker script with "-Wl,"

2022-09-28 Thread Torbjorn SVENSSON via Gcc-patches

Hi,

Ping: https://gcc.gnu.org/pipermail/gcc-patches/2022-September/601831.html

Kind regards,
Torbjörn

On 2022-09-19 18:57, Torbjörn SVENSSON wrote:

The linker script should not be prefixed with "-Wl," - it's not an
input file and does not interfere with the new dump output filename
strategy.

gcc/testsuite/ChangeLog:

* lib/gcc-defs.exp: Do not prefix linker script with "-Wl,".

Signed-off-by: Torbjörn SVENSSON  
---
  gcc/testsuite/lib/gcc-defs.exp | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/lib/gcc-defs.exp b/gcc/testsuite/lib/gcc-defs.exp
index 42ef1d85432..2102ed6f7a3 100644
--- a/gcc/testsuite/lib/gcc-defs.exp
+++ b/gcc/testsuite/lib/gcc-defs.exp
@@ -332,7 +332,7 @@ proc gcc_adjust_linker_flags_list { args } {
continue
} elseif { $skip != "" } then {
set skip ""
-   } elseif { $opt == "-Xlinker" } then {
+   } elseif { $opt == "-Xlinker" || $opt == "-T" } then {
set skip $opt
} elseif { ![string match "-*" $opt] \
   && [file isfile $opt] } {


PING^1 [PATCH] testsuite: 'b' instruction can't do long enough jumps

2022-09-28 Thread Torbjorn SVENSSON via Gcc-patches

Hi,

Ping: https://gcc.gnu.org/pipermail/gcc-patches/2022-September/601829.html

Kind regards,
Torbjörn

On 2022-09-19 18:30, Torbjörn SVENSSON wrote:

After moving the testglue in commit 9d503515cee, the jump to exit and
abort is too far for the 'b' instruction on Cortex-M0. As most of the
C code would generate a 'bl' instruction instead of a 'b'
instruction, lets do the same for the inline assembler.

The error seen without this patch:

/tmp/cccCRiCl.o: in function `main':
stack-protector-1.c:(.text+0x4e): relocation truncated to fit: R_ARM_THM_JUMP11 
against symbol `__wrap_exit' defined in .text section in gcc_tg.o
stack-protector-1.c:(.text+0x50): relocation truncated to fit: R_ARM_THM_JUMP11 
against symbol `__wrap_abort' defined in .text section in gcc_tg.o
collect2: error: ld returned 1 exit status

gcc/testsuite/ChangeLog:

 * gcc/testsuite/gcc.target/arm/stack-protector-1.c: Use 'bl'
instead of 'b' instruction.
* gcc/testsuite/gcc.target/arm/stack-protector-3.c: Likewise.

Co-Authored-By: Yvan ROUX  
Signed-off-by: Torbjörn SVENSSON  
---
  gcc/testsuite/gcc.target/arm/stack-protector-1.c | 4 ++--
  gcc/testsuite/gcc.target/arm/stack-protector-3.c | 2 +-
  2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/gcc.target/arm/stack-protector-1.c 
b/gcc/testsuite/gcc.target/arm/stack-protector-1.c
index 8d28b0a847c..3f0ffc9c3f3 100644
--- a/gcc/testsuite/gcc.target/arm/stack-protector-1.c
+++ b/gcc/testsuite/gcc.target/arm/stack-protector-1.c
@@ -56,8 +56,8 @@ asm (
  "ldr r1, [sp, #4]\n"
CHECK (r1)
  "mov r0, #0\n"
-" b   exit\n"
+" bl  exit\n"
  "1:\n"
-" b   abort\n"
+" bl  abort\n"
  ".size   main, .-main"
  );
diff --git a/gcc/testsuite/gcc.target/arm/stack-protector-3.c 
b/gcc/testsuite/gcc.target/arm/stack-protector-3.c
index b8f77fa2309..2f710529b8f 100644
--- a/gcc/testsuite/gcc.target/arm/stack-protector-3.c
+++ b/gcc/testsuite/gcc.target/arm/stack-protector-3.c
@@ -26,7 +26,7 @@ asm (
  ".type   __stack_chk_fail, %function\n"
  "__stack_chk_fail:\n"
  "movsr0, #0\n"
-" b   exit\n"
+" bl  exit\n"
  ".size   __stack_chk_fail, .-__stack_chk_fail"
  );
  


Re: [PATCH v2] testsuite: Only run test on target if VMA == LMA

2022-09-23 Thread Torbjorn SVENSSON via Gcc-patches

Hi Richard,

Thanks for your review.
Comments below.

On 2022-09-23 19:34, Richard Sandiford wrote:

Torbjörn SVENSSON via Gcc-patches  writes:

Checking that the triplet matches arm*-*-eabi (or msp430-*-*) is not
enough to know if the execution will enter an endless loop, or if it
will give a meaningful result. As the execution test only work when
VMA and LMA are equal, make sure that this condition is met.

2022-09-16  Torbjörn SVENSSON  

gcc/testsuite/ChangeLog:

* lib/target-supports.exp (check_effective_target_vma_equals_lma): New.
 * c-c++-common/torture/attr-noinit-1.c: Requre VMA == LMA to run.
 * c-c++-common/torture/attr-noinit-2.c: Likewise.
 * c-c++-common/torture/attr-noinit-3.c: Likewise.
 * c-c++-common/torture/attr-persistent-1.c: Likewise.
 * c-c++-common/torture/attr-persistent-3.c: Likewise.


Looks like a nice thing to have.

Could you add an entry to doc/sourcebuild.texi too?


I've added a note and will be shared in a v3.


+
+# Example output of objdump:
+#vma_equals_lma9059.exe: file format elf32-littlearm
+#
+#Sections:
+#Idx Name  Size  VMA   LMA   File off  Algn
+#  6 .data 0558  2000  08002658  0002  2**3
+#  CONTENTS, ALLOC, LOAD, DATA
+
+# Capture LMA and VMA columns for .data section
+if ![ regexp "\d*\d+\s+\.data\s+\d+\s+(\d+)\s+(\d+)" $output dummy 
vma lma ] {


Maybe my Tcl is getting rusty, but I'm surprised this quoting works.
I'd have expected single backslashes to be interpreted as C-style
sequences (for \n etc) and so be eaten before regexp sees them.
Quoting with {...} instead of "..." would avoid that.


Good catch! I'm not fluent in Tcl and apparently, I was not testing this 
well enough before sending it to the list. I got the expected result for 
the test cases, but for the wrong reason. I've correct it for the v3.



+verbose "Could not parse objdump output" 2
+return 0
+} else {
+return [string equal $vma $lma]
+}
+   } else {
+remote_file build delete $exe
+verbose "Could not determine if VMA is equal to LMA. Assuming not 
equal." 2
+return 0
+   }


Would it be more conservative to return 1 on failure rather than 0?
That way, a faulty test would trigger XFAILs rather than UNSUPPORTEDs,
with XFAILs being more likely to get attention.


The main issue here is that for targets where VMA != LMA, executing the 
tests will fall into an endless recursion loop. Well, "endless" in the 
sense that the stack might be depleted or the test will simply timeout. 
The test cases are designed to assume that it's safe to call _start() 
from within main() to verify that the state of some variables tagged 
with certain attributes are correct after a "reset".



On the other hand, I suppose we don't lose much if these tests are
run on common targets only.  So either way is OK, just asking. ;-)


Do you think it's worth to have these tests reach the timeout to have 
them in the XFAIL list rather than in the UNSUPPORTED list?
Keep in mind that it's not just one test case, it's 5 test cases times 
the number of permutations of the CFLAGS...
It's also not expected that these test cases will be changed in a way 
that will make them work when VMA != LMA.


Kind regards,
Torbjörn


Re: [PATCH] testsuite: Sanitize fails for SP FPU on Arm

2022-09-23 Thread Torbjorn SVENSSON via Gcc-patches

Hi Joseph,

On 2022-09-23 00:42, Joseph Myers wrote:

On Thu, 22 Sep 2022, Torbjörn SVENSSON via Gcc-patches wrote:


This patch stops reporting fails for Arm targets with single
precision floating point unit for types wider than 32 bits (the width
of float on arm-none-eabi).

As reported in PR102017, fenv is reported as supported in recent
versions of newlib. At the same time, for some Arm targets, the
implementation in libgcc does not support exceptions and thus, the
test fails with a call to abort().


It's definitely wrong to have this sort of Arm-specific conditional in
architecture-independent tests.  Tests requiring floating-point exceptions
support should have an appropriate dg-require-effective-target; if that
dg-require-effective-target wrongly passes in certain configurations, fix
it (or e.g. add a new check_effective_target_fenv_exceptions_double to
verify that exceptions work for double, as opposed to the present
check_effective_target_fenv_exceptions which checks whether exceptions
work for float, and then adjust tests requiring exceptions for double to
use the new effective-target).



Okay, thanks for your review.
I will split this test case into 3 files as for SP FPU, we would like to 
verify that the exception handling for the float part work, but at the 
same time we know that exception handling for double and long double 
should not work.
Do you think it's preferable to have the double and long double should 
be reported as UNSUPPORRTED, or as XFAIL for the SP FPU case?


Re: [PATCH] testsuite: Disable zero-scratch-regs-{7, 9, 11}.c on arm

2022-09-16 Thread Torbjorn SVENSSON via Gcc-patches

Hi all,

Appears that this is just a problem for gcc11 (and perhaps gcc12?). 
Master already has the needed implementation, so the patch below is not 
needed.


Sorry for the buzz.

Kind regards,
Torbjörn

On 2022-09-15 08:54, Torbjörn SVENSSON wrote:

-fzero-call-used-regs=all and -fzero-call-used-regs=all-gpr are not
supported on arm*. On arm-none-eabi, the testcases fails with:

   sorry, unimplemented: '-fzero-call-used-regs' not supported on this target

2022-09-15  Torbjörn SVENSSON  

gcc/testsuite/ChangeLog:

* c-c++-common/zero-scratch-regs-7.c: Skip on arm.
* c-c++-common/zero-scratch-regs-9.c: Likewise.
* c-c++-common/zero-scratch-regs-11.c: Likewise.

Co-Authored-By: Yvan ROUX  
Signed-off-by: Torbjörn SVENSSON  
---
  gcc/testsuite/c-c++-common/zero-scratch-regs-11.c | 2 +-
  gcc/testsuite/c-c++-common/zero-scratch-regs-7.c  | 1 +
  gcc/testsuite/c-c++-common/zero-scratch-regs-9.c  | 2 +-
  3 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/c-c++-common/zero-scratch-regs-11.c 
b/gcc/testsuite/c-c++-common/zero-scratch-regs-11.c
index b7739b2c6f6..6fd2a1dc382 100644
--- a/gcc/testsuite/c-c++-common/zero-scratch-regs-11.c
+++ b/gcc/testsuite/c-c++-common/zero-scratch-regs-11.c
@@ -1,5 +1,5 @@
  /* { dg-do run } */
-/* { dg-skip-if "not implemented" { ! { i?86*-*-* x86_64*-*-* sparc*-*-* 
aarch64*-*-* arm*-*-* nvptx*-*-* s390*-*-* loongarch64*-*-* } } } */
+/* { dg-skip-if "not implemented" { ! { i?86*-*-* x86_64*-*-* sparc*-*-* 
aarch64*-*-* nvptx*-*-* s390*-*-* loongarch64*-*-* } } } */
  /* { dg-options "-O2 -fzero-call-used-regs=all" } */
  
  #include "zero-scratch-regs-10.c"

diff --git a/gcc/testsuite/c-c++-common/zero-scratch-regs-7.c 
b/gcc/testsuite/c-c++-common/zero-scratch-regs-7.c
index 2a4c8b2e73d..c684b4a02f9 100644
--- a/gcc/testsuite/c-c++-common/zero-scratch-regs-7.c
+++ b/gcc/testsuite/c-c++-common/zero-scratch-regs-7.c
@@ -1,5 +1,6 @@
  /* { dg-do run } */
  /* { dg-skip-if "not implemented" { ia64*-*-* } } */
+/* { dg-skip-if "not implemented" { arm*-*-* } } */
  /* { dg-options "-O2 -fzero-call-used-regs=all-gpr" } */
  
  #include "zero-scratch-regs-1.c"

diff --git a/gcc/testsuite/c-c++-common/zero-scratch-regs-9.c 
b/gcc/testsuite/c-c++-common/zero-scratch-regs-9.c
index ea83bc146b7..0e8922053e8 100644
--- a/gcc/testsuite/c-c++-common/zero-scratch-regs-9.c
+++ b/gcc/testsuite/c-c++-common/zero-scratch-regs-9.c
@@ -1,5 +1,5 @@
  /* { dg-do run } */
-/* { dg-skip-if "not implemented" { ! { i?86*-*-* x86_64*-*-* sparc*-*-* 
aarch64*-*-* arm*-*-* nvptx*-*-* s390*-*-* loongarch64*-*-* } } } */
+/* { dg-skip-if "not implemented" { ! { i?86*-*-* x86_64*-*-* sparc*-*-* 
aarch64*-*-* nvptx*-*-* s390*-*-* loongarch64*-*-* } } } */
  /* { dg-options "-O2 -fzero-call-used-regs=all" } */
  
  #include "zero-scratch-regs-1.c"


Re: [PATCH v2] gcov: Respect triplet when looking for gcov

2022-09-12 Thread Torbjorn SVENSSON via Gcc-patches

On 2022-09-12 10:40, Martin Liška wrote:

On 9/12/22 09:06, Torbjorn SVENSSON via Gcc-patches wrote:



On 2022-09-11 21:38, Mikael Morin wrote:

Le 11/09/2022 à 18:04, Torbjorn SVENSSON a écrit :

Can you fix it for me and submit it or do you want me to send a v3?


For trivial things like this, there is no need for a v3 (nor was there for a 
v2).
Do you miss a git write account and need someone to push for you?


Ok!

I do not have any write access, so yes, please push it for me!


Please attach a patch with git format-patch and I'm going to push it now.

Cheers,
Martin


Patch attached as requested.From 0400f4b34a62ad5a54e87c537b4a41bc630fd105 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Torbj=C3=B6rn=20SVENSSON?= 
Date: Fri, 9 Sep 2022 12:19:27 +0200
Subject: [PATCH] gcov: Respect triplet when looking for gcov
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

When testing a cross toolchain outside the build tree, the binary name
for gcov is prefixed with the triplet.

gcc/testsuite/ChangeLog:

* g++.dg/gcov/gcov.exp: Respect triplet when looking for gcov.
* gcc.misc-tests/gcov.exp: Likewise.

Signed-off-by: Torbjörn SVENSSON 
---
 gcc/testsuite/g++.dg/gcov/gcov.exp| 4 ++--
 gcc/testsuite/gcc.misc-tests/gcov.exp | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/g++.dg/gcov/gcov.exp 
b/gcc/testsuite/g++.dg/gcov/gcov.exp
index 88acd95c361..04e7a016486 100644
--- a/gcc/testsuite/g++.dg/gcov/gcov.exp
+++ b/gcc/testsuite/g++.dg/gcov/gcov.exp
@@ -24,9 +24,9 @@ global GXX_UNDER_TEST
 
 # Find gcov in the same directory as $GXX_UNDER_TEST.
 if { ![is_remote host] && [string match "*/*" [lindex $GXX_UNDER_TEST 0]] } {
-set GCOV [file dirname [lindex $GXX_UNDER_TEST 0]]/gcov
+set GCOV [file dirname [lindex $GXX_UNDER_TEST 0]]/[transform gcov]
 } else {
-set GCOV gcov
+set GCOV [transform gcov]
 }
 
 # Initialize harness.
diff --git a/gcc/testsuite/gcc.misc-tests/gcov.exp 
b/gcc/testsuite/gcc.misc-tests/gcov.exp
index 82376d90ac2..b8e9661aa53 100644
--- a/gcc/testsuite/gcc.misc-tests/gcov.exp
+++ b/gcc/testsuite/gcc.misc-tests/gcov.exp
@@ -24,9 +24,9 @@ global GCC_UNDER_TEST
 
 # For now find gcov in the same directory as $GCC_UNDER_TEST.
 if { ![is_remote host] && [string match "*/*" [lindex $GCC_UNDER_TEST 0]] } {
-set GCOV [file dirname [lindex $GCC_UNDER_TEST 0]]/gcov
+set GCOV [file dirname [lindex $GCC_UNDER_TEST 0]]/[transform gcov]
 } else {
-set GCOV gcov
+set GCOV [transform gcov]
 }
 
 # Initialize harness.
-- 
2.25.1



Re: [PATCH v2] gcov: Respect triplet when looking for gcov

2022-09-12 Thread Torbjorn SVENSSON via Gcc-patches




On 2022-09-11 21:38, Mikael Morin wrote:

Le 11/09/2022 à 18:04, Torbjorn SVENSSON a écrit :

Can you fix it for me and submit it or do you want me to send a v3?


For trivial things like this, there is no need for a v3 (nor was there 
for a v2).

Do you miss a git write account and need someone to push for you?


Ok!

I do not have any write access, so yes, please push it for me!


Re: [PATCH v2] gcov: Respect triplet when looking for gcov

2022-09-11 Thread Torbjorn SVENSSON via Gcc-patches

Hi,

On 2022-09-11 16:34, Mikael Morin wrote:

Hello,

diff --git a/gcc/testsuite/gcc.misc-tests/gcov.exp 
b/gcc/testsuite/gcc.misc-tests/gcov.exp

index 82376d90ac2..a55ce234f6e 100644
--- a/gcc/testsuite/gcc.misc-tests/gcov.exp
+++ b/gcc/testsuite/gcc.misc-tests/gcov.exp
@@ -24,9 +24,9 @@ global GCC_UNDER_TEST

  (...)

  } else {
-    set GCOV gcov
+    set GCOV {transform gcov]


Typo: I guess the opening curly bracket '{' should be a square one '['?


Yes. Apparently I was too stressed when preparing this patch. Can you 
fix it for me and submit it or do you want me to send a v3?


Re: [PATCH] Added information about inline assembler in stack calculations (.su files)

2018-11-27 Thread Torbjorn SVENSSON
Hi!

Thanks for the feedback.
Attached is an updated patch where I switched to the NOP define instead.
I'm not sure if stack-usage-naked.c should be moved to gcc.dg-tree, or 
if it should skip using the nop.h file (it feels wrong to do #include 
"../../gcc.dg/nop.h" from within gcc.taget-tree).

Torbjörn

On 27/11/2018 19:40, Segher Boessenkool wrote:
> Hi!
>
> On Mon, Nov 26, 2018 at 02:02:49PM +, Torbjorn SVENSSON wrote:
>> Attached is a small patch that, in case of inline assembler code,
>> indicates that the function stack usage is uncertain due to inline
>> assembler.
>>
>> The test suite are using "nop" as an assembler instruction on all
>> targets, is this acceptable or is there a better way to test this?
> Maybe see testsuite/gcc.dg/nop.h ?
>
>
> Segher

From e8af10ab24c7e095604b16206c0bd544e8699b93 Mon Sep 17 00:00:00 2001
From: Niklas DAHLQUIST 
Date: Fri, 9 Nov 2018 18:48:34 +0100
Subject: [PATCH] Added information about inline assembler in stack
 calculations

The stack usage calculation in GCC ignores any possible stack usage that
any inline assembly might contribute, and this is not reflected in the
.su file currently.

Since inline assembly will add to the uncertainty of the actual stack
usage for a function, this should be shown in the .su file as well.

This changeset will add "ignoring_inline_assembly" to the .su-file "type"
information of functions containing inline assembly.

The resulting stack usage type for functions containing inline assembly
will be according to the following table:

Static | Dynamic | Inline asm() | Resulting stack usage type

*  | 0   | False| static
*  | 0   | True | static,ignoring_inline_assembler
*  | 0 < x   | False| dynamic
*  | 0 < x   | True | dynamic,ignoring_inline_assembler
*  | 0 < x < MAX | False| dynamic,bounded
*  | 0 < x < MAX | True | dynamic,bounded,ignoring_inline_assembler

Added test case for ignore inline assembler in stack analysis files (.su)

Signed-off-by: Niklas DAHLQUIST 

diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 38e27a50a1e..e61ddc3260b 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -6456,7 +6456,7 @@ Warn if the stack usage of a function might exceed @var{byte-size}.
 The computation done to determine the stack usage is conservative.
 Any space allocated via @code{alloca}, variable-length arrays, or related
 constructs is included by the compiler when determining whether or not to
-issue a warning.
+issue a warning. @code{asm} statements are ignored when computing stack usage.
 
 The message is in keeping with the output of @option{-fstack-usage}.
 
diff --git a/gcc/function.c b/gcc/function.c
index 69523c1d723..197f80c0df3 100644
--- a/gcc/function.c
+++ b/gcc/function.c
@@ -1822,6 +1822,10 @@ instantiate_virtual_regs_in_insn (rtx_insn *insn)
 
   if (asm_noperands (PATTERN (insn)) >= 0)
 {
+   if (flag_stack_usage_info)
+	 {
+	   current_function_has_inline_assembler = 1;
+	 }
   if (!check_asm_operands (PATTERN (insn)))
 	{
 	  error_for_asm (insn, "impossible constraint in %");
diff --git a/gcc/function.h b/gcc/function.h
index 7e59050e8a6..8c3ef49e866 100644
--- a/gcc/function.h
+++ b/gcc/function.h
@@ -208,11 +208,16 @@ struct GTY(()) stack_usage
   /* Nonzero if the amount of stack space allocated dynamically cannot
  be bounded at compile-time.  */
   unsigned int has_unbounded_dynamic_stack_size : 1;
+
+  /* NonZero if body contains asm statement (ignored in stack calculations) */
+  unsigned int has_inline_assembler: 1;
 };
 
 #define current_function_static_stack_size (cfun->su->static_stack_size)
 #define current_function_dynamic_stack_size (cfun->su->dynamic_stack_size)
 #define current_function_pushed_stack_size (cfun->su->pushed_stack_size)
+#define current_function_has_inline_assembler \
+  (cfun->su->has_inline_assembler)
 #define current_function_has_unbounded_dynamic_stack_size \
   (cfun->su->has_unbounded_dynamic_stack_size)
 #define current_function_allocates_dynamic_stack_space\
diff --git a/gcc/testsuite/gcc.dg/stack-usage-3.c b/gcc/testsuite/gcc.dg/stack-usage-3.c
new file mode 100644
index 000..ccb935f358e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/stack-usage-3.c
@@ -0,0 +1,24 @@
+/* { dg-do compile } */
+/* { dg-options "-fstack-usage" } */
+/* nvptx doesn't have a reg allocator, and hence no stack usage data.  */
+/* { dg-skip-if "" { nvptx-*-* } { "*" } { "" } } */
+
+#include "nop.h"
+
+void foo()
+{
+int i;
+i = 1;
+}
+
+void bar()
+{
+int i;
+i = 1;
+asm(NOP);
+}
+
+/* { dg-final { scan-stack-usage "foo\t\[1-9\]\[0-9\]*\tstatic" } } */
+/* { 

[PATCH] Added information about inline assembler in stack calculations (.su files)

2018-11-26 Thread Torbjorn SVENSSON
Hi,

Attached is a small patch that, in case of inline assembler code, 
indicates that the function stack usage is uncertain due to inline 
assembler.

The test suite are using "nop" as an assembler instruction on all 
targets, is this acceptable or is there a better way to test this?

Patch has been tested on gcc-arm-none-eabi-7-2018-q2-update for both 
arm-none-eabi and x86_64-linux-gnu and SVN head (r266454) for 
x86_64-linux-gnu.

Thanks,
Torbjörn, Samuel and Niklas






From c7149f9be7c408c6355e085d0d2d6700b9938d08 Mon Sep 17 00:00:00 2001
From: Niklas DAHLQUIST 
Date: Fri, 9 Nov 2018 18:48:34 +0100
Subject: [PATCH] Added information about inline assembler in stack
 calculations

The stack usage calculation in GCC ignores any possible stack usage that
any inline assembly might contribute, and this is not reflected in the
.su file currently.

Since inline assembly will add to the uncertainty of the actual stack
usage for a function, this should be shown in the .su file as well.

This changeset will add "ignoring_inline_assembly" to the .su-file "type"
information of functions containing inline assembly.

The resulting stack usage type for functions containing inline assembly
will be according to the following table:

Static | Dynamic | Inline asm() | Resulting stack usage type

*  | 0   | False| static
*  | 0   | True | static,ignoring_inline_assembler
*  | 0 < x   | False| dynamic
*  | 0 < x   | True | dynamic,ignoring_inline_assembler
*  | 0 < x < MAX | False| dynamic,bounded
*  | 0 < x < MAX | True | dynamic,bounded,ignoring_inline_assembler

Added test case for ignore inline assembler in stack analysis files (.su)

Signed-off-by: Niklas DAHLQUIST 

diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 38e27a50a1e..e61ddc3260b 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -6456,7 +6456,7 @@ Warn if the stack usage of a function might exceed @var{byte-size}.
 The computation done to determine the stack usage is conservative.
 Any space allocated via @code{alloca}, variable-length arrays, or related
 constructs is included by the compiler when determining whether or not to
-issue a warning.
+issue a warning. @code{asm} statements are ignored when computing stack usage.
 
 The message is in keeping with the output of @option{-fstack-usage}.
 
diff --git a/gcc/function.c b/gcc/function.c
index 69523c1d723..197f80c0df3 100644
--- a/gcc/function.c
+++ b/gcc/function.c
@@ -1822,6 +1822,10 @@ instantiate_virtual_regs_in_insn (rtx_insn *insn)
 
   if (asm_noperands (PATTERN (insn)) >= 0)
 {
+   if (flag_stack_usage_info)
+	 {
+	   current_function_has_inline_assembler = 1;
+	 }
   if (!check_asm_operands (PATTERN (insn)))
 	{
 	  error_for_asm (insn, "impossible constraint in %");
diff --git a/gcc/function.h b/gcc/function.h
index 7e59050e8a6..8c3ef49e866 100644
--- a/gcc/function.h
+++ b/gcc/function.h
@@ -208,11 +208,16 @@ struct GTY(()) stack_usage
   /* Nonzero if the amount of stack space allocated dynamically cannot
  be bounded at compile-time.  */
   unsigned int has_unbounded_dynamic_stack_size : 1;
+
+  /* NonZero if body contains asm statement (ignored in stack calculations) */
+  unsigned int has_inline_assembler: 1;
 };
 
 #define current_function_static_stack_size (cfun->su->static_stack_size)
 #define current_function_dynamic_stack_size (cfun->su->dynamic_stack_size)
 #define current_function_pushed_stack_size (cfun->su->pushed_stack_size)
+#define current_function_has_inline_assembler \
+  (cfun->su->has_inline_assembler)
 #define current_function_has_unbounded_dynamic_stack_size \
   (cfun->su->has_unbounded_dynamic_stack_size)
 #define current_function_allocates_dynamic_stack_space\
diff --git a/gcc/testsuite/gcc.dg/stack-usage-3.c b/gcc/testsuite/gcc.dg/stack-usage-3.c
new file mode 100644
index 000..dfd92058a40
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/stack-usage-3.c
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+/* { dg-options "-fstack-usage" } */
+/* nvptx doesn't have a reg allocator, and hence no stack usage data.  */
+/* { dg-skip-if "" { nvptx-*-* } { "*" } { "" } } */
+
+void foo()
+{
+int i;
+i = 1;
+}
+
+void bar()
+{
+int i;
+i = 1;
+asm("nop");
+}
+
+/* { dg-final { scan-stack-usage "foo\t\[1-9\]\[0-9\]*\tstatic" } } */
+/* { dg-final { scan-stack-usage "bar\t\[1-9\]\[0-9\]*\tstatic,ignoring_inline_asm" } } */
+/* { dg-final { cleanup-stack-usage } } */
+
diff --git a/gcc/testsuite/gcc.dg/stack-usage-4.c b/gcc/testsuite/gcc.dg/stack-usage-4.c
new file mode 100644
index 000..6f0065006ec
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/stack-usage-4.c
@@ -0,0 +1,25 @@
+/* { dg-do compile } */
+/* { dg-options "-fstack-usage" } */
+/* nvptx doesn't have a reg allocator, and hence no stack usage data.  */
+/* { dg-skip-if "" { nvptx-*-* } { "*" } { ""