[pushed] read-rtl: Fix infinite loop while parsing [...]

Message ID mptr0l49hu0.fsf@arm.com
State Accepted
Headers
Series [pushed] read-rtl: Fix infinite loop while parsing [...] |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Richard Sandiford Nov. 5, 2023, 6:27 p.m. UTC
  read_rtx_operand would spin endlessly for:

   (unspec [(...))] UNSPEC_FOO)

because read_nested_rtx does nothing if the next character is not '('.

Pushed after testing on aarch64-linux-gnu & x86_&4-linux-gnu.

Richard


gcc/
	* read-rtl.cc (read_rtx_operand): Avoid spinning endlessly for
	invalid [...] operands.
---
 gcc/read-rtl.cc | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
  

Patch

diff --git a/gcc/read-rtl.cc b/gcc/read-rtl.cc
index 292f8b72d43..f3b5613dfdb 100644
--- a/gcc/read-rtl.cc
+++ b/gcc/read-rtl.cc
@@ -1896,8 +1896,10 @@  rtx_reader::read_rtx_operand (rtx return_rtx, int idx)
 		repeat_count--;
 		value = saved_rtx;
 	      }
-	    else
+	    else if (c == '(')
 	      value = read_nested_rtx ();
+	    else
+	      fatal_with_file_and_line ("unexpected character in vector");
 
 	    for (; repeat_count > 0; repeat_count--)
 	      {