PR target/118828

gcc/ChangeLog:

        * config/loongarch/loongarch-c.cc (loongarch_pragma_target_parse):
        Update the predefined macros.

gcc/testsuite/ChangeLog:

        * gcc.target/loongarch/pr118828.c: New test.
        * gcc.target/loongarch/pr118828-2.c: New test.
        * gcc.target/loongarch/pr118828-3.c: New test.
        * gcc.target/loongarch/pr118828-4.c: New test.

Change-Id: I13f7b44b11bba2080db797157a0389cc1bd65ac6
---
 gcc/config/loongarch/loongarch-c.cc           | 14 +++++
 .../gcc.target/loongarch/pr118828-2.c         | 30 ++++++++++
 .../gcc.target/loongarch/pr118828-3.c         | 55 +++++++++++++++++++
 .../gcc.target/loongarch/pr118828-4.c         | 55 +++++++++++++++++++
 gcc/testsuite/gcc.target/loongarch/pr118828.c | 34 ++++++++++++
 5 files changed, 188 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/loongarch/pr118828-2.c
 create mode 100644 gcc/testsuite/gcc.target/loongarch/pr118828-3.c
 create mode 100644 gcc/testsuite/gcc.target/loongarch/pr118828-4.c
 create mode 100644 gcc/testsuite/gcc.target/loongarch/pr118828.c

diff --git a/gcc/config/loongarch/loongarch-c.cc 
b/gcc/config/loongarch/loongarch-c.cc
index 9a8de1ec381..66ae77ad665 100644
--- a/gcc/config/loongarch/loongarch-c.cc
+++ b/gcc/config/loongarch/loongarch-c.cc
@@ -27,6 +27,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tm.h"
 #include "c-family/c-common.h"
 #include "cpplib.h"
+#include "c-family/c-pragma.h"
 #include "tm_p.h"
 
 #define preprocessing_asm_p() (cpp_get_options (pfile)->lang == CLK_ASM)
@@ -212,6 +213,19 @@ loongarch_pragma_target_parse (tree args, tree pop_target)
 
   loongarch_reset_previous_fndecl ();
 
+  /* For the definitions, ensure all newly defined macros are considered
+     as used for -Wunused-macros.  There is no point warning about the
+     compiler predefined macros.  */
+  cpp_options *cpp_opts = cpp_get_options (parse_in);
+  unsigned char saved_warn_unused_macros = cpp_opts->warn_unused_macros;
+  cpp_opts->warn_unused_macros = 0;
+
+  cpp_force_token_locations (parse_in, BUILTINS_LOCATION);
+  loongarch_update_cpp_builtins (parse_in);
+  cpp_stop_forcing_token_locations (parse_in);
+
+  cpp_opts->warn_unused_macros = saved_warn_unused_macros;
+
   /* If we're popping or reseting make sure to update the globals so that
      the optab availability predicates get recomputed.  */
   if (pop_target)
diff --git a/gcc/testsuite/gcc.target/loongarch/pr118828-2.c 
b/gcc/testsuite/gcc.target/loongarch/pr118828-2.c
new file mode 100644
index 00000000000..3d32fcc15c9
--- /dev/null
+++ b/gcc/testsuite/gcc.target/loongarch/pr118828-2.c
@@ -0,0 +1,30 @@
+/* { dg-do preprocess } */
+/* { dg-options "-mno-lsx" } */
+
+#ifdef __loongarch_sx
+#error LSX should not be available here
+#endif
+
+#ifdef __loongarch_simd_width
+#error simd width shuold not be available here
+#endif
+
+#pragma GCC push_options
+#pragma GCC target("lsx")
+#ifndef __loongarch_sx
+#error LSX should be available here
+#endif
+#ifndef __loongarch_simd_width
+#error simd width should be available here
+#elif __loongarch_simd_width != 128
+#error simd width should be 128
+#endif
+#pragma GCC pop_options
+
+#ifdef __loongarch_sx
+#error LSX should become unavailable again
+#endif
+
+#ifdef __loongarch_simd_width
+#error simd width shuold become unavailable again
+#endif
diff --git a/gcc/testsuite/gcc.target/loongarch/pr118828-3.c 
b/gcc/testsuite/gcc.target/loongarch/pr118828-3.c
new file mode 100644
index 00000000000..a682ae4a356
--- /dev/null
+++ b/gcc/testsuite/gcc.target/loongarch/pr118828-3.c
@@ -0,0 +1,55 @@
+/* { dg-do run } */
+/* { dg-options "-march=loongarch64" } */
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifndef __loongarch_arch
+#error __loongarch_arch should not be available here
+#endif
+
+void
+test1 (void)
+{
+  if (strcmp (__loongarch_arch, "loongarch64") != 0)
+    {
+      printf ("__loongarch_arch should be loongarch64 here.\n");
+      abort ();
+    }
+}
+
+
+#pragma GCC push_options
+#pragma GCC target("arch=la64v1.1")
+
+void
+test2 (void)
+{
+  if (strcmp (__loongarch_arch, "la64v1.1") != 0)
+    {
+      printf ("__loongarch_arch should be la464 here.\n");
+      abort ();
+    }
+}
+#pragma GCC pop_options
+
+void
+test3 (void)
+{
+  if (strcmp (__loongarch_arch, "loongarch64") != 0)
+    {
+      printf ("__loongarch_arch should be loongarch64 here.\n");
+      abort ();
+    }
+}
+
+int
+main (int argc, char **argv)
+{
+  test1 ();
+  test2 ();
+  test3 ();
+
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.target/loongarch/pr118828-4.c 
b/gcc/testsuite/gcc.target/loongarch/pr118828-4.c
new file mode 100644
index 00000000000..3b3a7c6078c
--- /dev/null
+++ b/gcc/testsuite/gcc.target/loongarch/pr118828-4.c
@@ -0,0 +1,55 @@
+/* { dg-do run } */
+/* { dg-options "-mtune=la464" } */
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifndef __loongarch_tune
+#error __loongarch_tune should not be available here
+#endif
+
+void
+test1 (void)
+{
+  if (strcmp (__loongarch_tune, "la464") != 0)
+    {
+      printf ("__loongarch_tune should be la464 here.\n");
+      abort ();
+    }
+}
+
+
+#pragma GCC push_options
+#pragma GCC target("arch=la664")
+
+void
+test2 (void)
+{
+  if (strcmp (__loongarch_tune, "la664") != 0)
+    {
+      printf ("__loongarch_tune should be la664 here.\n");
+      abort ();
+    }
+}
+#pragma GCC pop_options
+
+void
+test3 (void)
+{
+  if (strcmp (__loongarch_tune, "la464") != 0)
+    {
+      printf ("__loongarch_tune should be la464 here.\n");
+      abort ();
+    }
+}
+
+int
+main (int argc, char **argv)
+{
+  test1 ();
+  test2 ();
+  test3 ();
+
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.target/loongarch/pr118828.c 
b/gcc/testsuite/gcc.target/loongarch/pr118828.c
new file mode 100644
index 00000000000..abdda24c758
--- /dev/null
+++ b/gcc/testsuite/gcc.target/loongarch/pr118828.c
@@ -0,0 +1,34 @@
+/* { dg-do preprocess } */
+/* { dg-options "-mno-lasx" } */
+
+#ifdef __loongarch_asx
+#error LASX should not be available here
+#endif
+
+#ifdef __loongarch_simd_width
+#if __loongarch_simd_width == 256
+#error simd width shuold not be 256
+#endif
+#endif
+
+#pragma GCC push_options
+#pragma GCC target("lasx")
+#ifndef __loongarch_asx
+#error LASX should be available here
+#endif
+#ifndef __loongarch_simd_width
+#error simd width should be available here
+#elif __loongarch_simd_width != 256
+#error simd width should be 256
+#endif
+#pragma GCC pop_options
+
+#ifdef __loongarch_asx
+#error LASX should become unavailable again
+#endif
+
+#ifdef __loongarch_simd_width
+#if __loongarch_simd_width == 256
+#error simd width shuold not be 256 again
+#endif
+#endif
-- 
2.34.1

Reply via email to