public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Christophe Lyon <christophe.lyon@linaro.org>
To: Christophe Lyon via Gcc-patches <gcc-patches@gcc.gnu.org>,
	Christophe Lyon <christophe.lyon@linaro.org>,
	 Richard Sandiford <richard.sandiford@arm.com>
Subject: Re: [testsuite][arm] Fix cmse-15.c expected output
Date: Wed, 8 Apr 2020 20:29:39 +0200	[thread overview]
Message-ID: <CAKdteOahhp58TDqRjuMUfY=xZ2EwNmL=hRJVcqQ+45G5U3_-TQ@mail.gmail.com> (raw)
In-Reply-To: <mptwo6qqpf5.fsf@arm.com>

[-- Attachment #1: Type: text/plain, Size: 2051 bytes --]

On Wed, 8 Apr 2020 at 11:48, Richard Sandiford
<richard.sandiford@arm.com> wrote:
>
> Christophe Lyon via Gcc-patches <gcc-patches@gcc.gnu.org> writes:
> > Hi,
> >
> > While checking Martin's fix for PR ipa/94445, he made me realize that
> > the cmse-15.c testcase still fails at -Os because ICF means that we
> > generate
> > nonsecure2:
> >         b       nonsecure0
> >
> > which is OK, but does not match the currently expected
> > nonsecure2:
> > ...
> >         bl      __gnu_cmse_nonsecure_call
> >
> > (see https://gcc.gnu.org/pipermail/gcc-patches/2020-April/543190.html)
> >
> > The test has already different expectations for v8-M and v8.1-M.
> >
> > I've decided to try to use check-function-bodies to account for the
> > different possibilities:
> > - v8-M vs v8.1-M via two different prefixes
> > - code generation variants (-0?) via multiple regexps
> >
> > I've tested that the test now passes with --target-board=-march=armv8-m.main
> > and --target-board=-march=armv8.1-m.main.
> >
> > I feel this a bit too much of a burden for the purpose, maybe there's
> > a better way of handling all these alternatives (in particular,
> > there's a lot of duplication since the expected code for the secure*
> > functions is the same for v8-M and v8.1-M).
>
> FWIW, an alternative is to give multiple versions with the same prefix
> and use { target ... } to select between them.  E.g.:
>
> /*
> ** foo:   { target a }
> **      ...
> */
> /*
> ** foo:   { target { ! a } }
> **      ...
> */
>

Ha indeed, that makes it simpler. Thanks for the example, I hadn't
fully understand how to use that scheme: I tried to add a third
alternative (different prefix) with no selector for cases where no
distinction was needed, but I realized that all alternatives need
their full matching description.

However, {target { ! a } } does not work as is, so the attached patch
uses a non-greedy regexp to avoid trying "! a }" instead of "target {
! a }"

If OK, maybe I should commit that as two separate patches?

Thanks

Christophe


> Thanks,
> Richard

[-- Attachment #2: cmse-15-function-bodies-v2.patch.txt --]
[-- Type: text/plain, Size: 4096 bytes --]

diff --git a/gcc/testsuite/gcc.target/arm/cmse/cmse-15.c b/gcc/testsuite/gcc.target/arm/cmse/cmse-15.c
index 0e37b50..b0fefe5 100644
--- a/gcc/testsuite/gcc.target/arm/cmse/cmse-15.c
+++ b/gcc/testsuite/gcc.target/arm/cmse/cmse-15.c
@@ -1,5 +1,8 @@
 /* { dg-do compile } */
 /* { dg-options "-mcmse" } */
+/* ARMv8-M expectation with target { ! arm_cmse_clear_ok }.  */
+/* ARMv8.1-M expectation with target arm_cmse_clear_ok.  */
+/* { dg-final { check-function-bodies "**" "" "" } } */
 
 int __attribute__ ((cmse_nonsecure_call)) (*ns_foo) (void);
 int (*s_bar) (void);
@@ -11,67 +14,204 @@ typedef int s_bar_t (void);
 typedef int __attribute__ ((cmse_nonsecure_call)) (* ns_foo_ptr) (void);
 typedef int (*s_bar_ptr) (void);
 
+/*
+** nonsecure0:  { target arm_cmse_clear_ok }
+**	...
+**	blxns	r[0-3]
+**	...
+*/
+/*
+** nonsecure0: { target { ! arm_cmse_clear_ok } }
+**	...
+**	bl	__gnu_cmse_nonsecure_call
+**	...
+*/
 int nonsecure0 (ns_foo_t * ns_foo_p)
 {
   return ns_foo_p ();
 }
 
+/*
+** nonsecure1:  { target arm_cmse_clear_ok }
+**	...
+**	blxns	r[0-3]
+**	...
+*/
+/*
+** nonsecure1: { target { ! arm_cmse_clear_ok } }
+**	...
+**	bl	__gnu_cmse_nonsecure_call
+**	...
+*/
 int nonsecure1 (ns_foo_t ** ns_foo_p)
 {
   return (*ns_foo_p) ();
 }
 
+/*
+** nonsecure2:  { target arm_cmse_clear_ok }
+**	...
+** (
+**	blxns	r[0-3]
+** |
+**	b	nonsecure0
+** )
+**	...
+*/
+/*
+** nonsecure2: { target { ! arm_cmse_clear_ok } }
+**	...
+** (
+**	bl	__gnu_cmse_nonsecure_call
+** |
+**	b	nonsecure0
+** )
+**	...
+*/
 int nonsecure2 (ns_foo_ptr ns_foo_p)
 {
   return ns_foo_p ();
 }
+
+/*
+** nonsecure3:  { target arm_cmse_clear_ok }
+**	...
+**	blxns	r[0-3]
+**	...
+*/
+/*
+** nonsecure3: { target { ! arm_cmse_clear_ok } }
+**	...
+**	bl	__gnu_cmse_nonsecure_call
+**	...
+*/
 int nonsecure3 (ns_foo_ptr * ns_foo_p)
 {
   return (*ns_foo_p) ();
 }
 
+/*
+** secure0:
+**	...
+** (
+**	bx	r[0-3]
+** |
+**	blx	r[0-3]
+** )
+**	...
+*/
 int secure0 (s_bar_t * s_bar_p)
 {
   return s_bar_p ();
 }
 
+/*
+** secure1:
+**	...
+** (
+**	bx	r[0-3]
+** |
+**	blx	r[0-3]
+** )
+**	...
+*/
 int secure1 (s_bar_t ** s_bar_p)
 {
   return (*s_bar_p) ();
 }
 
+/*
+** secure2:
+**	...
+** (
+**	bx	r[0-3]
+** |
+**	blx	r[0-3]
+** |
+**	b	secure0
+** )
+**	...
+*/
 int secure2 (s_bar_ptr s_bar_p)
 {
   return s_bar_p ();
 }
 
+/*
+** secure3:
+**	...
+** (
+**	bx	r[0-3]
+** |
+**	blx	r[0-3]
+** )
+**	...
+*/
 int secure3 (s_bar_ptr * s_bar_p)
 {
   return (*s_bar_p) ();
 }
 
+/*
+** nonsecure4:  { target arm_cmse_clear_ok }
+**	...
+**	blxns	r[0-3]
+**	...
+*/
+/*
+** nonsecure4: { target { ! arm_cmse_clear_ok } }
+**	...
+**	bl	__gnu_cmse_nonsecure_call
+**	...
+*/
 int nonsecure4 (void)
 {
   return ns_foo ();
 }
 
+/*
+** nonsecure5:  { target arm_cmse_clear_ok }
+**	...
+**	blxns	r[0-3]
+**	...
+*/
+/*
+** nonsecure5: { target { ! arm_cmse_clear_ok } }
+**	...
+**	bl	__gnu_cmse_nonsecure_call
+**	...
+*/
 int nonsecure5 (void)
 {
   return (*ns_foo2) ();
 }
 
+/*
+** secure4:
+**	...
+** (
+**	bx	r[0-3]
+** |
+**	blx	r[0-3]
+** )
+**	...
+*/
 int secure4 (void)
 {
   return s_bar ();
 }
 
+/*
+** secure5:
+**	...
+** (
+**	bx	r[0-3]
+** |
+**	blx	r[0-3]
+** )
+**	...
+*/
 int secure5 (void)
 {
   return (*s_bar2) ();
 }
-
-/* ARMv8-M expectation.  */
-/* { dg-final { scan-assembler-times "bl\\s+__gnu_cmse_nonsecure_call" 6 { target { ! arm_cmse_clear_ok } } } } */
-
-/* ARMv8.1-M expectation.  */
-/* { dg-final { scan-assembler-times "blxns" 6 { target arm_cmse_clear_ok } } } */
diff --git a/gcc/testsuite/lib/scanasm.exp b/gcc/testsuite/lib/scanasm.exp
index f7d2773..0098c3d 100644
--- a/gcc/testsuite/lib/scanasm.exp
+++ b/gcc/testsuite/lib/scanasm.exp
@@ -679,7 +679,7 @@ proc check-function-bodies { args } {
 	if { [string equal -length $prefix_len $line $prefix] } {
 	    set line [string trim [string range $line $prefix_len end]]
 	    if { !$in_function } {
-		if { [regexp "^(.*\\S)\\s+{(.*)}\$" $line dummy \
+		if { [regexp "^(.*?\\S)\\s+{(.*)}\$" $line dummy \
 			  line selector] } {
 		    set selector [dg-process-target $selector]
 		} else {

[-- Attachment #3: cmse-15-function-bodies-v2.chglog.txt --]
[-- Type: text/plain, Size: 251 bytes --]

gcc/testsuite/ChangeLog:

2020-04-08  Christophe Lyon  <christophe.lyon@linaro.org>

	* gcc.target/arm/cmse/cmse-15.c: Use check-function-bodies.
	* lib/scanasm.exp (check-function-bodies): Use non-greedy regexp
	when extracting the target selector.


  reply	other threads:[~2020-04-08 18:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-06 15:12 Christophe Lyon
2020-04-07 10:31 ` Andre Vieira (lists)
2020-04-07 10:54   ` Christophe Lyon
2020-04-08  9:47 ` Richard Sandiford
2020-04-08 18:29   ` Christophe Lyon [this message]
2020-04-09 10:57     ` Richard Sandiford

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAKdteOahhp58TDqRjuMUfY=xZ2EwNmL=hRJVcqQ+45G5U3_-TQ@mail.gmail.com' \
    --to=christophe.lyon@linaro.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=richard.sandiford@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).