This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch: suppress -Woverlength-strings in asm()
- From: Tom Tromey <tromey at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 02 Feb 2011 13:04:11 -0700
- Subject: Patch: suppress -Woverlength-strings in asm()
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.
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: ;
+}
+