Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2025-02

"unused variable" depends on optimization?

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Martin Frb

Is it correct (i.e. by design) that the compiler emits some "may not be initialized" warnings, only on certain optimization levels?

The following is
- NOT given with -O1
- present with -O3

lazsyntextarea.pp(1325,54) Warning: Local variable "ViewedRange" does
not seem to be initialized

O1 is actually right, it is always initialized, no warning needed. But I would accept that the compiler may not be able to deduce that. However, if it does not, then should O1 also display the warning?

procedure TLazSynSurfaceManager.InvalidateLines(FirstTextLine,
   LastTextLine: TLineIdx; AScreenLineOffset: Integer);
var
   rcInval: TRect;
   ViewedRange: TLineRange;
begin
   rcInval := Bounds;
   if (FirstTextLine >= 0) then begin
     ViewedRange := DisplayView.TextToViewIndex(FirstTextLine);
     rcInval.Top := Max(TextArea.TextBounds.Top,
                        TextArea.TextBounds.Top + (ViewedRange.Top +
AScreenLineOffset
                           - TextArea.TopLine + 1) * TextArea.LineHeight);
   end;
   if (LastTextLine >= 0) then begin
     if LastTextLine  FirstTextLine then
       ViewedRange := DisplayView.TextToViewIndex(LastTextLine);
     rcInval.Bottom := Min(TextArea.TextBounds.Bottom, ///////////////
<<<<<<< 1325
                           TextArea.TextBounds.Top + (ViewedRange.Bottom
+ AScreenLineOffset
                              - TextArea.TopLine + 2)  *
TextArea.LineHeight);
   end;

Reply by email

Jonas Maebe
to Martin Frb
Martin Frb wrote
Is it correct (i.e. by design) that the compiler emits some "may not be initialized" warnings, only on certain optimization levels?

Yes. Those warnings depends on data flow analysis, which is only enabled by defaullt at -O3 and higher. You can also enabled it separately with -Oodfa.

Jonas

Reply by email

Martin Frb
to Jonas Maebe
Jonas Maebe wrote 7 lines
On 23/02/2025 14:14, Martin Frb via fpc-devel wrote: > Is it correct (i.e. by design) that the compiler emits some "may not > be initialized" warnings, only on certain optimization levels? Yes. Those warnings depends on data flow analysis, which is only enabled by defaullt at -O3 and higher. You can also enabled it separately with -Oodfa.

Ok, so without dfa it does not omit the warning, probably because it has see that there was a conditional initialization? (i.e. might be ok, at least sometimes, even if certainly not always)

Meaning -O1 is lenient in its checks, because they are not as evolved.

Reply by email

Florian Klämpfl
to Martin Frb
Show quoted text 11 lines
Am 23.02.2025 um 14:26 schrieb Martin Frb via fpc-devel : On 23/02/2025 14:16, Jonas Maebe via fpc-devel wrote: > On 23/02/2025 14:14, Martin Frb via fpc-devel wrote: >> Is it correct (i.e. by design) that the compiler emits some "may not be initialized" warnings, only on certain optimization levels? > > Yes. Those warnings depends on data flow analysis, which is only enabled by defaullt at -O3 and higher. You can also enabled it separately with -Oodfa. Ok, so without dfa it does not omit the warning, probably because it has see that there was a conditional initialization? (i.e. might be ok, at least sometimes, even if certainly not always) Meaning -O1 is lenient in its checks, because they are not as evolved.

Yes, with -O1 the compiler does not see that the variable is initialized only conditionally. With -Oodfa/-O3 it takes care of this but actually it should also know about the condition being the same, something it cannot do at any optimization level.

Reply by email