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]

Re: [patch ada]: Fix boolean_type_node setup and some cleanup for boolean use


> Hmm, sad. As the a check in tree-cfg for truth-expressions about
> having type-precision of 1 would be a good way.  What is actual the
> cause for not setting type-precision here?

But we are setting it:

  /* In Ada, we use an unsigned 8-bit type for the default boolean type.  */
  boolean_type_node = make_unsigned_type (8);
  TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);

See make_unsigned_type:

/* Create and return a type for unsigned integers of PRECISION bits.  */

tree
make_unsigned_type (int precision)
{
  tree type = make_node (INTEGER_TYPE);

  TYPE_PRECISION (type) = precision;

  fixup_unsigned_type (type);
  return type;
}


The other languages are changing the precision, but in Ada we need a standard 
scalar (precision == mode size) in order to support invalid values.

> At least in testcases I didn't found a regression caused by this.

Right, I've just installed the attached testcase, it passes with the unmodified 
compiler but fails with your gcc-interface/misc.c change.


2011-05-17  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/invalid1.adb: New test.


-- 
Eric Botcazou
-- { dg-do run }
-- { dg-options "-gnatws -gnatVa" }

pragma Initialize_Scalars;

procedure Invalid1 is

  X : Boolean;
  A : Boolean := False;

  procedure Uninit (B : out Boolean) is
  begin
    if A then
      B := True;
      raise Program_Error;
    end if;
  end;

begin

  -- first, check that initialize_scalars is enabled
  begin
    if X then
      A := False;
    end if;
    raise Program_Error;
  exception
    when Constraint_Error => null;
  end;

  -- second, check if copyback of an invalid value raises constraint error
  begin
    Uninit (A);
    if A then
      -- we expect constraint error in the 'if' above according to gnat ug:
      -- ....
      -- call.  Note that there is no specific option to test `out'
      -- parameters, but any reference within the subprogram will be tested
      -- in the usual manner, and if an invalid value is copied back, any
      -- reference to it will be subject to validity checking.
      -- ...
      raise Program_Error;
    end if;
    raise Program_Error;
  exception
    when Constraint_Error => null;
  end;

end;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]