diff options
author | Iain Buclaw <ibuclaw@gdcproject.org> | 2020-09-12 16:48:58 +0200 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gdcproject.org> | 2020-09-12 21:34:38 +0200 |
commit | 707e9159ed25d19c174e4da18b194e530878d450 (patch) | |
tree | c28d409b32c482ff55965576c1198b0a1568d3d2 /gcc/d/d-lang.cc | |
parent | e4011c13c1f8d51f00af61bcb8189bcbe45823b7 (diff) | |
download | gcc-707e9159ed25d19c174e4da18b194e530878d450.zip gcc-707e9159ed25d19c174e4da18b194e530878d450.tar.gz gcc-707e9159ed25d19c174e4da18b194e530878d450.tar.bz2 |
d: Return promoted types in d_type_promotes_to when linkage is not D
This enables warnings to be shown when a bad type is passed to va_arg
inside an extern(C) or extern(C++) function.
gcc/d/ChangeLog:
PR d/97002
* d-codegen.cc (d_build_call): Set input_location on CALL_EXPR.
* d-lang.cc: Include function.h.
(d_type_promotes_to): Do default conversions for C and C++ functions.
* intrinsics.cc (expand_intrinsic_vaarg): Use build1_loc to build
VA_ARG_EXPR.
gcc/testsuite/ChangeLog:
PR d/97002
* gdc.dg/pr97002.d: New test.
Diffstat (limited to 'gcc/d/d-lang.cc')
-rw-r--r-- | gcc/d/d-lang.cc | 58 |
1 files changed, 56 insertions, 2 deletions
diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc index c5254a0..fb95716 100644 --- a/gcc/d/d-lang.cc +++ b/gcc/d/d-lang.cc @@ -43,6 +43,7 @@ along with GCC; see the file COPYING3. If not see #include "langhooks.h" #include "langhooks-def.h" #include "target.h" +#include "function.h" #include "stringpool.h" #include "stor-layout.h" #include "varasm.h" @@ -1358,12 +1359,65 @@ d_type_for_size (unsigned bits, int unsignedp) return 0; } -/* Implements the lang_hooks.types.type_promotes_to routine for language D. - All promotions for variable arguments are handled by the D frontend. */ +/* Implements the lang_hooks.types.type_promotes_to routine for language D. */ static tree d_type_promotes_to (tree type) { + /* Promotions are only applied on unnamed function arguments for declarations + with `extern(C)' or `extern(C++)' linkage. */ + if (cfun && DECL_LANG_FRONTEND (cfun->decl) + && DECL_LANG_FRONTEND (cfun->decl)->linkage != LINKd) + { + /* In [type/integer-promotions], integer promotions are conversions of the + following types: + + bool int + byte int + ubyte int + short int + ushort int + char int + wchar int + dchar uint + + If an enum has as a base type one of the types in the left column, it + is converted to the type in the right column. */ + if (TREE_CODE (type) == ENUMERAL_TYPE && ENUM_IS_SCOPED (type)) + type = TREE_TYPE (type); + + type = TYPE_MAIN_VARIANT (type); + + /* Check for promotions of target-defined types first. */ + tree promoted_type = targetm.promoted_type (type); + if (promoted_type) + return promoted_type; + + if (TREE_CODE (type) == BOOLEAN_TYPE) + return d_int_type; + + if (INTEGRAL_TYPE_P (type)) + { + if (type == d_byte_type || type == d_ubyte_type + || type == d_short_type || type == d_ushort_type + || type == char8_type_node || type == char16_type_node) + return d_int_type; + + if (type == char32_type_node) + return d_uint_type; + + if (TYPE_PRECISION (type) < TYPE_PRECISION (d_int_type)) + return d_int_type; + } + + /* Float arguments are converted to doubles. */ + if (type == float_type_node) + return double_type_node; + + if (type == ifloat_type_node) + return idouble_type_node; + } + return type; } |