Avoid superfluous compiler warnings
GCC warns about uninitialized local variables in cases where no initialization is needed, in particular in the overloads of the 'Capability::call()' function. Prior this patch, we dealt with those warnings by using an (unreliable) GCC pragma or by disabling the particular warning altogether (which is a bad idea). This patch removes the superfluous warnings by telling the compiler that the variable in question is volatile.
This commit is contained in:
parent
f4bc08c16f
commit
64245dde3a
|
@ -151,7 +151,7 @@ void Ipc_server::_prepare_next_reply_wait()
|
||||||
_read_offset = sizeof(long);
|
_read_offset = sizeof(long);
|
||||||
|
|
||||||
/* read client thread id from request buffer */
|
/* read client thread id from request buffer */
|
||||||
long tid;
|
long tid = 0;
|
||||||
if (_reply_needed) {
|
if (_reply_needed) {
|
||||||
_read_from_buf(tid);
|
_read_from_buf(tid);
|
||||||
Ipc_ostream::_dst = Native_capability(tid, 0); /* only _tid member is used */
|
Ipc_ostream::_dst = Native_capability(tid, 0); /* only _tid member is used */
|
||||||
|
|
|
@ -134,6 +134,27 @@ namespace Genode {
|
||||||
*/
|
*/
|
||||||
Capability(void *ptr) : Untyped_capability(ptr) {}
|
Capability(void *ptr) : Untyped_capability(ptr) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper for the return type instantiated by 'call' overloads
|
||||||
|
*
|
||||||
|
* Each 'call' overload creates an instance of the return value
|
||||||
|
* type as local variable. A reference to this variable is passed
|
||||||
|
* to the '_call' function, which will assign its value. Even
|
||||||
|
* though the variable does not need to be initialized prior the
|
||||||
|
* call of '_call', the GCC will still complain "warning: ‘ret’ may
|
||||||
|
* be used uninitialized in this function". Wrapping the return
|
||||||
|
* value in a struct silences the compiler.
|
||||||
|
*/
|
||||||
|
template <typename IF>
|
||||||
|
struct Return
|
||||||
|
{
|
||||||
|
typedef typename Trait::Call_return<typename IF::Ret_type>::Type
|
||||||
|
Return_type;
|
||||||
|
|
||||||
|
volatile Return_type _value;
|
||||||
|
Return_type &value() { return *(Return_type *)(&_value); }
|
||||||
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef RPC_INTERFACE Rpc_interface;
|
typedef RPC_INTERFACE Rpc_interface;
|
||||||
|
@ -178,24 +199,14 @@ namespace Genode {
|
||||||
static RPC_INTERFACE* deref(Capability<RPC_INTERFACE> c) {
|
static RPC_INTERFACE* deref(Capability<RPC_INTERFACE> c) {
|
||||||
return reinterpret_cast<RPC_INTERFACE*>(c.local()); }
|
return reinterpret_cast<RPC_INTERFACE*>(c.local()); }
|
||||||
|
|
||||||
/*
|
|
||||||
* Suppress warning about uninitialized 'ret' variable in 'call'
|
|
||||||
* functions on compilers that support the #pragma. If this is
|
|
||||||
* not the case, the pragma can be masked by supplying the
|
|
||||||
* 'SUPPRESS_GCC_PRAGMA_WUNINITIALIZED' define to the compiler.
|
|
||||||
*/
|
|
||||||
#ifndef SUPPRESS_GCC_PRAGMA_WUNINITIALIZED
|
|
||||||
#pragma GCC diagnostic ignored "-Wuninitialized" call();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
template <typename IF>
|
template <typename IF>
|
||||||
typename Trait::Call_return<typename IF::Ret_type>::Type
|
typename Trait::Call_return<typename IF::Ret_type>::Type
|
||||||
call() const
|
call() const
|
||||||
{
|
{
|
||||||
Meta::Empty e;
|
Meta::Empty e;
|
||||||
typename Trait::Call_return<typename IF::Ret_type>::Type ret;
|
Return<IF> ret;
|
||||||
_call<IF>(e, ret);
|
_call<IF>(e, ret.value());
|
||||||
return ret;
|
return ret.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename IF>
|
template <typename IF>
|
||||||
|
@ -204,9 +215,9 @@ namespace Genode {
|
||||||
{
|
{
|
||||||
Meta::Empty e;
|
Meta::Empty e;
|
||||||
typename IF::Client_args args(v1, e);
|
typename IF::Client_args args(v1, e);
|
||||||
typename Trait::Call_return<typename IF::Ret_type>::Type ret;
|
Return<IF> ret;
|
||||||
_call<IF>(args, ret);
|
_call<IF>(args, ret.value());
|
||||||
return ret;
|
return ret.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename IF>
|
template <typename IF>
|
||||||
|
@ -215,9 +226,9 @@ namespace Genode {
|
||||||
{
|
{
|
||||||
Meta::Empty e;
|
Meta::Empty e;
|
||||||
typename IF::Client_args args(v1, v2, e);
|
typename IF::Client_args args(v1, v2, e);
|
||||||
typename Trait::Call_return<typename IF::Ret_type>::Type ret;
|
Return<IF> ret;
|
||||||
_call<IF>(args, ret);
|
_call<IF>(args, ret.value());
|
||||||
return ret;
|
return ret.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename IF>
|
template <typename IF>
|
||||||
|
@ -227,9 +238,9 @@ namespace Genode {
|
||||||
{
|
{
|
||||||
Meta::Empty e;
|
Meta::Empty e;
|
||||||
typename IF::Client_args args(v1, v2, v3, e);
|
typename IF::Client_args args(v1, v2, v3, e);
|
||||||
typename Trait::Call_return<typename IF::Ret_type>::Type ret;
|
Return<IF> ret;
|
||||||
_call<IF>(args, ret);
|
_call<IF>(args, ret.value());
|
||||||
return ret;
|
return ret.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename IF>
|
template <typename IF>
|
||||||
|
@ -239,9 +250,9 @@ namespace Genode {
|
||||||
{
|
{
|
||||||
Meta::Empty e;
|
Meta::Empty e;
|
||||||
typename IF::Client_args args(v1, v2, v3, v4, e);
|
typename IF::Client_args args(v1, v2, v3, v4, e);
|
||||||
typename Trait::Call_return<typename IF::Ret_type>::Type ret;
|
Return<IF> ret;
|
||||||
_call<IF>(args, ret);
|
_call<IF>(args, ret.value());
|
||||||
return ret;
|
return ret.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename IF>
|
template <typename IF>
|
||||||
|
@ -252,9 +263,9 @@ namespace Genode {
|
||||||
{
|
{
|
||||||
Meta::Empty e;
|
Meta::Empty e;
|
||||||
typename IF::Client_args args(v1, v2, v3, v4, v5, e);
|
typename IF::Client_args args(v1, v2, v3, v4, v5, e);
|
||||||
typename Trait::Call_return<typename IF::Ret_type>::Type ret;
|
Return<IF> ret;
|
||||||
_call<IF>(args, ret);
|
_call<IF>(args, ret.value());
|
||||||
return ret;
|
return ret.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename IF>
|
template <typename IF>
|
||||||
|
@ -265,9 +276,9 @@ namespace Genode {
|
||||||
{
|
{
|
||||||
Meta::Empty e;
|
Meta::Empty e;
|
||||||
typename IF::Client_args args(v1, v2, v3, v4, v5, v6, e);
|
typename IF::Client_args args(v1, v2, v3, v4, v5, v6, e);
|
||||||
typename Trait::Call_return<typename IF::Ret_type>::Type ret;
|
Return<IF> ret;
|
||||||
_call<IF>(args, ret);
|
_call<IF>(args, ret.value());
|
||||||
return ret;
|
return ret.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename IF>
|
template <typename IF>
|
||||||
|
@ -279,9 +290,9 @@ namespace Genode {
|
||||||
{
|
{
|
||||||
Meta::Empty e;
|
Meta::Empty e;
|
||||||
typename IF::Client_args args(v1, v2, v3, v4, v5, v6, v7, e);
|
typename IF::Client_args args(v1, v2, v3, v4, v5, v6, v7, e);
|
||||||
typename Trait::Call_return<typename IF::Ret_type>::Type ret;
|
Return<IF> ret;
|
||||||
_call<IF>(args, ret);
|
_call<IF>(args, ret.value());
|
||||||
return ret;
|
return ret.value();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,3 @@ SRC_CC = main.cc services.cc
|
||||||
INC_DIR += $(REP_DIR)/src/app/scout/include \
|
INC_DIR += $(REP_DIR)/src/app/scout/include \
|
||||||
$(REP_DIR)/src/app/scout/include/genode \
|
$(REP_DIR)/src/app/scout/include/genode \
|
||||||
$(REP_DIR)/src/server/framebuffer/sdl
|
$(REP_DIR)/src/server/framebuffer/sdl
|
||||||
|
|
||||||
# suppress non-critical but weird compiler warning, probably a bug in gcc-4.6.1
|
|
||||||
CC_OPT_main += -Wno-uninitialized
|
|
||||||
|
|
|
@ -2,5 +2,3 @@ TARGET = test-python
|
||||||
LIBS = cxx env python libc libc_log libm
|
LIBS = cxx env python libc libc_log libm
|
||||||
REQUIRES = x86
|
REQUIRES = x86
|
||||||
SRC_CC = main.cc
|
SRC_CC = main.cc
|
||||||
|
|
||||||
CC_OPT_main = -Wno-uninitialized
|
|
||||||
|
|
|
@ -2,18 +2,3 @@ TARGET = chroot
|
||||||
REQUIRES = linux
|
REQUIRES = linux
|
||||||
SRC_CC = main.cc
|
SRC_CC = main.cc
|
||||||
LIBS = cxx env server lx_hybrid
|
LIBS = cxx env server lx_hybrid
|
||||||
|
|
||||||
#
|
|
||||||
# XXX find a way to remove superfluous warning:
|
|
||||||
#
|
|
||||||
# base/include/util/token.h: In constructor ‘Genode::Config::Config()’:
|
|
||||||
# base/include/util/token.h:69:67: warning: ‘ret’ may be used uninitialized in
|
|
||||||
# this function [-Wuninitialized]
|
|
||||||
# base/include/base/capability.h:196:62: note: ‘ret’ was declared here
|
|
||||||
# base/include/util/token.h:100:68: warning: ‘prephitmp.1897’ may be used
|
|
||||||
# uninitialized in this function
|
|
||||||
# [-Wuninitialized]
|
|
||||||
# os/include/os/config.h:42:4: note: ‘prephitmp.1897’ was declared here
|
|
||||||
#
|
|
||||||
CC_WARN = -Wall -Wno-uninitialized
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue