[LLVMbugs] [Bug 12190] New: Function-local static blocks issue spurious analyzer warning

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Mar 5 12:36:03 PST 2012


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

             Bug #: 12190
           Summary: Function-local static blocks issue spurious analyzer
                    warning
           Product: clang
           Version: 3.0
          Platform: Macintosh
        OS/Version: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
        AssignedTo: kremenek at apple.com
        ReportedBy: bgertzfield at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


Running clang 3.0 (clang-211.10.1) on Mac OS X 10.7.2 11C74, the following
program incorrectly issues a spurious static analyzer warning.

According to the Language Specification for Blocks from
http://clang.llvm.org/docs/BlockLanguageSpec.txt :

===
A Block literal expression may be used as the initialization value for Block
variables at global or local static scope.
===

That means the following test program (which uses a Block literal expression as
the initialization value for a Block variable at local static scope) should not
emit a static analyzer warning.

Note: If I change from a function-local static scope to global static scope,
the static analyzer warning goes away.

% cat clang-static-analyzer-bug.c
int main(int argc, char **argv) {
  static void (^localStaticBlock)(void) = ^{ };
  return 0;
}

% clang --analyze -c clang-static-analyzer-bug.c   
clang-static-analyzer-bug.c:3:3: warning: Address of stack-allocated block
declared on line 2 is still referred to by
      the global variable 'localStaticBlock' upon returning to the caller. This
will be a dangling reference
  return 0;
  ^
1 warning generated.

% clang -g -o clang-static-analyzer-bug clang-static-analyzer-bug.c

% gdb ./clang-static-analyzer-bug

(gdb) break main
Breakpoint 1 at 0x100000efe: file clang-static-analyzer-bug.c, line 4.

(gdb) run
Breakpoint 1, main (argc=1, argv=0x7fff5fbff958) at
clang-static-analyzer-bug.c:4
4      return 0;

(gdb) info address localStaticBlock
Symbol "localStaticBlock" is static storage at address 0x100001040.

-- 
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.



More information about the llvm-bugs mailing list