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]

[Ada] Fix wrong size computation with boolean discriminant


This is a regression present on the mainline and caused by the wrong handling 
of TRUTH_NOT_EXPR by the max_size function.

Tested on x86_64-suse-linux, applied on the mainline.


2017-02-24  Eric Botcazou  <ebotcazou@adacore.com>

	* gcc-interface/utils.c (max_size) <tcc_expression>: Flip the second
	argument when recursing on TRUTH_NOT_EXPR.


2017-02-24  Eric Botcazou  <ebotcazou@adacore.com>

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

-- 
Eric Botcazou
Index: gcc-interface/utils.c
===================================================================
--- gcc-interface/utils.c	(revision 245625)
+++ gcc-interface/utils.c	(working copy)
@@ -3635,7 +3635,8 @@ max_size (tree exp, bool max_p)
 	    return exp;
 
 	  return fold_build1 (code, type,
-			      max_size (TREE_OPERAND (exp, 0), max_p));
+			      max_size (TREE_OPERAND (exp, 0),
+			      code == TRUTH_NOT_EXPR ? !max_p : max_p));
 
 	case 2:
 	  if (code == COMPOUND_EXPR)
-- { dg-do run }
-- { dg-options "-O -gnatws" }

procedure Discr47 is

  type Rec (D : Boolean := False) is record
    case D is
      when True => null;
      when False => C : Character;
    end case;
  end record;

  R : Rec;

begin
  if R'Size /= 16 then
    raise Program_Error;
  end if;
end;

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