[1/2] LoongArch: Avoid RTL flag check failure in loongarch_classify_symbol

Message ID d4c6022ba84c2c95af5bf231ae6a7fdfd0aef2da.camel@xry111.site
State Committed
Commit a45b7b19e1364dd7b0066df49d458b05ba3c72d1
Headers
Series [1/2] LoongArch: Avoid RTL flag check failure in loongarch_classify_symbol |

Commit Message

Xi Ruoyao Aug. 24, 2022, 2:03 p.m. UTC
  SYMBOL_REF_TLS_MODEL invokes SYMBOL_REF_FLAGS, and SYMBOL_REF_FLAGS
invokes RTL_FLAG_CHECK1 and aborts when RTL code is not SYMBOL_REF.

r13-1833 removed "gcc_assert (SYMBOL_REF_P (x))" before invoking
"SYMBOL_REF_TLS_MODEL (x)", indicating that it's now possible that "x"
is not a SYMBOL_REF.  So we need to check if "x" is SYMBOL_REF first.

This fixes a test failure happening with r13-2173:

    pr106096.C:26:1: internal compiler error: RTL flag check:
    SYMBOL_REF_FLAGS used with unexpected rtx code 'const' in
    loongarch_classify_symbol

gcc/ChangeLog:

	* config/loongarch/loongarch.cc (loongarch_classify_symbol):
	Return early if the rtx is not SYMBOL_REF.
---
 gcc/config/loongarch/loongarch.cc | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
  

Comments

Lulu Cheng Aug. 25, 2022, 8:29 a.m. UTC | #1
在 2022/8/24 下午10:03, Xi Ruoyao 写道:
> SYMBOL_REF_TLS_MODEL invokes SYMBOL_REF_FLAGS, and SYMBOL_REF_FLAGS
> invokes RTL_FLAG_CHECK1 and aborts when RTL code is not SYMBOL_REF.
>
> r13-1833 removed "gcc_assert (SYMBOL_REF_P (x))" before invoking
> "SYMBOL_REF_TLS_MODEL (x)", indicating that it's now possible that "x"
> is not a SYMBOL_REF.  So we need to check if "x" is SYMBOL_REF first.
>
> This fixes a test failure happening with r13-2173:
>
>      pr106096.C:26:1: internal compiler error: RTL flag check:
>      SYMBOL_REF_FLAGS used with unexpected rtx code 'const' in
>      loongarch_classify_symbol


I think there is no problem with the code modification, but I have not 
detected this ICE.
  
Xi Ruoyao Aug. 25, 2022, 10:53 a.m. UTC | #2
On Thu, 2022-08-25 at 16:29 +0800, Lulu Cheng wrote:
> 
> 在 2022/8/24 下午10:03, Xi Ruoyao 写道:
>  
> > SYMBOL_REF_TLS_MODEL invokes SYMBOL_REF_FLAGS, and SYMBOL_REF_FLAGS
> > invokes RTL_FLAG_CHECK1 and aborts when RTL code is not SYMBOL_REF.
> > 
> > r13-1833 removed "gcc_assert (SYMBOL_REF_P (x))" before invoking
> > "SYMBOL_REF_TLS_MODEL (x)", indicating that it's now possible that
> > "x"
> > is not a SYMBOL_REF.  So we need to check if "x" is SYMBOL_REF
> > first.
> > 
> > This fixes a test failure happening with r13-2173:
> > 
> >     pr106096.C:26:1: internal compiler error: RTL flag check:
> >     SYMBOL_REF_FLAGS used with unexpected rtx code 'const' in
> >     loongarch_classify_symbol
> 
> I think there is no problem with the code modification, but I have not
> detected this ICE.

If ENABLE_RTL_CHECKING is disabled (for example, use --enable-
checking=release, which is also the default for release tarballs), the
check will be skipped.
  

Patch

diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc
index 16fd4acc970..41d9cca6d31 100644
--- a/gcc/config/loongarch/loongarch.cc
+++ b/gcc/config/loongarch/loongarch.cc
@@ -1633,14 +1633,13 @@  loongarch_rtx_constant_in_small_data_p (machine_mode mode)
 static enum loongarch_symbol_type
 loongarch_classify_symbol (const_rtx x)
 {
-  if (LABEL_REF_P (x))
+  if (!SYMBOL_REF_P (x))
     return SYMBOL_PCREL;
 
   if (SYMBOL_REF_TLS_MODEL (x))
     return SYMBOL_TLS;
 
-  if (SYMBOL_REF_P (x)
-      && !loongarch_symbol_binds_local_p (x))
+  if (!loongarch_symbol_binds_local_p (x))
     return SYMBOL_GOT_DISP;
 
   return SYMBOL_PCREL;