diff options
author | Piotr Trojanek <trojanek@adacore.com> | 2025-01-02 17:36:54 +0100 |
---|---|---|
committer | Marc Poulhiès <dkm@gcc.gnu.org> | 2025-01-13 11:52:56 +0100 |
commit | 26b649b2d17dccf0f4c3c048f37c49660aad7f71 (patch) | |
tree | a1e7c0ffa9c6fadcffd5f8fb5955a8ab334c5b1f | |
parent | d3904a3ad9d7b4c8e5e536e5166b89548510fd48 (diff) | |
download | gcc-26b649b2d17dccf0f4c3c048f37c49660aad7f71.zip gcc-26b649b2d17dccf0f4c3c048f37c49660aad7f71.tar.gz gcc-26b649b2d17dccf0f4c3c048f37c49660aad7f71.tar.bz2 |
ada: Fix parsing of raise expressions with no parens
According to Ada grammar, raise expression is an expression, but requires
parens to be a simple_expression. We wrongly classified raise expressions
as expressions, because we mishandled a global state variable in the parser.
This patch causes some illegal code to be rejected.
gcc/ada/ChangeLog:
* par-ch4.adb (P_Relation): Prevent Expr_Form to be overwritten when
parsing the raise expression itself.
(P_Simple_Expression): Fix manipulation of Expr_Form.
-rw-r--r-- | gcc/ada/par-ch4.adb | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/gcc/ada/par-ch4.adb b/gcc/ada/par-ch4.adb index 97f9b7d..3f8d1f1 100644 --- a/gcc/ada/par-ch4.adb +++ b/gcc/ada/par-ch4.adb @@ -2181,8 +2181,9 @@ package body Ch4 is -- First check for raise expression if Token = Tok_Raise then + Node1 := P_Raise_Expression; Expr_Form := EF_Non_Simple; - return P_Raise_Expression; + return Node1; end if; -- All other cases @@ -2415,6 +2416,8 @@ package body Ch4 is Node1 := P_Term; end if; + Expr_Form := EF_Simple; + -- In the following, we special-case a sequence of concatenations of -- string literals, such as "aaa" & "bbb" & ... & "ccc", with nothing -- else mixed in. For such a sequence, we return a tree representing @@ -2530,11 +2533,6 @@ package body Ch4 is end; end if; end; - - -- All done, we clearly do not have name or numeric literal so this - -- is a case of a simple expression which is some other possibility. - - Expr_Form := EF_Simple; end if; -- If all extensions are enabled and we have a deep delta aggregate |