Recent

Author Topic: [Solved] Why FPC don't 'fold' str consts?  (Read 995 times)

AlexTP

  • Hero Member
  • *****
  • Posts: 2714
    • UVviewsoft
[Solved] Why FPC don't 'fold' str consts?
« on: October 24, 2022, 06:15:43 pm »
Code: Pascal  [Select][+][-]
  1. {$mode objfpc}{$h+}
  2. const
  3.   cc0 = 'value0';
  4.   cc1 = 'value1';
  5. var
  6.   s: string;
  7. begin
  8.   s:= 'text_';
  9.   s:= s+ '_prefix_'+cc0+cc1;
  10.   writeln(s);
  11. end.
  12.  
I see that binary file has separate places for all 3 consts:
- '_prefix_'
- 'value0'
- 'value1'
While FPC can fold all 3 to a single one. If I use brackets,

Code: Pascal  [Select][+][-]
  1. s+ ('_prefix_'+cc0+cc1);
  2.  
I see the single place with all 3 concatenated.

Free Pascal Compiler version 3.2.3-660-g9b2ba834a6 [2022/08/18] for x86_64
« Last Edit: November 26, 2022, 10:09:01 pm by AlexTP »

Kays

  • Hero Member
  • *****
  • Posts: 632
  • Whasup!?
    • KaiBurghardt.de
Re: Why does FPC not “fold” string constants?
« Reply #1 on: October 25, 2022, 02:14:36 pm »
Bug was described in issue #38267. Should be fixed in 3.3.1 now.
Yours Sincerely
Kai Burghardt

AlexTP

  • Hero Member
  • *****
  • Posts: 2714
    • UVviewsoft
Re: Why FPC don't 'fold' str consts?
« Reply #2 on: October 25, 2022, 02:49:30 pm »
Thanks! Solved.

PascalDragon

  • Hero Member
  • *****
  • Posts: 6397
  • Compiler Developer
Re: Why FPC don't 'fold' str consts?
« Reply #3 on: October 25, 2022, 09:07:41 pm »
Please note that this requires at least -O2 (just for the sake of completeness so that no one is surprised).

 

TinyPortal © 2005-2018