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] | |
Tested on i686-linux, committed on trunk
The following program shows a number of warnings now issued for known
at compile time constraint check failures that were missed before.
1. package N is
2. type Ref is access all Integer;
3. subtype Not_Null_Ref is not null Ref;
4. Nil : constant Ref := null;
5. procedure P (X : not null Ref);
6. procedure Q (X : out Not_Null_Ref);
7. function F (X : not null Ref) return not null Ref;
8. Int : aliased Integer := 123;
9. end N;
Compiling: n.adb (source file time stamp: 2007-06-29 14:04:08)
1. package body N is
2. procedure P (X : not null Ref) is
3. begin
4. null;
5. end P;
6. procedure Q (X : out Not_Null_Ref) is
|
>>> warning: variable "X" is never read and never assigned
7. begin
8. X := Nil; -- WARNING: null not allowed
|
>>> warning: (Ada 2005) null not allowed in null-excluding objects
>>> warning: "Constraint_Error" will be raised at run time
9. end Q;
10. function F (X : not null Ref) return not null Ref is
11. begin
12. return Nil; -- WARNING: null not allowed
|
>>> warning: (Ada 2005) null not allowed for null-excluding return
>>> warning: "Constraint_Error" will be raised at run time
13. end F;
14. end N;
1. procedure N.Main is
2. Local_3 : not null Ref := Nil; -- WARNING: null not allowed
|
>>> warning: null value not allowed here
>>> warning: "Constraint_Error" will be raised at run time
3. Local_4 : not null Ref := Int'Access; -- OK
4. begin
5. Local_4 := Nil; -- WARNING: null not allowed
|
>>> warning: (Ada 2005) null not allowed in null-excluding objects
>>> warning: "Constraint_Error" will be raised at run time
6. P (Nil); -- WARNING: null not allowed
|
>>> warning: (Ada 2005) null not allowed in null-excluding formal
>>> warning: "Constraint_Error" will be raised at run time
7. end N.Main;
Itypes do not have explicit declarations, and they are elaborated in gigi upon
first occurrence. This occurrence must be in the scope of definition. However,
in some cases itypes are generated in one context and only used in a nested
context. To ensure that they are elaborated at the proper place, we generate
an Itype_Reference node in the proper scope. This patch verifies that the
current scope is the proper one for the Itype_Reference. and prevents multiple
definitions that would otherwise lead to link errors.
Compiling and executing p.adb below must produce the output:
X
Y
Y
X
-----
package Vars is
Length : Positive := 1;
end Vars;
with Vars;
package Types is
type Descriptor is record
A : String (1 .. Vars.Length);
B : String (1 .. Vars.Length);
end record;
end Types;
with Types;
package Pkg is
One_Descriptor : Types.Descriptor := (A => "X", B => "Y");
procedure Switch;
end Pkg;
package body Pkg is
procedure Switch is
A : String := One_Descriptor.A;
B : String := One_Descriptor.B;
begin
One_Descriptor.A := B;
One_Descriptor.B := A;
end Switch;
end Pkg;
with Pkg; use Pkg;
with Ada.Text_IO; use Ada.Text_IO;
procedure P is
begin
Put_Line (One_Descriptor.A);
Put_Line (One_Descriptor.B);
Pkg.Switch;
Put_Line (One_Descriptor.A);
Put_Line (One_Descriptor.B);
end;
This patch also fixes a complex interaction between object renaming and removing
side effects when generating access checks. If an object renaming denotes a
component that may be misaligned, it is treated by a macro in the front-end.
However, if part of the renamed object is of an access type that can be
modified through an assignment, subsequent uses of the macro may denote the
wrong object. We must therefore treat the object, or a prefix of it, as
requiring capture in a temporary. Note that removing side effects can itself
generate renaming declarations.
See gnat.dg/renaming2.adb
--
Finally, for an array type whose component type is a character type, an
initial value
can be provided with an aggregate which is then folded into a string literal.
If the array is the expression in an object declaration with an unconstrained
type, the bounds are then obtained from the string. The range expression for
the constraint assumed incorrectly that the index type of the array was an
integer type, leading to spurious errors and/or aborts when the index type
was an enumeration type.
See gnat.dg/bad_array.adb
2007-08-14 Robert Dewar <dewar@adacore.com>
Ed Schonberg <schonberg@adacore.com>
Javier Miranda <miranda@adacore.com>
* exp_util.ads, exp_util.adb:
This patch replaces a number of occurrences of explicit tests for N_Null
with calls to Known_Null. This improves tracking of null values, since
Known_Null also catches null constants, and variables currently known to
be null, so we get better tracking.
(Ensure_Defined): create an itype reference only in the scope of the
itype.
(Side_Effect_Free): A selected component of an access type that
denotes a component with a rep clause must be treated as not
side-effect free, because if it is part of a linked structure its
value may be affected by a renaming.
(Expand_Subtype_From_Expr): For limited objects initialized with build
in place function calls, do nothing; otherwise we prematurely introduce
an N_Reference node in the expression initializing the object, which
breaks the circuitry that detects and adds the additional arguments to
the called function. Bug found working in the new patch for statically
allocated dispatch tables.
(Is_Library_Level_Tagged_Type): New subprogram.
(Remove_Side_Effects): If the expression of an elementary type is an
operator treat as a function call.
(Make_Literal_Range): If the index type of the array is not integer, use
attributes properly to compute the constraint on the resulting aggregate
which is a string.
* freeze.ads, freeze.adb (Freeze_Entity): If the entity is a
class-wide type whose base type is an incomplete private type, leave
class-wide type unfrozen so that freeze nodes can be generated
properly at a later point.
(Freeze_Entity, array case): Handle case of pragma Pack and component
size attributre clause for same array.
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] |