[fpc-devel] Data flow analysis (dfa) and "case ... of"

2017-06-05 Thread Juha Manninen
Wiki tells about problems the dfa encounters: http://wiki.freepascal.org/FPC_New_Features_3.0#Node_dfa_for_liveness_analysis In this code if "b" is true in the first test, it will be true also in the second test, thus using "i" is safe and valid. ... if b then i:=1; writeln; if b

Re: [fpc-devel] Data flow analysis (dfa) and "case ... of"

2017-06-05 Thread Denis Kozlov
Result is undefined if caller passes an out of range value. An example: TControlBorderSpacing.GetSpace(TAnchorKind(-1)); Result is indeed not initialized, so silencing this message may be harmful. Denis On 05/06/2017 15:22, Juha Manninen wrote: Wiki tells about problems the dfa encounters:

Re: [fpc-devel] Data flow analysis (dfa) and "case ... of"

2017-06-05 Thread Jonas Maebe
On 05/06/17 18:46, Denis Kozlov wrote: Result is undefined if caller passes an out of range value. That would be an error at the time this out-of-range value would be converted to TAnchorKind. If range checking is off there or disabled via an explicit type cast, then the result is undefined

Re: [fpc-devel] Data flow analysis (dfa) and "case ... of"

2017-06-05 Thread Juha Manninen
For some reason my reply went only to Denis first. Another try here... On Mon, Jun 5, 2017 at 7:46 PM, Denis Kozlov wrote: > Result is undefined if caller passes an out of range value. > An example: TControlBorderSpacing.GetSpace(TAnchorKind(-1)); > Result is indeed not

Re: [fpc-devel] Data flow analysis (dfa) and "case ... of"

2017-06-05 Thread Denis Kozlov
I have just created a new GUI application, enabled range checking "-Cr" and executed the following: ShowMessage(IntToStr(Form1.BorderSpacing.GetSpace(TAnchorKind(-1; The displayed value is a semi-random integer. No compiler errors or run-time errors. P.S. Same behaviour for Lazarus

Re: [fpc-devel] Data flow analysis (dfa) and "case ... of"

2017-06-05 Thread Jonas Maebe
On 05/06/17 19:39, Denis Kozlov wrote: I have just created a new GUI application, enabled range checking "-Cr" and executed the following: ShowMessage(IntToStr(Form1.BorderSpacing.GetSpace(TAnchorKind(-1; The displayed value is a semi-random integer. No compiler errors or run-time

Re: [fpc-devel] Data flow analysis (dfa) and "case ... of"

2017-06-05 Thread Juha Manninen
On Monday, June 5, 2017, Denis Kozlov wrote: > I have just created a new GUI application, enabled range checking "-Cr" > and executed the following: > ShowMessage(IntToStr(Form1.BorderSpacing.GetSpace(TAnchorKind(-1; > The displayed value is a semi-random integer. No

Re: [fpc-devel] Data flow analysis (dfa) and "case ... of"

2017-06-05 Thread Denis Kozlov
I just wanted to highlight that these cases as legal and I presume not uncommon, particularly if values are deserialized and typecasted. It seems that there is no way for compiler to know if the result has indeed being initialized by reason of enumeration of valid values, because one has

Re: [fpc-devel] Data flow analysis (dfa) and "case ... of"

2017-06-05 Thread Sven Barth via fpc-devel
On 05.06.2017 20:37, Denis Kozlov wrote: > > I just wanted to highlight that these cases as legal and I presume not > uncommon, particularly if values are deserialized and typecasted. They are legal in the sense that they result in undefined behavior and in that case the compiler is free to act

Re: [fpc-devel] Data flow analysis (dfa) and "case ... of"

2017-06-05 Thread Jonas Maebe
On 05/06/17 20:37, Denis Kozlov wrote: On 05/06/2017 18:59, Jonas Maebe wrote: That is why I said "If range checking is off there or disabled via an explicit type cast, then the result is undefined by definition." You use an explicit typecast above. > > I just wanted to highlight that these

Re: [fpc-devel] Data flow analysis (dfa) and "case ... of"

2017-06-05 Thread Juha Manninen
On Mon, Jun 5, 2017 at 9:37 PM, Denis Kozlov wrote: > I just wanted to highlight that these cases as legal and I presume not > uncommon, particularly if values are deserialized and typecasted. No they are not legal. Why you write this nonsense? Values outside the range dictated