[LLVMbugs] [Bug 9544] New: Static Analyzer should warn about usage of weak symbols without check.

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Mar 24 12:27:53 PDT 2011


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

           Summary: Static Analyzer should warn about usage of weak
                    symbols without check.
           Product: clang
           Version: trunk
          Platform: All
        OS/Version: MacOS X
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Static Analyzer
        AssignedTo: kremenek at apple.com
        ReportedBy: devlists at shadowlab.org
                CC: llvmbugs at cs.uiuc.edu


Created an attachment (id=6358)
 --> (http://llvm.org/bugs/attachment.cgi?id=6358)
Example

When using a symbol declared as weak_import, the symbol may be set to null at
launch time by the dynamic linker if it is not available.

So when calling a weak function, the user has to check that the symbol is valid
and not null.

This is a special case of 'null deref', so maybe it can be done using the
existing null deref checker.

For example:
--------------------
extern int foo() __attribute__((weak_import,visibility("default")));
extern const char * const kGlobalStringSymbol
__attribute__((weak_import,visibility("default")));

int test(char *arg) {
  if (0 == strcmp(kGlobalStringSymbol, arg)) // expected warning: use of weak
symbol 'kGlobalStringSymbol' which may be null
    return 0;

  return foo(); // expect warning: use of weak symbol 'foo' which may be null
}

int test2(char *arg) {
  if (&kGlobalStringSymbol && 0 == strcmp(kGlobalStringSymbol, arg)) // no
warning
    return 0;

  return foo ? foo() : 0; // no 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.



More information about the llvm-bugs mailing list