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: [email protected]
        ReportedBy: [email protected]
                CC: [email protected]


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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to