[llvm-bugs] [Bug 25937] New: Missing 'null passed to a callee that requires a non-null argument' warning for calls to functions declared with a typedef that has a nonnull attribute

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Dec 23 12:43:51 PST 2015


https://llvm.org/bugs/show_bug.cgi?id=25937

            Bug ID: 25937
           Summary: Missing 'null passed to a callee that requires a
                    non-null argument' warning for calls to functions
                    declared with a typedef that has a nonnull attribute
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: thonerma at synopsys.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

I've tested this with Clang 3.5-3.7 and trunk (r234313).  Clang versions prior
to 3.5 didn't support infix nonnull attribute on parameters, so I didn't bother
going back further.

$ cat t.c
typedef void (f1_t)(int *__attribute__((nonnull)) p);
f1_t f1;
typedef void (f2_t)(int *p) __attribute__((nonnull));
f2_t f2;
typedef void (f3_t)(int *p);
f3_t f3 __attribute__((nonnull));
void f() {
    f1(0);
    f2(0);
    f3(0);
}

$ clang -c t.c
t.c:10:9: warning: null passed to a callee that requires a non-null argument
[-Wnonnull]
    f3(0);
       ~^
1 warning generated.

Note that a warning is only emitted for the call to f3(); warnings should be
issued for the calls to f1() and f2() as well.

The Clang AST does not store the nonnull attribute for the f1_t typedef
declaration, but it does for the f2_t typedef declaration:

$ clang -Xclang -ast-dump -w -c t.c
...
|-TypedefDecl 0x80bbc28 <t.c:1:1, col:52> col:15 referenced f1_t 'void (int
*)':'void (int *)'
...
|-TypedefDecl 0x80fd950 <line:3:1, col:27> col:15 referenced f2_t 'void (int
*)':'void (int *)'
| `-NonNullAttr 0x80fd9a0 <col:44>
...

So, there appears to be two issues:
1) Infix nonnull attributes applied to parameters of typedef declarations are
not preserved in the AST.
2) Warnings are not emitted for calls to functions declared with a typedef
declaration that has nonnull attributes.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20151223/d176e5d8/attachment.html>


More information about the llvm-bugs mailing list