From: Lulu Cheng Date: Tue, 14 Oct 2025 08:20:04 +0000 (+0800) Subject: LoongArch: Fix ICE for illegal strings in the target attribute. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bb39433b51137c5786324b48e0a5ea075be52121;p=thirdparty%2Fgcc.git LoongArch: Fix ICE for illegal strings in the target attribute. 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. --- diff --git a/gcc/config/loongarch/loongarch-target-attr.cc b/gcc/config/loongarch/loongarch-target-attr.cc index cb537446dff..922aa0483b5 100644 --- a/gcc/config/loongarch/loongarch-target-attr.cc +++ b/gcc/config/loongarch/loongarch-target-attr.cc @@ -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 " + "% 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 % argument %qs is unknown", - str_to_check); + arg_str); return found; } diff --git a/gcc/testsuite/gcc.target/loongarch/attr-check-error-message.c b/gcc/testsuite/gcc.target/loongarch/attr-check-error-message.c index 82dcd172555..6420f332110 100644 --- a/gcc/testsuite/gcc.target/loongarch/attr-check-error-message.c +++ b/gcc/testsuite/gcc.target/loongarch/attr-check-error-message.c @@ -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" } */ +{}