Bug #7756

clang 4.2 sees through UNINITIALIZED_VAR macro, gives warning

Added by Eric Hodel about 2 years ago. Updated about 2 years ago.

[ruby-core:51742]
Status:Closed
Priority:Normal
Assignee:Yusuke Endoh
ruby -v:- Backport:

Description

=begin

In clang 3.2, the UNINITIALIZED_VAR macro does not prevent the compiler from producing a warning.

Apple clang 3.2:

$ clang -v
Apple LLVM version 4.2 (clang-425.0.24) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin12.2.1
Thread model: posix

When compiling thread.c:

compiling ../trunk/thread.c
../trunk/thread.c:3261:34: warning: variable 'orig_read' is uninitialized when
used within its own initialization [-Wuninitialized]
rb_fdset_t UNINITIALIZED_VAR(orig_read);
~~~~~~~~
../trunk/vm_core.h:119:34: note: expanded from macro 'UNINITIALIZED_VAR'
#define UNINITIALIZED_VAR(x) x = x
^
../trunk/thread.c:3262:34: warning: variable 'orig_write' is uninitialized when
used within its own initialization [-Wuninitialized]
rb_fdset_t UNINITIALIZED_VAR(orig_write);
~~~~~~~~~
../trunk/vm_core.h:119:34: note: expanded from macro 'UNINITIALIZED_VAR'
#define UNINITIALIZED_VAR(x) x = x
^
../trunk/thread.c:3263:34: warning: variable 'orig_except' is uninitialized when
used within its own initialization [-Wuninitialized]
rb_fdset_t UNINITIALIZED_VAR(orig_except);
~~~~~~~~~~
../trunk/vm_core.h:119:34: note: expanded from macro 'UNINITIALIZED_VAR'
#define UNINITIALIZED_VAR(x) x = x
^
3 warnings generated.

=end

Associated revisions

Revision 39855
Added by Nobuyoshi Nakada about 2 years ago

vm_core.h: suppress warnings

  • vm_core.h (UNINITIALIZED_VAR): suppress warnings by clang 4.2. [Bug #7756]

Revision 39855
Added by Nobuyoshi Nakada about 2 years ago

vm_core.h: suppress warnings

  • vm_core.h (UNINITIALIZED_VAR): suppress warnings by clang 4.2. [Bug #7756]

History

#1 Updated by Motohiro KOSAKI about 2 years ago

Hm, maybe we need another workaround.
Does attribute (unused) works on your compiler?

likes

#ifdef GNUC
#define UNINITIALIZED_VAR(x) x attribute (unused) = x
#else
....

#2 Updated by Eric Hodel about 2 years ago

=begin
This patch works:

Index: vm_core.h
===================================================================
--- vm_core.h (revision 38980)
+++ vm_core.h (working copy)
@@ -116,7 +116,7 @@
#endif /* GNUC >= 3 */

#if GNUC >= 3
-#define UNINITIALIZED_VAR(x) x = x
+#define UNINITIALIZED_VAR(x) x attribute((unused))
#else
#define UNINITIALIZED_VAR(x) x
#endif
=end

#3 Updated by Koichi Sasada about 2 years ago

  • Assignee set to Yusuke Endoh

mame-san, how about it?

#4 Updated by Yusuke Endoh about 2 years ago

  • Target version changed from 2.0.0 to next minor

It emits just a warning, not an error, right?
Looks not significant.

Yusuke Endoh mame@tsg.ne.jp

#5 Updated by Eric Hodel about 2 years ago

It is only a warning

#6 Updated by Nobuyoshi Nakada about 2 years ago

=begin
Unfortunately, it doesn't shut up gcc-4.7.

thread.c: In function 'do_select':
thread.c:3155:26: warning: 'orig_except.fdset' may be used uninitialized in this function [-Wmaybe-uninitialized]
thread.c:3352:16: note: 'orig_except.fdset' was declared here
thread.c:3229:19: warning: 'orig_except.maxfd' may be used uninitialized in this function [-Wmaybe-uninitialized]
thread.c:3352:16: note: 'orig_except.maxfd' was declared here
thread.c:3155:26: warning: 'orig_write.fdset' may be used uninitialized in this function [-Wmaybe-uninitialized]
thread.c:3351:16: note: 'orig_write.fdset' was declared here
thread.c:3229:19: warning: 'orig_write.maxfd' may be used uninitialized in this function [-Wmaybe-uninitialized]
thread.c:3351:16: note: 'orig_write.maxfd' was declared here
thread.c:3155:26: warning: 'orig_read.fdset' may be used uninitialized in this function [-Wmaybe-uninitialized]
thread.c:3350:16: note: 'orig_read.fdset' was declared here
thread.c:3229:19: warning: 'orig_read.maxfd' may be used uninitialized in this function [-Wmaybe-uninitialized]
thread.c:3350:16: note: 'orig_read.maxfd' was declared here
=end

#7 Updated by Yui NARUSE about 2 years ago

GCC 4.6 and clang (2.8?) supports pragma diagnostic, but its syntax is different from current UNINITIALIZED_VAR().

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wuninitialized"
blah blah
#pragma GCC diagnostic pop

http://gcc.gnu.org/gcc-4.6/changes.html
http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html
http://clang.llvm.org/docs/UsersManual.html#controlling-diagnostics-via-pragmas

#8 Updated by Yui NARUSE about 2 years ago

A macro can be following, but it still changes syntax from current UNINITIALIZED_VAR.

#if GCC_VERSION_SINCE(4,6,0) || defined(clang)

define SUPPRESS_DIAGNOSTIC(arg,rest) \

    _Pragma("GCC diagnostic push") \
    _Pragma(STRINGIZE(GCC diagnostic ignored arg)) \
    rest \
    _Pragma("GCC diagnostic pop")

#else

define SUPPRESS_DIAGNOSTIC(arg,rest) rest

#endif

#9 Updated by Nobuyoshi Nakada about 2 years ago

  • Subject changed from clang 3.2 sees through UNINITIALIZED_VAR macro, gives warning to clang 4.2 sees through UNINITIALIZED_VAR macro, gives warning

#10 Updated by Nobuyoshi Nakada about 2 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r39855.
Eric, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


vm_core.h: suppress warnings

  • vm_core.h (UNINITIALIZED_VAR): suppress warnings by clang 4.2. [Bug #7756]

Also available in: Atom PDF