[COMMITTED] ada: Reject illegal declarations in expression functions

Message ID 20230522084950.1725774-1-poulhies@adacore.com
State Accepted
Headers
Series [COMMITTED] ada: Reject illegal declarations in expression functions |

Checks

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

Commit Message

Marc Poulhiès May 22, 2023, 8:49 a.m. UTC
  From: Steve Baird <baird@adacore.com>

gcc/ada/

	* sem_ch4.adb (Analyze_Expression_With_Actions.Check_Action_Ok):
	If Comes_From_Source (A) is False, then look at Original_Node (A)
	instead of A. In particular, if an (illegal) expression function
	is transformed into a "vanilla" function, we don't want to allow
	it just because Comes_From_Source is now False.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_ch4.adb | 10 ++++++++++
 1 file changed, 10 insertions(+)
  

Patch

diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb
index 153a63586ca..7e8da9f2d5a 100644
--- a/gcc/ada/sem_ch4.adb
+++ b/gcc/ada/sem_ch4.adb
@@ -2368,6 +2368,16 @@  package body Sem_Ch4 is
       procedure Check_Action_OK (A : Node_Id) is
       begin
          if not Comes_From_Source (N) or else not Comes_From_Source (A) then
+
+            --  If, for example, an (illegal) expression function is
+            --  transformed into a"vanilla" function then we don't want to
+            --  allow it just because Comes_From_Source is now False. So look
+            --  at the Original_Node.
+
+            if A /= Original_Node (A) then
+               Check_Action_OK (Original_Node (A));
+            end if;
+
             return; -- Allow anything in generated code
          end if;