Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

-Wreturn-type should not emit warnings when non-termination can be derived indirectly #11713

Open Quuxplusone opened 12 years ago

Quuxplusone commented 12 years ago
Bugzilla Link PR11542
Status NEW
Importance P enhancement
Reported by Ed Schouten (ed@80386.nl)
Reported on 2011-12-12 03:35:31 -0800
Last modified on 2011-12-13 03:32:59 -0800
Version 3.0
Hardware PC FreeBSD
CC efriedma@quicinc.com, kremenek@apple.com, llvm-bugs@lists.llvm.org
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
I suspect this bug is similar to bug 9599, but not identical, so I'm filing
this anyway.

The following code generates a -Wreturn-type warning:

__attribute__((__noreturn__)) void bar(void);

static void
foo(void)
{

        bar();
}

int
f(void)
{

        foo();
}

foo.c:15:1: warning: control reaches end of non-void function [-Wreturn-type]

If I change the call to foo() to bar(), it obviously work, but in this case the
compiler should be to derive to a certain extent that foo() isn't going to
return anyway. This information should be available anyway, as for this
specific C file, foo() is even inlined into bar() completely.
Quuxplusone commented 12 years ago

Stated differently; in theory (disregarding things like in-line assembly, the halting problem, etc) there should be no need at all to add attribute((noreturn)) to any static function. It should be able to derive this information from the call graph.

Quuxplusone commented 12 years ago
It must be noted that it also raises this warning for pieces of code like the
following:

static void
foo(void)
{

        for (;;);
}

int
f(void)
{

        foo();
}