This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
The compiler tries to optimize comparisons involving expressions that are not compile-time known, but can be recognized as identical, for example references to the same variable. If the expressions are references to the same discriminant the expressions cannot be assumed to be equal, because they may denote the discriminant of two different instances of the same discriminated type, used for example as a component bound. The following must compile and execute quietly: procedure No_Fold is type Arr is array (integer range <>) of Integer; type Rec (Discr : Positive) is record Field : Arr (1 .. Discr); end record; R1 : Rec (3) := (3, (others => 0)); R2 : Rec (7) := (7, (others => 0)); procedure Compare (X, Y : Rec) is begin if X.Discr < Y.Discr and then not (X.Field'Last < Y.Field'Last) then raise Program_Error; end if; end Compare; begin Compare (R1, R2); end; Tested on x86_64-pc-linux-gnu, committed on trunk 2010-09-09 Ed Schonberg <schonberg@adacore.com> * sem_eval.adb (Is_Same_Value): Two occurrences of the same discriminant cannot be assumed to be the same value because they may refer to bounds of a component of two different instances of a discriminated type.
Attachment:
difs
Description: Text document
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |