[Openmp-commits] [PATCH] D22427: Replace enum types in variadic functions by build-in types.
Samuel Antao via Openmp-commits
openmp-commits at lists.llvm.org
Fri Jul 15 15:32:17 PDT 2016
sfantao created this revision.
sfantao added reviewers: tlwilmar, jlpeyton, AndreyChurbanov.
sfantao added subscribers: openmp-commits, caomhin, carlo.bertolli, arpith-jacob.
When compiling the runtime library with clang we get warnings like:
error: passing an object that undergoes default argument promotion to 'va_start' has undefined behavior [-Werror,-Wvarargs]
va_start( args, id );
^
note: parameter of type 'kmp_i18n_id_t' (aka 'kmp_i18n_id') is declared here
kmp_i18n_id_t id,
My understanding is that the va_start macro only gets the promoted type so it won't know what was the exact type of the argument, which can potentially not work for some targets given that the implementation of the the calling convention could not be done properly.
This patch fixes that by using a built-in type in the function signature.
https://reviews.llvm.org/D22427
Files:
runtime/src/kmp_i18n.c
runtime/src/kmp_i18n.h
runtime/src/thirdparty/ittnotify/ittnotify_static.c
Index: runtime/src/thirdparty/ittnotify/ittnotify_static.c
===================================================================
--- runtime/src/thirdparty/ittnotify/ittnotify_static.c
+++ runtime/src/thirdparty/ittnotify/ittnotify_static.c
@@ -285,10 +285,16 @@
#pragma warning(disable: 4055) /* warning C4055: 'type cast' : from data pointer 'void *' to function pointer 'XXX' */
#endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
-static void __itt_report_error(__itt_error_code code, ...)
+static void __itt_report_error(unsigned code_arg, ...)
{
va_list args;
- va_start(args, code);
+ va_start(args, code_arg);
+
+ // We use unsigned for the code argument and explicitly cast it here to the
+ // right enumerator because variadic functions are not compatible with
+ // default promotions.
+ __itt_error_code code = (__itt_error_code)code_arg;
+
if (_N_(_ittapi_global).error_handler != NULL)
{
__itt_error_handler_t* handler = (__itt_error_handler_t*)(size_t)_N_(_ittapi_global).error_handler;
Index: runtime/src/kmp_i18n.h
===================================================================
--- runtime/src/kmp_i18n.h
+++ runtime/src/kmp_i18n.h
@@ -128,7 +128,7 @@
// Helper functions. Creates messages either from message catalog or from system. Note: these
// functions allocate memory. You should pass created messages to __kmp_msg() function, it will
// print messages and destroy them.
-kmp_msg_t __kmp_msg_format( kmp_i18n_id_t id, ... );
+kmp_msg_t __kmp_msg_format( unsigned id_arg, ... );
kmp_msg_t __kmp_msg_error_code( int code );
kmp_msg_t __kmp_msg_error_mesg( char const * mesg );
Index: runtime/src/kmp_i18n.c
===================================================================
--- runtime/src/kmp_i18n.c
+++ runtime/src/kmp_i18n.c
@@ -703,16 +703,22 @@
kmp_msg_t
__kmp_msg_format(
- kmp_i18n_id_t id,
+ unsigned id_arg,
...
) {
kmp_msg_t msg;
va_list args;
kmp_str_buf_t buffer;
__kmp_str_buf_init( & buffer );
- va_start( args, id );
+ va_start( args, id_arg );
+
+ // We use unsigned for the ID argument and explicitly cast it here to the
+ // right enumerator because variadic functions are not compatible with
+ // default promotions.
+ kmp_i18n_id_t id = (kmp_i18n_id_t)id_arg;
+
#if KMP_OS_UNIX
// On Linux* OS and OS X*, printf() family functions process parameter numbers, for example:
// "%2$s %1$s".
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22427.64200.patch
Type: text/x-patch
Size: 2476 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20160715/bef5d4f3/attachment.bin>
More information about the Openmp-commits
mailing list