x86: Reject target("no-general-regs-only")
authorH.J. Lu <hjl.tools@gmail.com>
Wed, 26 Aug 2020 19:37:05 +0000 (12:37 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Wed, 26 Aug 2020 19:56:18 +0000 (12:56 -0700)
Reject target("no-general-regs-only") pragma and attribute.

gcc/

PR target/96802
* config/i386/i386-options.c (ix86_valid_target_attribute_inner_p):
Reject target("no-general-regs-only").

gcc/testsuite/

PR target/96802
* gcc.target/i386/pr96802-1.c: New test.
* gcc.target/i386/pr96802-2.c: Likewise.

gcc/config/i386/i386-options.c
gcc/testsuite/gcc.target/i386/pr96802-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr96802-2.c [new file with mode: 0644]

index e0fc68c27bf3ead8a57b46ad6de48d5fb87a02de..b93c338346f2f77c03a479b2baf1081aecbc6be8 100644 (file)
@@ -1189,6 +1189,13 @@ ix86_valid_target_attribute_inner_p (tree fndecl, tree args, char *p_strings[],
        {
          if (mask == OPTION_MASK_GENERAL_REGS_ONLY)
            {
+             if (!opt_set_p)
+               {
+                 error_at (loc, "pragma or attribute %<target(\"%s\")%>  "
+                           "does not allow a negated form", p);
+                 return false;
+               }
+
              if (type != ix86_opt_ix86_yes)
                gcc_unreachable ();
 
diff --git a/gcc/testsuite/gcc.target/i386/pr96802-1.c b/gcc/testsuite/gcc.target/i386/pr96802-1.c
new file mode 100644 (file)
index 0000000..e6ceb95
--- /dev/null
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+
+/* Reject the negated form of non-negatable attributes.  */
+
+__attribute__ ((target ("no-general-regs-only")))
+int
+foo (int a)
+{
+  return a + 1;
+}
+
+/* { dg-error "does not allow a negated form" "" { target *-*-* } 0 } */
diff --git a/gcc/testsuite/gcc.target/i386/pr96802-2.c b/gcc/testsuite/gcc.target/i386/pr96802-2.c
new file mode 100644 (file)
index 0000000..515f567
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+
+/* Reject the negated form of non-negatable pragma target.  */
+
+#pragma GCC push_options
+#pragma GCC target("no-general-regs-only")
+
+int
+foo (int a)
+{
+  return a + 1;
+}
+
+#pragma GCC pop_options
+
+/* { dg-error "does not allow a negated form" "" { target *-*-* } 0 } */