aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorLulu Cheng <chenglulu@loongson.cn>2025-01-22 17:57:21 +0800
committerLulu Cheng <chenglulu@loongson.cn>2025-02-06 19:03:39 +0800
commit50d2bde68a097c2e9fb3bdd7e6664c8988889828 (patch)
treec158d458059817c0fd29c8a7c9864dd78219c4c8 /gcc
parent7eb260c8a472568912c1e0b83fb402d22977281e (diff)
downloadgcc-50d2bde68a097c2e9fb3bdd7e6664c8988889828.zip
gcc-50d2bde68a097c2e9fb3bdd7e6664c8988889828.tar.gz
gcc-50d2bde68a097c2e9fb3bdd7e6664c8988889828.tar.bz2
LoongArch: Fix ICE caused by illegal calls to builtin functions [PR118561].
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/config/loongarch/loongarch-builtins.cc7
-rw-r--r--gcc/testsuite/gcc.target/loongarch/pr118561.c9
2 files changed, 14 insertions, 2 deletions
diff --git a/gcc/config/loongarch/loongarch-builtins.cc b/gcc/config/loongarch/loongarch-builtins.cc
index 92d995a..1849b35 100644
--- a/gcc/config/loongarch/loongarch-builtins.cc
+++ b/gcc/config/loongarch/loongarch-builtins.cc
@@ -2996,7 +2996,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);
@@ -3036,7 +3039,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
index 0000000..81a776e
--- /dev/null
+++ b/gcc/testsuite/gcc.target/loongarch/pr118561.c
@@ -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" } */
+}