Bug #7756

clang 4.2 sees through UNINITIALIZED_VAR macro, gives warning

Added by Eric Hodel about 1 year ago. Updated about 1 year ago.

[ruby-core:51742]
Status:Closed
Priority:Normal
Assignee:Yusuke Endoh
Category:core
Target version:next minor
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 'origread' is uninitialized when
used within its own initialization [-Wuninitialized]
rb
fdsett UNINITIALIZEDVAR(origread);
~~~~~~~~
../trunk/vm
core.h:119:34: note: expanded from macro 'UNINITIALIZEDVAR'
#define UNINITIALIZED
VAR(x) x = x
^
../trunk/thread.c:3262:34: warning: variable 'origwrite' is uninitialized when
used within its own initialization [-Wuninitialized]
rb
fdsett UNINITIALIZEDVAR(origwrite);
~~~~~~~~~
../trunk/vm
core.h:119:34: note: expanded from macro 'UNINITIALIZEDVAR'
#define UNINITIALIZED
VAR(x) x = x
^
../trunk/thread.c:3263:34: warning: variable 'origexcept' is uninitialized when
used within its own initialization [-Wuninitialized]
rb
fdsett UNINITIALIZEDVAR(origexcept);
~~~~~~~~~~
../trunk/vm
core.h:119:34: note: expanded from macro 'UNINITIALIZEDVAR'
#define UNINITIALIZED
VAR(x) x = x
^
3 warnings generated.

=end

Associated revisions

Revision 39855
Added by Nobuyoshi Nakada about 1 year ago

vm_core.h: suppress warnings

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

History

#1 Updated by Motohiro KOSAKI about 1 year ago

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

likes

#ifdef GNUC
#define UNINITIALIZEDVAR(x) x _attribute__ (unused) = x
#else
....

#2 Updated by Eric Hodel about 1 year ago

=begin
This patch works:

Index: vmcore.h
===================================================================
--- vm
core.h (revision 38980)
+++ vmcore.h (working copy)
@@ -116,7 +116,7 @@
#endif /* _
GNUC__ >= 3 */

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

#3 Updated by Koichi Sasada about 1 year ago

  • Assignee set to Yusuke Endoh

mame-san, how about it?

#4 Updated by Yusuke Endoh about 1 year 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 1 year ago

It is only a warning

#6 Updated by Nobuyoshi Nakada about 1 year ago

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

thread.c: In function 'doselect':
thread.c:3155:26: warning: 'orig
except.fdset' may be used uninitialized in this function [-Wmaybe-uninitialized]
thread.c:3352:16: note: 'origexcept.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: 'origexcept.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: 'origwrite.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: 'origwrite.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: 'origread.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 1 year 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 1 year ago

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

#if GCCVERSIONSINCE(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 1 year 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 1 year 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

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

Also available in: Atom PDF