]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
LoongArch: Fix ICE for illegal strings in the target attribute.
authorLulu Cheng <chenglulu@loongson.cn>
Tue, 14 Oct 2025 08:20:04 +0000 (16:20 +0800)
committerLulu Cheng <chenglulu@loongson.cn>
Tue, 11 Nov 2025 07:33:35 +0000 (15:33 +0800)
Modify the two situations:

1. __attribute__ ((target ("arch")))
ICE will be reported before modification, and there will be an error
prompt after modification.

2. __attribute__ ((target ("arch=12345")))
Fixed the issue where the attribute string was not printed completely
in the previous error message.

gcc/ChangeLog:

* config/loongarch/loongarch-target-attr.cc
(loongarch_process_one_target_attr): Fix ICE.

gcc/testsuite/ChangeLog:

* gcc.target/loongarch/attr-check-error-message.c: Add tests.

gcc/config/loongarch/loongarch-target-attr.cc
gcc/testsuite/gcc.target/loongarch/attr-check-error-message.c

index cb537446dffe13169f81123a5b30636bcd3611b7..922aa0483b57984a896e7a76265f119f73261ed8 100644 (file)
@@ -203,7 +203,13 @@ loongarch_process_one_target_attr (char *arg_str, location_t loc)
          /* Use the option setting machinery to set an option to an enum.  */
          case loongarch_attr_enum:
            {
-             gcc_assert (arg);
+             if (!arg)
+               {
+                 error_at (loc, "the value of pragma or attribute "
+                           "%<target(\"%s\")%> not be empty", str_to_check);
+                 return false;
+               }
+
              bool valid;
              int value;
              struct cl_decoded_option decoded;
@@ -244,7 +250,7 @@ loongarch_process_one_target_attr (char *arg_str, location_t loc)
      were malformed we will have returned false already.  */
   if (!found)
     error_at (loc, "attribute %<target%> argument %qs is unknown",
-             str_to_check);
+             arg_str);
 
   return found;
 }
index 82dcd1725553cfef7c3e17bc168017a16ea42489..6420f332110114982d975a17a9b5006ccb08edc4 100644 (file)
@@ -28,3 +28,11 @@ test6 (void) /* { dg-error "attribute \\\'target\\\' argument not a string" } */
 __attribute__ ((target ("lsx,"))) void
 test7 (void)   /* { dg-error "malformed \\\'target\\\(\\\"lsx,\\\"\\\)\\\' pragma or attribute" } */
 {}
+
+__attribute__ ((target ("arch"))) void
+test8 (void)   /* { dg-error "the value of pragma or attribute \\\'target\\\(\\\"arch\\\"\\\)\\\' not be empty" } */
+{}
+
+__attribute__ ((target ("lsx;priority=1"))) void
+test9 (void)   /* { dg-error "attribute \\\'target\\\' argument \\\'lsx;priority=1\\\' is unknown" } */
+{}