Skip to content

Bogus warning with semi-initialised struct variables and static inline functions #10000

@llvmbot

Description

@llvmbot
Bugzilla Link 9628
Resolution FIXED
Resolved on Mar 23, 2012 00:11
Version 2.9
OS MacOS X
Reporter LLVM Bugzilla Contributor
CC @tkremenek

Extended Description

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions