Bug 1250848

Summary: Missing compiler warnings from GLib runtime check macros
Product: [Fedora] Fedora Reporter: Milan Crha <mcrha>
Component: glib2Assignee: Matthias Clasen <mclasen>
Status: CLOSED UPSTREAM QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 22CC: davejohansen, jakub, jwakely, lantw44, law, mclasen, mpolacek
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-08-06 08:51:45 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
test.c none

Description Milan Crha 2015-08-06 07:09:37 UTC
Created attachment 1059733 [details]
test.c

Please see the attached test.c file. There are three types of functions, which should produce the same compiler warnings about function return values, but they do not. I do not understand why. The first line contains a command line to compile the code.

The first set of functions, prefixed with "direct_", uses direct 'return' statements, which gcc catches nicely and warns about issues.

The second set of functions, prefixed with "macro_", uses GLib's g_return{_val}_if_fail() macros, in the same way as the "direct_" functions, thus I expect to be warned about them. I get no warning here.

The last function, my_macro_missing_return_func(), uses cop&pasted g_return_if_fail() macro from /usr/include/glib-2.0/glib/gmessages.h, only renamed to my_return_if_fail(), about which the gcc claims the compiler warning, just as expected.

As the macro expansion works in case of the last function, I expect it to work the same in the second set of functions, but it doesn't. I know the macros are used, because I see the warnings in the runtime.

$ gcc --version
gcc (GCC) 5.1.1 20150618 (Red Hat 5.1.1-4)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Comment 1 Milan Crha 2015-08-06 07:15:59 UTC
There is a comment at [1]:
> I found glib/gmessages.h contains this:
>
> /* Suppress warnings when GCC is in -pedantic mode and not -std=c99 */
> #if (__GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96))
> #pragma GCC system_header
> #endif
>
>
> so warnings caused by g_return_if_fail and g_return_val_if_fail are suppressed.

but even if I add -pedantic and -std=c99 into the command line, then I'm not warned during the compile time. (Why would anyone disable these warnings anyway?)

[1] https://bugzilla.gnome.org/show_bug.cgi?id=753276#c5

Comment 2 Milan Crha 2015-08-06 07:18:57 UTC
(In reply to Milan Crha from comment #1)
> but even if I add -pedantic and -std=c99 into the command line, then I'm not
> warned during the compile time.

It might be just other compiler flags to enable the warnings, because if I manually disable the quoted code then the warnings are shown as expected.

Comment 3 Milan Crha 2015-08-06 08:51:45 UTC
Thinking of it, it's glib's issue, the check doesn't seem to do what it claims to do, thus let's move this upstream:
https://bugzilla.gnome.org/show_bug.cgi?id=753310