https://bugs.llvm.org/show_bug.cgi?id=50236

            Bug ID: 50236
           Summary: `-Wsometimes-uninitialized` false positive for
                    assignment
           Product: new-bugs
           Version: 12.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]

Created attachment 24832
  --> https://bugs.llvm.org/attachment.cgi?id=24832&action=edit
Repro

Compiling the attached C source (named sometimes.c) gives the following
warning:

sometimes.c:8:7: warning: variable 'a' is used uninitialized whenever 'if'
condition is false [-Wsometimes-uninitialized]
  if (!c) c = foo(&a);
      ^~
sometimes.c:9:7: note: uninitialized use occurs here
  b = a;
      ^
sometimes.c:8:3: note: remove the 'if' if its condition is always true
  if (!c) c = foo(&a);
  ^~~~~~~~
sometimes.c:7:8: note: initialize the variable 'a' to silence this warning
  int a, b;
       ^
        = 0
1 warning generated.

At line 9, the value of sometimes-uninitialized variable `a` is only assigned
to another variable `b`, and so it should not be warned until the value is
actually used.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to