Re: [spice-common v2 8/8] log: Let gcc know about the logging macros which abort

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Mar 29, 2019 at 06:51:54AM -0400, Frediano Ziglio wrote:
> > 
> > Without the added abort(), it cannot know g_log(G_LOG_LEVEL_CRITICAL)
> > will never return.
> > 
> > Signed-off-by: Christophe Fergeau <cfergeau@xxxxxxxxxx>
> 
> I prefer the "for" way. But by the way, this is not telling the compiler
> that spice_log (NOT g_log) is not returning but to call abort() after
> spice_log.

Since abort() does not return, overall result is that the compiler won't
think code after spice_critical() can be reached.

> I don't think the compiler will warn that with that flag the function
> it not returning, is not clear why you need these changes.
> Optimization? I don't think that calling an additional function
> and jumping back to original flow would change much.

I'm fairly sure I got warnings during some experiments which led me to
these changes, but I haven't been able to get them now.
One testcase which warns without these changes:

#include "log.h"
#include "stdbool.h"

int main(int argc, char **argv)
{
        switch(argc) {
                case 1:
                        spice_critical("foo");
                default:
                        return 0;
        }
}


$ LC_ALL=C gcc  -c    $(pkg-config --cflags --libs glib-2.0 spice-protocol) -I common   -Wimplicit-fallthrough=5 ./fallthrough.c
In file included from ./fallthrough.c:1:
./fallthrough.c: In function 'main':
common/log.h:73:5: warning: this statement may fall through [-Wimplicit-fallthrough=]
   73 |     spice_log(G_LOG_LEVEL_CRITICAL, SPICE_STRLOC, __FUNCTION__, "" format, ## __VA_ARGS__); \
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./fallthrough.c:8:25: note: in expansion of macro 'spice_critical'
    8 |                         spice_critical("foo");
      |                         ^~~~~~~~~~~~~~
./fallthrough.c:9:17: note: here
    9 |                 default:
      |                 ^~~~~~~

(I can add this to the log)

Christophe

Attachment: signature.asc
Description: PGP signature

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel

[Index of Archives]     [Linux Virtualization]     [Linux Virtualization]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]