Patchwork Patch: suppress -Woverlength-strings in asm()

login
register
mail settings
Submitter Tom Tromey
Date Feb. 2, 2011, 8:04 p.m.
Message ID <m3r5bqfbk4.fsf@fleche.redhat.com>
Download mbox | patch
Permalink /patch/81528/
State New
Headers show

Comments

Tom Tromey - Feb. 2, 2011, 8:04 p.m.
This is a supplement to my previous patch to allow __extension__ to
suppress -Woverlength-strings.

This patch changes `asm' to disable -Woverlength-strings implicitly.
The rationale for this is that (1) asm is a gcc extension, so the
pedantic rule need not apply, and (2) that __extension__ __asm__ may
suppress too much.

Jakub regtested this for me.  New test cases included.

Tom

2011-02-02  Tom Tromey  <tromey@redhat.com>

	* c-parser.c (c_parser_asm_string_literal): Clear
	warn_overlength_strings.

2011-02-02  Tom Tromey  <tromey@redhat.com>

	* gcc.dg/Woverlength-strings-pedantic-c90-asm.c: New file.
	* gcc.dg/Woverlength-strings-pedantic-c89-asm.c: New file.
	* gcc.dg/Woverlength-strings-pedantic-c99-asm.c: New file.
Joseph S. Myers - Feb. 4, 2011, 9:32 p.m.
On Wed, 2 Feb 2011, Tom Tromey wrote:

> 2011-02-02  Tom Tromey  <tromey@redhat.com>
> 
> 	* c-parser.c (c_parser_asm_string_literal): Clear
> 	warn_overlength_strings.
> 
> 2011-02-02  Tom Tromey  <tromey@redhat.com>
> 
> 	* gcc.dg/Woverlength-strings-pedantic-c90-asm.c: New file.
> 	* gcc.dg/Woverlength-strings-pedantic-c89-asm.c: New file.
> 	* gcc.dg/Woverlength-strings-pedantic-c99-asm.c: New file.

OK.
Tom Tromey - March 14, 2011, 5:52 p.m.
>> 2011-02-02  Tom Tromey  <tromey@redhat.com>
>> 
>> * c-parser.c (c_parser_asm_string_literal): Clear
>> warn_overlength_strings.
>> 
>> 2011-02-02  Tom Tromey  <tromey@redhat.com>
>> 
>> * gcc.dg/Woverlength-strings-pedantic-c90-asm.c: New file.
>> * gcc.dg/Woverlength-strings-pedantic-c89-asm.c: New file.
>> * gcc.dg/Woverlength-strings-pedantic-c99-asm.c: New file.

Joseph> OK.

Now that Stage 1 is open, I am checking this in.

I think this is minor enough that it need not be synchronized with any
other commit.

Tom

Patch

diff --git a/gcc/c-parser.c b/gcc/c-parser.c
index b0ef249..dd4c535 100644
--- a/gcc/c-parser.c
+++ b/gcc/c-parser.c
@@ -3264,6 +3264,8 @@  static tree
 c_parser_asm_string_literal (c_parser *parser)
 {
   tree str;
+  int save_flag = warn_overlength_strings;
+  warn_overlength_strings = 0;
   if (c_parser_next_token_is (parser, CPP_STRING))
     {
       str = c_parser_peek_token (parser)->value;
@@ -3281,6 +3283,7 @@  c_parser_asm_string_literal (c_parser *parser)
       c_parser_error (parser, "expected string literal");
       str = NULL_TREE;
     }
+  warn_overlength_strings = save_flag;
   return str;
 }
 
diff --git a/gcc/testsuite/gcc.dg/Woverlength-strings-pedantic-c89-asm.c b/gcc/testsuite/gcc.dg/Woverlength-strings-pedantic-c89-asm.c
new file mode 100644
index 0000000..45373bc
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Woverlength-strings-pedantic-c89-asm.c
@@ -0,0 +1,47 @@ 
+/* -Woverlength-strings complains about string constants which are too long
+   for the C standard's "minimum maximum" limits.  It is off by default,
+   but implied by -pedantic.  */
+
+/* { dg-options "-std=c89 -pedantic" } */
+
+#define TEN "          "
+#define HUN TEN TEN TEN TEN TEN  TEN TEN TEN TEN TEN
+#define THO HUN HUN HUN HUN HUN  HUN HUN HUN HUN HUN
+
+/* C89's minimum-maximum is 509. */
+__asm__ (HUN HUN HUN HUN HUN TEN);
+
+/* C99's minimum-maximum is 4095.  */
+__asm__ (
+  THO THO THO THO     /* 4000 */
+  TEN TEN TEN TEN TEN /* 4050 */
+  TEN TEN TEN TEN     /* 4090 */
+  "123456");
+
+void
+f (void)
+{
+  /* C89's minimum-maximum is 509. */
+  __asm__ (HUN HUN HUN HUN HUN TEN);
+  __asm__ (HUN HUN HUN HUN HUN TEN : : );
+  __asm__ goto (HUN HUN HUN HUN HUN TEN : : : : label);
+
+  /* C99's minimum-maximum is 4095.  */
+  __asm__ (
+	   THO THO THO THO     /* 4000 */
+	   TEN TEN TEN TEN TEN /* 4050 */
+	   TEN TEN TEN TEN     /* 4090 */
+	   "123456");
+  __asm__ (
+	   THO THO THO THO     /* 4000 */
+	   TEN TEN TEN TEN TEN /* 4050 */
+	   TEN TEN TEN TEN     /* 4090 */
+	   "123456" : : );
+  __asm__ goto (
+		THO THO THO THO     /* 4000 */
+		TEN TEN TEN TEN TEN /* 4050 */
+		TEN TEN TEN TEN     /* 4090 */
+		"123456" : : : : label);
+
+ label: ;
+}
diff --git a/gcc/testsuite/gcc.dg/Woverlength-strings-pedantic-c90-asm.c b/gcc/testsuite/gcc.dg/Woverlength-strings-pedantic-c90-asm.c
new file mode 100644
index 0000000..b5523bc
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Woverlength-strings-pedantic-c90-asm.c
@@ -0,0 +1,48 @@ 
+/* -Woverlength-strings complains about string constants which are too long
+   for the C standard's "minimum maximum" limits.  It is off by default,
+   but implied by -pedantic.  */
+
+/* { dg-options "-std=c90 -pedantic" } */
+
+#define TEN "          "
+#define HUN TEN TEN TEN TEN TEN  TEN TEN TEN TEN TEN
+#define THO HUN HUN HUN HUN HUN  HUN HUN HUN HUN HUN
+
+/* C89's minimum-maximum is 509. */
+__asm__ (HUN HUN HUN HUN HUN TEN);
+
+/* C99's minimum-maximum is 4095.  */
+__asm__ (
+  THO THO THO THO     /* 4000 */
+  TEN TEN TEN TEN TEN /* 4050 */
+  TEN TEN TEN TEN     /* 4090 */
+  "123456");
+
+void
+f (void)
+{
+  /* C89's minimum-maximum is 509. */
+  __asm__ (HUN HUN HUN HUN HUN TEN);
+  __asm__ (HUN HUN HUN HUN HUN TEN : :);
+  __asm__ goto (HUN HUN HUN HUN HUN TEN : : : : label);
+
+  /* C99's minimum-maximum is 4095.  */
+  __asm__ (
+	   THO THO THO THO     /* 4000 */
+	   TEN TEN TEN TEN TEN /* 4050 */
+	   TEN TEN TEN TEN     /* 4090 */
+	   "123456");
+  __asm__ (
+	   THO THO THO THO     /* 4000 */
+	   TEN TEN TEN TEN TEN /* 4050 */
+	   TEN TEN TEN TEN     /* 4090 */
+	   "123456" : :);
+  __asm__ goto (
+		THO THO THO THO     /* 4000 */
+		TEN TEN TEN TEN TEN /* 4050 */
+		TEN TEN TEN TEN     /* 4090 */
+		"123456" : : : : label);
+
+ label: ;
+}
+
diff --git a/gcc/testsuite/gcc.dg/Woverlength-strings-pedantic-c99-asm.c b/gcc/testsuite/gcc.dg/Woverlength-strings-pedantic-c99-asm.c
new file mode 100644
index 0000000..8840e38
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Woverlength-strings-pedantic-c99-asm.c
@@ -0,0 +1,48 @@ 
+/* -Woverlength-strings complains about string constants which are too long
+   for the C standard's "minimum maximum" limits.  It is off by default,
+   but implied by -pedantic.  */
+
+/* { dg-options "-std=c99 -pedantic" } */
+
+#define TEN "          "
+#define HUN TEN TEN TEN TEN TEN  TEN TEN TEN TEN TEN
+#define THO HUN HUN HUN HUN HUN  HUN HUN HUN HUN HUN
+
+/* C89's minimum-maximum is 509. */
+__asm__ (HUN HUN HUN HUN HUN TEN);
+
+/* C99's minimum-maximum is 4095.  */
+__asm__ (
+  THO THO THO THO     /* 4000 */
+  TEN TEN TEN TEN TEN /* 4050 */
+  TEN TEN TEN TEN     /* 4090 */
+  "123456");
+
+void
+f (void)
+{
+  /* C89's minimum-maximum is 509. */
+  __asm__ (HUN HUN HUN HUN HUN TEN);
+  __asm__ (HUN HUN HUN HUN HUN TEN : :);
+  __asm__ goto (HUN HUN HUN HUN HUN TEN : : : : label);
+
+  /* C99's minimum-maximum is 4095.  */
+  __asm__ (
+	   THO THO THO THO     /* 4000 */
+	   TEN TEN TEN TEN TEN /* 4050 */
+	   TEN TEN TEN TEN     /* 4090 */
+	   "123456");
+  __asm__ (
+	   THO THO THO THO     /* 4000 */
+	   TEN TEN TEN TEN TEN /* 4050 */
+	   TEN TEN TEN TEN     /* 4090 */
+	   "123456" : :);
+  __asm__ goto (
+		THO THO THO THO     /* 4000 */
+		TEN TEN TEN TEN TEN /* 4050 */
+		TEN TEN TEN TEN     /* 4090 */
+		"123456" : : : : label);
+
+ label: ;
+}
+