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

           Summary: Bogus warning with semi-initialised struct variables
                    and static inline functions
           Product: clang
           Version: 2.9
          Platform: Macintosh
        OS/Version: MacOS X
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Static Analyzer
        AssignedTo: [email protected]
        ReportedBy: [email protected]
                CC: [email protected]


Consider the following program:

#include <stdio.h>

struct Foo { int x; int y; };

static __inline__ int foogetx(struct Foo foo) { return foo.x; }

int main() {
    struct Foo bar;
    bar.x = 5;
    printf("%d\n", foogetx(bar));
    return 0;
}

$ clang --version
Apple clang version 2.0 (tags/Apple/clang-137) (based on LLVM 2.9svn)
Target: x86_64-apple-darwin10
Thread model: posix

$ clang --analyze a.c
a.c:10:20: warning: Passed-by-value struct argument contains uninitialized data
(e.g., field: 'y')
    printf("%d\n", foogetx(bar));
                   ^       ~~~
1 warning generated.

This is not an actual issue since that particular member (.x) has been
initialised. It seems that this should be fixed with full interprocedural
analysis, but that might not be necessary considering that foogetx() is a
static inline function.

At any rate, using bar.x instead of foogetx(bar) is a simple enough workaround.
This situation happens with some functions in Apple's Foundation library, too:

NSRect frame;
frame.size = NSZeroSize;
NSHeight(frame) // static analyser warning
frame.size.height // no static analyser warning

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- 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