]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
LoongArch: Fix ICE caused by illegal calls to builtin functions [PR118561].
authorLulu Cheng <chenglulu@loongson.cn>
Wed, 22 Jan 2025 09:57:21 +0000 (17:57 +0800)
committerLulu Cheng <chenglulu@loongson.cn>
Thu, 6 Feb 2025 11:06:30 +0000 (19:06 +0800)
PR target/118561

gcc/ChangeLog:

* config/loongarch/loongarch-builtins.cc
(loongarch_expand_builtin_lsx_test_branch):
NULL_RTX will not be returned when an error is detected.
(loongarch_expand_builtin): Likewise.

gcc/testsuite/ChangeLog:

* gcc.target/loongarch/pr118561.c: New test.

(cherry picked from commit 50d2bde68a097c2e9fb3bdd7e6664c8988889828)

gcc/config/loongarch/loongarch-builtins.cc
gcc/testsuite/gcc.target/loongarch/pr118561.c [new file with mode: 0644]

index 8a635938deed795c9a49a6de3270920822a2023a..669313ac9b7abb5a38a826b1f0a310ac343d0e5b 100644 (file)
@@ -3074,7 +3074,10 @@ loongarch_expand_builtin_lsx_test_branch (enum insn_code icode, tree exp)
     ops[1].value = force_reg (ops[1].mode, ops[1].value);
 
   if ((cbranch = maybe_gen_insn (icode, 3, ops)) == NULL_RTX)
-    error ("failed to expand built-in function");
+    {
+      error ("failed to expand built-in function");
+      return const0_rtx;
+    }
 
   cmp_result = gen_reg_rtx (SImode);
 
@@ -3114,7 +3117,7 @@ loongarch_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED,
     {
       error_at (EXPR_LOCATION (exp),
                "built-in function %qD is not enabled", fndecl);
-      return target;
+      return target ? target : const0_rtx;
     }
 
   switch (d->builtin_type)
diff --git a/gcc/testsuite/gcc.target/loongarch/pr118561.c b/gcc/testsuite/gcc.target/loongarch/pr118561.c
new file mode 100644 (file)
index 0000000..81a776e
--- /dev/null
@@ -0,0 +1,9 @@
+/* PR target/118561: ICE with -mfpu=none */
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=loongarch64 -mfpu=none" } */
+
+int
+test (void)
+{
+  return __builtin_loongarch_movfcsr2gr (0); /* { dg-error "built-in function '__builtin_loongarch_movfcsr2gr' is not enabled" } */
+}