public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] RISC-V: Raise error on unexpected ISA string at end.
@ 2019-07-31 11:21 Maxim Blinov
  2019-07-31 16:24 ` Martin Sebor
  2019-07-31 16:48 ` [PATCH v2] " Maxim Blinov
  0 siblings, 2 replies; 4+ messages in thread
From: Maxim Blinov @ 2019-07-31 11:21 UTC (permalink / raw)
  To: gcc-patches; +Cc: Maxim Blinov

This patch adds the same check that is present in binutils/bfd/elfxx-riscv.c.

Checks that we have reached the end of the string after all the
parsing routines have been run. Without this check, GCC silently
succeeds on erroneous input, and produces an assembly with a truncated
arch attribute.

tested with RUNTESTFLAGS="riscv.exp"

Thanks,
Maxim

gcc/ChangeLog:
2019-07-31  Maxim Blinov  <maxim.blinov@embecosm.com>

	* common/config/riscv/riscv-common.c: Check -march string ends
	with null.

gcc/testsuite/ChangeLog:
2019-07-31  Maxim Blinov  <maxim.blinov@embecosm.com>

	* gcc.target/riscv/attribute-10.c: New test.

---
 gcc/common/config/riscv/riscv-common.c        | 7 +++++++
 gcc/testsuite/gcc.target/riscv/attribute-10.c | 6 ++++++
 2 files changed, 13 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/riscv/attribute-10.c

diff --git a/gcc/common/config/riscv/riscv-common.c b/gcc/common/config/riscv/riscv-common.c
index eeb75717db0..64a309241da 100644
--- a/gcc/common/config/riscv/riscv-common.c
+++ b/gcc/common/config/riscv/riscv-common.c
@@ -513,6 +513,13 @@ riscv_subset_list::parse (const char *arch, location_t loc)
   if (p == NULL)
     goto fail;
 
+  if (*p != '\0')
+    {
+      error_at (loc, "-march=%s: unexpected ISA string at end: %<%s%>",
+               arch, p);
+      goto fail;
+    }
+
   return subset_list;
 
 fail:
diff --git a/gcc/testsuite/gcc.target/riscv/attribute-10.c b/gcc/testsuite/gcc.target/riscv/attribute-10.c
new file mode 100644
index 00000000000..dd817879a67
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/attribute-10.c
@@ -0,0 +1,6 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=rv32im_s_sx_unexpectedstring -mabi=ilp32" } */
+int foo()
+{
+}
+/* { dg-error "unexpected ISA string at end:" "" { target { "riscv*-*-*" } } 0 } */
-- 
2.20.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] RISC-V: Raise error on unexpected ISA string at end.
  2019-07-31 11:21 [PATCH] RISC-V: Raise error on unexpected ISA string at end Maxim Blinov
@ 2019-07-31 16:24 ` Martin Sebor
  2019-07-31 16:48 ` [PATCH v2] " Maxim Blinov
  1 sibling, 0 replies; 4+ messages in thread
From: Martin Sebor @ 2019-07-31 16:24 UTC (permalink / raw)
  To: Maxim Blinov, gcc-patches

On 7/31/19 5:19 AM, Maxim Blinov wrote:
> This patch adds the same check that is present in binutils/bfd/elfxx-riscv.c.
> 
> Checks that we have reached the end of the string after all the
> parsing routines have been run. Without this check, GCC silently
> succeeds on erroneous input, and produces an assembly with a truncated
> arch attribute.
> 
> tested with RUNTESTFLAGS="riscv.exp"
> 
> Thanks,
> Maxim
> 
> gcc/ChangeLog:
> 2019-07-31  Maxim Blinov  <maxim.blinov@embecosm.com>
> 
> 	* common/config/riscv/riscv-common.c: Check -march string ends
> 	with null.
> 
> gcc/testsuite/ChangeLog:
> 2019-07-31  Maxim Blinov  <maxim.blinov@embecosm.com>
> 
> 	* gcc.target/riscv/attribute-10.c: New test.
> 
> ---
>   gcc/common/config/riscv/riscv-common.c        | 7 +++++++
>   gcc/testsuite/gcc.target/riscv/attribute-10.c | 6 ++++++
>   2 files changed, 13 insertions(+)
>   create mode 100644 gcc/testsuite/gcc.target/riscv/attribute-10.c
> 
> diff --git a/gcc/common/config/riscv/riscv-common.c b/gcc/common/config/riscv/riscv-common.c
> index eeb75717db0..64a309241da 100644
> --- a/gcc/common/config/riscv/riscv-common.c
> +++ b/gcc/common/config/riscv/riscv-common.c
> @@ -513,6 +513,13 @@ riscv_subset_list::parse (const char *arch, location_t loc)
>     if (p == NULL)
>       goto fail;
>   
> +  if (*p != '\0')
> +    {
> +      error_at (loc, "-march=%s: unexpected ISA string at end: %<%s%>",

I would expect the missing quotes around the option to trigger
a -Wformat-diag warning.  The %<%s%s> should also be flagged by
the same warning.  Changing the format string as follows should
avoid the warnings:

   error_at (loc, "%<-march=%s%>: unexpected ISA string at end: %qs"

Thanks
Martin

> +               arch, p);
> +      goto fail;
> +    }
> +
>     return subset_list;
>   
>   fail:
> diff --git a/gcc/testsuite/gcc.target/riscv/attribute-10.c b/gcc/testsuite/gcc.target/riscv/attribute-10.c
> new file mode 100644
> index 00000000000..dd817879a67
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/attribute-10.c
> @@ -0,0 +1,6 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -march=rv32im_s_sx_unexpectedstring -mabi=ilp32" } */
> +int foo()
> +{
> +}
> +/* { dg-error "unexpected ISA string at end:" "" { target { "riscv*-*-*" } } 0 } */
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] RISC-V: Raise error on unexpected ISA string at end.
  2019-07-31 11:21 [PATCH] RISC-V: Raise error on unexpected ISA string at end Maxim Blinov
  2019-07-31 16:24 ` Martin Sebor
@ 2019-07-31 16:48 ` Maxim Blinov
  2019-07-31 22:14   ` Jim Wilson
  1 sibling, 1 reply; 4+ messages in thread
From: Maxim Blinov @ 2019-07-31 16:48 UTC (permalink / raw)
  To: gcc-patches; +Cc: Maxim Blinov

Hi Martin, thanks for reviewing.

> I would expect the missing quotes around the option to trigger
> a -Wformat-diag warning.  The %<%s%s> should also be flagged by
> the same warning.  Changing the format string as follows should
> avoid the warnings:
> 
>   error_at (loc, "%<-march=%s%>: unexpected ISA string at end: %qs"

I've made the corresponding changes.
tested with RUNTESTFLAGS="riscv.exp"

Thanks,
Maxim

gcc/ChangeLog:
2019-07-31  Maxim Blinov  <maxim.blinov@embecosm.com>

	* common/config/riscv/riscv-common.c: Check -march string ends
	with null.

gcc/testsuite/ChangeLog:
2019-07-31  Maxim Blinov  <maxim.blinov@embecosm.com>

	* gcc.target/riscv/attribute-10.c: New test.

---
 gcc/common/config/riscv/riscv-common.c        | 7 +++++++
 gcc/testsuite/gcc.target/riscv/attribute-10.c | 6 ++++++
 2 files changed, 13 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/riscv/attribute-10.c

diff --git a/gcc/common/config/riscv/riscv-common.c b/gcc/common/config/riscv/riscv-common.c
index eeb75717db0..a16d6c5b448 100644
--- a/gcc/common/config/riscv/riscv-common.c
+++ b/gcc/common/config/riscv/riscv-common.c
@@ -513,6 +513,13 @@ riscv_subset_list::parse (const char *arch, location_t loc)
   if (p == NULL)
     goto fail;
 
+  if (*p != '\0')
+    {
+      error_at (loc, "%<-march=%s%>: unexpected ISA string at end: %qs",
+               arch, p);
+      goto fail;
+    }
+
   return subset_list;
 
 fail:
diff --git a/gcc/testsuite/gcc.target/riscv/attribute-10.c b/gcc/testsuite/gcc.target/riscv/attribute-10.c
new file mode 100644
index 00000000000..dd817879a67
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/attribute-10.c
@@ -0,0 +1,6 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=rv32im_s_sx_unexpectedstring -mabi=ilp32" } */
+int foo()
+{
+}
+/* { dg-error "unexpected ISA string at end:" "" { target { "riscv*-*-*" } } 0 } */
-- 
2.20.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] RISC-V: Raise error on unexpected ISA string at end.
  2019-07-31 16:48 ` [PATCH v2] " Maxim Blinov
@ 2019-07-31 22:14   ` Jim Wilson
  0 siblings, 0 replies; 4+ messages in thread
From: Jim Wilson @ 2019-07-31 22:14 UTC (permalink / raw)
  To: Maxim Blinov; +Cc: GCC Patches

On Wed, Jul 31, 2019 at 9:41 AM Maxim Blinov <maxim.blinov@embecosm.com> wrote:
> gcc/ChangeLog:
> 2019-07-31  Maxim Blinov  <maxim.blinov@embecosm.com>
>
>         * common/config/riscv/riscv-common.c: Check -march string ends
>         with null.
>
> gcc/testsuite/ChangeLog:
> 2019-07-31  Maxim Blinov  <maxim.blinov@embecosm.com>
>
>         * gcc.target/riscv/attribute-10.c: New test.

Looks good.  I committed the revised patch.

Jim

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-07-31 21:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-31 11:21 [PATCH] RISC-V: Raise error on unexpected ISA string at end Maxim Blinov
2019-07-31 16:24 ` Martin Sebor
2019-07-31 16:48 ` [PATCH v2] " Maxim Blinov
2019-07-31 22:14   ` Jim Wilson

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).