http://llvm.org/bugs/show_bug.cgi?id=20301

            Bug ID: 20301
           Summary: implicit _Noreturn
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    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() {
    exit(0);
  }

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

with
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
false
  if (strlen(argv[1]) < 3 || sscanf(argv[1], "%i", &a) < 1)
      ^~~~~~~~~~~~~~~~~~~~~~
unitialized-noreturn.c:10:8: note: initialize the variable 'a' to silence this
warning
  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
own.

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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to