llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.87k stars 11.93k forks source link

Assigning autoreleased objects into a static variable does not produce a warning #5327

Open llvmbot opened 15 years ago

llvmbot commented 15 years ago
Bugzilla Link 4955
Version unspecified
OS MacOS X
Reporter LLVM Bugzilla Contributor
CC @tkremenek

Extended Description

Description: The static analyzer does not warn of assigning autoreleased objects into a static variable.

Steps to reproduce: int main(int argc, char argv[]) { static NSString foo = nil; NSAutoreleasePool pool = [[NSAutoreleasePool alloc] init]; NSMutableArray f = [NSMutableArray array]; for(int i = 0; i < 10; ++i) { [f addObject:[NSString stringWithFormat:@"%d", i]]; } foo = [f componentsJoinedByString:@","]; [pool drain]; printf("%s\n", [foo UTF8String]); return 0; }

Actual results: I can compile and analyze, all with no warnings of any kind. When the app runs, it crashes with "EXC_BAD_ACCESS" (as "expected").

Expected results: The analyzer should warn me that I'm assigning an autoreleased object into a static variable. In GUI applications especially, where autoreleasepools are created and destroyed frequently, this can be quite detrimental.

Build date: 11 September 2009, Mac OS X 10.6, Xcode 3.2 (built-in analyzer) 11 September 2009, Mac OS X 10.5, Xcode 3.1, checker 0.219

llvmbot commented 11 years ago

+1 — Still a problem as of Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn)

tkremenek commented 12 years ago

cloned to rdar://problem/11957587

llvmbot commented 12 years ago

Still hitting this:

Apple clang version 4.0 (tags/Apple/clang-421.0.55) (based on LLVM 3.1svn)

llvmbot commented 15 years ago

assigned to @tkremenek