[LLVMbugs] [Bug 7285] New: Use of 'const ... *p' pointing to non-const; possible invalid "undefined" warning ?

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Jun 2 09:47:55 PDT 2010


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

           Summary: Use of 'const ... *p' pointing to non-const; possible
                    invalid "undefined" warning ?
           Product: clang
           Version: 2.7
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
        AssignedTo: kremenek at apple.com
        ReportedBy: wmeier at newsguy.com
                CC: llvmbugs at cs.uiuc.edu


clang.i686        2.7-1.fc13       
@anaconda-InstallationRepo-201005130056.i386
llvm.i686         2.7-1.fc13       
@anaconda-InstallationRepo-201005130056.i386
clang version 1.1 (branches/release_27)

Running on Fedora 13  x86
-------

Test Program:

void foo(int k) {
}

typedef struct {
    int t;
} addr;

void zil(void) {

    int i;
    const int *addri_p;

    addr src;
    const addr *addr_p;

    src.t = 1;
    addr_p = &src;
    foo(addr_p->t);

    i = 1;
    addri_p = &i;
    foo(*addri_p);
}

Result from scan-build

$ scan-build gcc -c foo.c
scan-build: 'clang' executable not found in
'/usr/lib/clang-analyzer/scan-build/bin'.
scan-build: Using 'clang' from path: /usr/bin/clang
ANALYZE: foo.c foo
ANALYZE: foo.c zil
foo.c:18:5: warning: Pass-by-value argument in function call is undefined
    foo(addr_p->t);
    ^   ~~~~~~~~~
1 diagnostic generated.
scan-build: 1 bugs found.

======

Notes: 

1. If the 'const' is removed from 'const addr *addr_p;' then there's no
   warning.

2. The above warning seems invalid in that the usage of const in this case
seems valid. . However, I'm certainly not a C language lawyer so the usage may
actually not be valid.  

3. FWIW: There's no warning for what seems to me to be a similar usage of const
but w/o using a struct ('const int *addri_p;' and etc).

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