#include "langhooks.h"
#include "langhooks-def.h"
#include "target.h"
+#include "function.h"
#include "stringpool.h"
#include "stor-layout.h"
#include "varasm.h"
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;
}
--- /dev/null
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97002
+// { dg-do compile }
+
+import core.stdc.stdarg;
+
+enum E1 : bool { one, two }
+enum E2 : short { one, two }
+enum E3 : dchar { one, two }
+enum E4 : float { one, two }
+
+extern(C) void fun(void *p1, ...)
+{
+ va_arg!bool(_argptr); // { dg-warning "'bool' is promoted to 'int' when passed through '...'" "promoted" }
+ // { dg-message "note: .so you should pass .int. not .bool. to .va_arg.." "int not bool" { target *-*-* } .-1 }
+ // { dg-message "note: if this code is reached, the program will abort" "will abort" { target *-*-* } .-2 }
+
+ va_arg!byte(_argptr); // { dg-warning "'byte' is promoted to 'int' when passed through '...'" "promoted" }
+ // { dg-message "note: if this code is reached, the program will abort" "will abort" { target *-*-* } .-1 }
+
+ va_arg!ubyte(_argptr); // { dg-warning "'ubyte' is promoted to 'int' when passed through '...'" "promoted" }
+ // { dg-message "note: if this code is reached, the program will abort" "will abort" { target *-*-* } .-1 }
+
+ va_arg!short(_argptr); // { dg-warning "'short' is promoted to 'int' when passed through '...'" "promoted" }
+ // { dg-message "note: if this code is reached, the program will abort" "will abort" { target *-*-* } .-1 }
+
+ va_arg!ushort(_argptr); // { dg-warning "'ushort' is promoted to 'int' when passed through '...'" "promoted" }
+ // { dg-message "note: if this code is reached, the program will abort" "will abort" { target *-*-* } .-1 }
+
+ va_arg!char(_argptr); // { dg-warning "'char' is promoted to 'int' when passed through '...'" "promoted" }
+ // { dg-message "note: if this code is reached, the program will abort" "will abort" { target *-*-* } .-1 }
+
+ va_arg!wchar(_argptr); // { dg-warning "'wchar' is promoted to 'int' when passed through '...'" "promoted" }
+ // { dg-message "note: if this code is reached, the program will abort" "will abort" { target *-*-* } .-1 }
+
+ va_arg!dchar(_argptr); // { dg-warning "'dchar' is promoted to 'uint' when passed through '...'" "promoted" }
+ // { dg-message "note: if this code is reached, the program will abort" "will abort" { target *-*-* } .-1 }
+
+ va_arg!float(_argptr); // { dg-warning "'float' is promoted to 'double' when passed through '...'" "promoted" }
+ // { dg-message "note: if this code is reached, the program will abort" "will abort" { target *-*-* } .-1 }
+
+ va_arg!ifloat(_argptr); // { dg-warning "'ifloat' is promoted to 'idouble' when passed through '...'" "promoted" }
+ // { dg-message "note: if this code is reached, the program will abort" "will abort" { target *-*-* } .-1 }
+
+ va_arg!E1(_argptr); // { dg-warning "'E1' is promoted to 'int' when passed through '...'" "promoted" }
+ // { dg-message "note: if this code is reached, the program will abort" "will abort" { target *-*-* } .-1 }
+
+ va_arg!E2(_argptr); // { dg-warning "'E2' is promoted to 'int' when passed through '...'" "promoted" }
+ // { dg-message "note: if this code is reached, the program will abort" "will abort" { target *-*-* } .-1 }
+
+ va_arg!E3(_argptr); // { dg-warning "'E3' is promoted to 'uint' when passed through '...'" "promoted" }
+ // { dg-message "note: if this code is reached, the program will abort" "will abort" { target *-*-* } .-1 }
+
+ va_arg!E4(_argptr); // { dg-warning "'E4' is promoted to 'double' when passed through '...'" "promoted" }
+ // { dg-message "note: if this code is reached, the program will abort" "will abort" { target *-*-* } .-1 }
+}