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:
Norman Feske 2012-10-05 15:42:32 +02:00
parent f4bc08c16f
commit 64245dde3a
5 changed files with 46 additions and 55 deletions

View File

@ -151,7 +151,7 @@ void Ipc_server::_prepare_next_reply_wait()
_read_offset = sizeof(long);
/* read client thread id from request buffer */
long tid;
long tid = 0;
if (_reply_needed) {
_read_from_buf(tid);
Ipc_ostream::_dst = Native_capability(tid, 0); /* only _tid member is used */

View File

@ -134,6 +134,27 @@ namespace Genode {
*/
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:
typedef RPC_INTERFACE Rpc_interface;
@ -178,24 +199,14 @@ namespace Genode {
static RPC_INTERFACE* deref(Capability<RPC_INTERFACE> c) {
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>
typename Trait::Call_return<typename IF::Ret_type>::Type
call() const
{
Meta::Empty e;
typename Trait::Call_return<typename IF::Ret_type>::Type ret;
_call<IF>(e, ret);
return ret;
Return<IF> ret;
_call<IF>(e, ret.value());
return ret.value();
}
template <typename IF>
@ -204,9 +215,9 @@ namespace Genode {
{
Meta::Empty e;
typename IF::Client_args args(v1, e);
typename Trait::Call_return<typename IF::Ret_type>::Type ret;
_call<IF>(args, ret);
return ret;
Return<IF> ret;
_call<IF>(args, ret.value());
return ret.value();
}
template <typename IF>
@ -215,9 +226,9 @@ namespace Genode {
{
Meta::Empty e;
typename IF::Client_args args(v1, v2, e);
typename Trait::Call_return<typename IF::Ret_type>::Type ret;
_call<IF>(args, ret);
return ret;
Return<IF> ret;
_call<IF>(args, ret.value());
return ret.value();
}
template <typename IF>
@ -227,9 +238,9 @@ namespace Genode {
{
Meta::Empty e;
typename IF::Client_args args(v1, v2, v3, e);
typename Trait::Call_return<typename IF::Ret_type>::Type ret;
_call<IF>(args, ret);
return ret;
Return<IF> ret;
_call<IF>(args, ret.value());
return ret.value();
}
template <typename IF>
@ -239,9 +250,9 @@ namespace Genode {
{
Meta::Empty e;
typename IF::Client_args args(v1, v2, v3, v4, e);
typename Trait::Call_return<typename IF::Ret_type>::Type ret;
_call<IF>(args, ret);
return ret;
Return<IF> ret;
_call<IF>(args, ret.value());
return ret.value();
}
template <typename IF>
@ -252,9 +263,9 @@ namespace Genode {
{
Meta::Empty e;
typename IF::Client_args args(v1, v2, v3, v4, v5, e);
typename Trait::Call_return<typename IF::Ret_type>::Type ret;
_call<IF>(args, ret);
return ret;
Return<IF> ret;
_call<IF>(args, ret.value());
return ret.value();
}
template <typename IF>
@ -265,9 +276,9 @@ namespace Genode {
{
Meta::Empty e;
typename IF::Client_args args(v1, v2, v3, v4, v5, v6, e);
typename Trait::Call_return<typename IF::Ret_type>::Type ret;
_call<IF>(args, ret);
return ret;
Return<IF> ret;
_call<IF>(args, ret.value());
return ret.value();
}
template <typename IF>
@ -279,9 +290,9 @@ namespace Genode {
{
Meta::Empty e;
typename IF::Client_args args(v1, v2, v3, v4, v5, v6, v7, e);
typename Trait::Call_return<typename IF::Ret_type>::Type ret;
_call<IF>(args, ret);
return ret;
Return<IF> ret;
_call<IF>(args, ret.value());
return ret.value();
}
};

View File

@ -4,6 +4,3 @@ SRC_CC = main.cc services.cc
INC_DIR += $(REP_DIR)/src/app/scout/include \
$(REP_DIR)/src/app/scout/include/genode \
$(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

View File

@ -2,5 +2,3 @@ TARGET = test-python
LIBS = cxx env python libc libc_log libm
REQUIRES = x86
SRC_CC = main.cc
CC_OPT_main = -Wno-uninitialized

View File

@ -2,18 +2,3 @@ TARGET = chroot
REQUIRES = linux
SRC_CC = main.cc
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