Value Range Propigation Spec

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Fri Oct 24 05:53:03 PDT 2014


On 10/22/2014 11:31 AM, Shammah Chancellor wrote:
> A couple of us working on SDC are trying to get ValueRange propigation
> implemented.   I was wonder if someone could offer some insight as to
> how VRP works in DMD.   If for example, trying to get the value range of
> a global, what is the expected behavior?
>
> It seems as though VRP is a language feature, and not a compiler feature
> -- since this allows some code to compile and not others.   Is there a
> specification for how it should work somewhere?  If not, it's hard to
> implement other compilers that will not generate errors in the same
> circumstances as DMD.
>

AFAIK:

- arithmetic operators: new range is given by the minimum and maximum 
values that the whole expression can attain given that operands are 
arbitrary values from their respective ranges. (DMD currently does 
something worse for bitwise operators, and probably modulo.) If overflow 
may occur, the full data type range is assumed. Likewise if divide by 
zero may occur. (This despite the fact that divide by zero is supposedly 
undefined behaviour. Go figure.)

- mutable variables: full data type range is assumed

- immutable variables: range of initializer is assumed. If it is a 
foreach range index variable, combine value ranges of lower and upper 
bound appropriately.


More information about the Digitalmars-d mailing list