[LLVMbugs] [Bug 20301] New: implicit _Noreturn

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Jul 14 14:59:30 PDT 2014


            Bug ID: 20301
           Summary: implicit _Noreturn
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
          Assignee: kremenek at apple.com
          Reporter: dilyan.palauzov at aegee.org
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

I have compiled llvam/clang based on today's trunk.

When I compile this program

  #include <stdlib.h>
  #include <string.h>
  #include <stdio.h>

  static void z() {

  int main(__attribute__((unused)) int argc, char** argv) {
    int a;
    if (strlen(argv[1]) < 3 || sscanf(argv[1], "%i", &a) < 1)
    if (a > 0) printf("A");

clang -std=c11 -Weverything unitialized-noreturn.c 2> unitialized-error

I get
unitialized-noreturn.c:5:17: warning: function 'z' could be declared with
attribute 'noreturn' [-Wmissing-noreturn]
static void z() {
unitialized-noreturn.c:11:7: warning: variable 'a' is used uninitialized
whenever '||' condition is true [-Wsometimes-uninitialized]
  if (strlen(argv[1]) < 3 || sscanf(argv[1], "%i", &a) < 1)
unitialized-noreturn.c:13:7: note: uninitialized use occurs here
  if (a > 0) printf("A");
unitialized-noreturn.c:11:7: note: remove the '||' if its condition is always
  if (strlen(argv[1]) < 3 || sscanf(argv[1], "%i", &a) < 1)
unitialized-noreturn.c:10:8: note: initialize the variable 'a' to silence this
  int a;
        = 0
2 warnings generated.

However, when I put _Noreturn on line 5, right before the definition of
function z() I get no warnings and no notes.

Provided that clang correctly detects the noreturn-nature of z(), why isn't
_Noreturn implied, but has to be provided explicitly?  I see _Noreturn as a way
to hint the compiler (e.g. in (forward) declaration) that a function does not
return, which only necessary when the compiler cannot determine this on its

Why does the second note ("||") depend on _Noreturn?

I expect that clang puts implicit _Noreturn to z() and that the ||-note does
not depend on _Noreturn.

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140714/c6a1c473/attachment.html>

More information about the llvm-bugs mailing list