[Ada] Make loop labels unique for front-end inlined calls

Programming / Compilers / GCC - pmderodat [138bc75d-0d04-0410-961f-82ee72b054a4] - 3 July 2019 08:14 EDT

This patch transforms loop labels in the body of subprograms that are to be inlined by the front-end, to prevent accidental duplication of loop labels, which might make the resulting source illegal.


Source program:

package P is procedure Get_Rom_Addr_Offset with Inline_Always; end P;

package body P is procedure Get_Rom_Addr_Offset is X : Integer; begin Main_Block : for I in 1 .. 10 loop X := 2; exit Main_Block when I > 4; other_loop: for J in character'('a') .. 'z' loop if I < 5 then exit Main_Block when J = 'k'; else Exit Other_Loop; end if; end loop other_loop; end loop Main_Block; end Get_Rom_Addr_Offset;

procedure P2 is begin Main_Block : for I in 1 .. 1 loop Get_Rom_Addr_Offset; end loop Main_Block; end P2; end P;

Command:

gcc -c -gnatN -gnatd.u -gnatDG p.adb


Output


package body p is

procedure p__get_rom_addr_offset is x : integer; other_loop : label main_block : label begin main_block : for i in 1 .. 10 loop x := 2; exit main_block when i > 4; other_loop : for j in 'a' .. 'z' loop if i < 5 then exit main_block when j = 'k'; else exit other_loop; end if; end loop other_loop; end loop main_block; return; end p__get_rom_addr_offset;

procedure p__p2 is main_block : label begin main_block : for i in 1 .. 1 loop B6b : declare x : integer; other_loopL10b : label main_blockL9b : label begin main_blockL9b : for i in 1 .. 10 loop x := 2; exit main_blockL9b when i > 4; other_loopL10b : for j in 'a' .. 'z' loop if i < 5 then exit main_blockL9b when j = 'k'; else exit other_loopL10b; end if; end loop other_loopL10b; end loop main_blockL9b; end B6b; end loop main_block; return; end p__p2; begin null; end p;

2019-07-03 Ed Schonberg

gcc/ada/

- inline.adb (Make_Loop_Labels_Unique): New procedure to modify the source code of subprograms that are inlined by the front-end, to prevent accidental duplication between loop labels in the inlined code and the code surrounding the inlined call.

c38b32ea453 [Ada] Make loop labels unique for front-end inlined calls
gcc/ada/ChangeLog | 7 ++++++
gcc/ada/inline.adb | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 69 insertions(+)

Upstream: gcc.gnu.org


  • Share