aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/gcc-interface/utils.c
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2018-05-25 09:03:29 +0000
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>2018-05-25 09:03:29 +0000
commit0d0cd28165d05981eadc966224dca77b87111b62 (patch)
treeb393260c4976c48845d0913b4bfd2057209f9bfb /gcc/ada/gcc-interface/utils.c
parent28e3372094a60b1d7fb9d076a29b050761e5692a (diff)
downloadgcc-0d0cd28165d05981eadc966224dca77b87111b62.zip
gcc-0d0cd28165d05981eadc966224dca77b87111b62.tar.gz
gcc-0d0cd28165d05981eadc966224dca77b87111b62.tar.bz2
[Ada] Support for C99 and C++ standard boolean types
This change the type Interfaces.C.Extensions.bool to be fully compatible with the C99 and C++ standard boolean types by making it a fully-fledged boolean type with convention C. The following C+Ada program must compile quietly in LTO mode: bool b; struct S {}; bool foo (struct S *s) { return true; } pragma Ada_2005; pragma Style_Checks (Off); with Interfaces.C; use Interfaces.C; with Interfaces.C.Extensions; package t_c is b : aliased Extensions.bool; -- t.c:3 pragma Import (C, b, "b"); type S is record null; end record; pragma Convention (C_Pass_By_Copy, S); -- t.c:5 function foo (the_s : access S) return Extensions.bool; -- t.c:7 pragma Import (C, foo, "foo"); end t_c; with t_c; use t_c; procedure P_C is Dummy : aliased S; begin b := foo (Dummy'Access); end; 2018-05-25 Eric Botcazou <ebotcazou@adacore.com> gcc/ada/ * freeze.adb (Freeze_Enumeration_Type): Do not give integer size to a boolean type with convention C. * libgnat/i-cexten.ads (bool): Change to boolean with convention C. * gcc-interface/decl.c (gnat_to_gnu_entity): Add new local variable FOREIGN and use it throughout the function. <E_Enumeration_Type>: Set precision 1 on boolean types with foreign convention. <E_Enumeration_Subtype>: Likewise for subtypes. <E_Record_Type>: Force the size of a storage unit on empty classes. * gcc-interface/utils.c (make_type_from_size) <BOOLEAN_TYPE>: Skip boolean types with precision 1 if the size is the expected one. From-SVN: r260721
Diffstat (limited to 'gcc/ada/gcc-interface/utils.c')
-rw-r--r--gcc/ada/gcc-interface/utils.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c
index eb2c257..cc25973 100644
--- a/gcc/ada/gcc-interface/utils.c
+++ b/gcc/ada/gcc-interface/utils.c
@@ -1133,9 +1133,15 @@ make_type_from_size (tree type, tree size_tree, bool for_biased)
switch (TREE_CODE (type))
{
+ case BOOLEAN_TYPE:
+ /* Do not mess with boolean types that have foreign convention. */
+ if (TYPE_PRECISION (type) == 1 && TYPE_SIZE (type) == size_tree)
+ break;
+
+ /* ... fall through ... */
+
case INTEGER_TYPE:
case ENUMERAL_TYPE:
- case BOOLEAN_TYPE:
biased_p = (TREE_CODE (type) == INTEGER_TYPE
&& TYPE_BIASED_REPRESENTATION_P (type));