utils2.c (build_binary_op): If operation's type is an enumeral or a boolean type...
authorEric Botcazou <ebotcazou@adacore.com>
Wed, 22 Apr 2009 22:32:54 +0000 (22:32 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Wed, 22 Apr 2009 22:32:54 +0000 (22:32 +0000)
* gcc-interface/utils2.c (build_binary_op) <PLUS_EXPR>: If operation's
type is an enumeral or a boolean type, change it to an integer type
with the same mode and signedness.

From-SVN: r146625

gcc/ada/ChangeLog
gcc/ada/gcc-interface/utils2.c
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/enum2.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/enum2_pkg.ads [new file with mode: 0644]

index acdc11cfc851f6d6a5c614a33509d167c855b6f9..6f31942e86923414c26b096b41f29ce3f8adfa57 100644 (file)
@@ -1,3 +1,9 @@
+2009-04-22  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gcc-interface/utils2.c (build_binary_op) <PLUS_EXPR>: If operation's
+       type is an enumeral or a boolean type, change it to an integer type
+       with the same mode and signedness.
+
 2009-04-22  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gcc-interface/utils.c (create_var_decl_1): Do not emit debug info
index 77a0389674d4789066f452b39f1388ac72aa0d66..d6b7d684de7d358b6a2b509be8db5def275ef5a7 100644 (file)
@@ -6,7 +6,7 @@
  *                                                                          *
  *                          C Implementation File                           *
  *                                                                          *
- *          Copyright (C) 1992-2008, Free Software Foundation, Inc.         *
+ *          Copyright (C) 1992-2009, Free Software Foundation, Inc.         *
  *                                                                          *
  * GNAT is free software;  you can  redistribute it  and/or modify it under *
  * terms of the  GNU General Public License as published  by the Free Soft- *
@@ -1010,11 +1010,15 @@ build_binary_op (enum tree_code op_code, tree result_type,
 
     case PLUS_EXPR:
     case MINUS_EXPR:
-      /* Avoid doing arithmetics in BOOLEAN_TYPE like the other compilers.
-        Contrary to C, Ada doesn't allow arithmetics in Standard.Boolean
-        but we can generate addition or subtraction for 'Succ and 'Pred.  */
-      if (operation_type && TREE_CODE (operation_type) == BOOLEAN_TYPE)
-       operation_type = left_base_type = right_base_type = integer_type_node;
+      /* Avoid doing arithmetics in ENUMERAL_TYPE or BOOLEAN_TYPE like the
+        other compilers.  Contrary to C, Ada doesn't allow arithmetics in
+        these types but can generate addition/subtraction for Succ/Pred.  */
+      if (operation_type
+         && (TREE_CODE (operation_type) == ENUMERAL_TYPE
+             || TREE_CODE (operation_type) == BOOLEAN_TYPE))
+       operation_type = left_base_type = right_base_type
+         = gnat_type_for_mode (TYPE_MODE (operation_type),
+                               TYPE_UNSIGNED (operation_type));
 
       /* ... fall through ... */
 
@@ -2199,7 +2203,7 @@ fill_vms_descriptor (tree expr, Entity_Id gnat_formal, Node_Id gnat_actual)
          add_stmt (build3 (COND_EXPR, void_type_node,
                            build_binary_op (GE_EXPR, long_integer_type_node,
                                             convert (long_integer_type_node,
-                                                     addr64expr), 
+                                                     addr64expr),
                                             malloc64low),
                            build_call_raise (CE_Range_Check_Failed, gnat_actual,
                                              N_Raise_Constraint_Error),
index 7af7fccfe0206ce6215f4c53c4f7f3c3ee7c0b36..8002f79601a16a306abb970c79a11428baf05fd9 100644 (file)
@@ -1,3 +1,8 @@
+2009-04-22  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/enum2.adb: New test.
+       * gnat.dg/enum2_pkg.ads: New helper.
+
 2009-04-22  Jakub Jelinek  <jakub@redhat.com>
 
        PR c/39855
diff --git a/gcc/testsuite/gnat.dg/enum2.adb b/gcc/testsuite/gnat.dg/enum2.adb
new file mode 100644 (file)
index 0000000..e98252a
--- /dev/null
@@ -0,0 +1,11 @@
+-- { dg-do run }
+-- { dg-options "-gnat05 -O2" }
+
+with Enum2_Pkg; use Enum2_Pkg;
+
+procedure Enum2 is
+  type Enum is (A, B, C, D);
+  Table : array (B .. C, 1 .. 1) of F_String := (others => (others => Null_String));
+begin
+  Table := (others => (others => Null_String));
+end;
diff --git a/gcc/testsuite/gnat.dg/enum2_pkg.ads b/gcc/testsuite/gnat.dg/enum2_pkg.ads
new file mode 100644 (file)
index 0000000..20112d2
--- /dev/null
@@ -0,0 +1,8 @@
+with Ada.Finalization; use Ada.Finalization;
+
+package Enum2_Pkg is
+  type F_String is new Controlled with record
+    Data : access String;
+  end record;
+  Null_String : constant F_String := (Controlled with Data => null);
+end Enum2_Pkg;