[LLVMbugs] [Bug 16825] New: false positive: garbage value warning

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Aug 7 10:17:32 PDT 2013


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

            Bug ID: 16825
           Summary: false positive: garbage value warning
           Product: clang
           Version: unspecified
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
          Assignee: kremenek at apple.com
          Reporter: michael.hecht at jmp.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Code:


//
//  main.cpp
//  sa-test
//
//  Created by Michael Hecht on 8/7/13.
//  Copyright (c) 2013 Michael Hecht. All rights reserved.
//

#include <iostream>
#include <cassert>
#include <cmath>

/*---------------- UNCERTAINTY COEFFICIENTS ----------------*/

static void zFreqCert( 
        int nr,int nc,
        int rowStride, int colStride,
        double const *tab,
        double const*rowtot,double const* coltot,double totn,
        double qAlpha,    //  normal quantile for (1 - ef->alpha/2)
        double&    ucr,    double&    e_ucr,    double&    l_ucr,    double&   
u_ucr,
        double&    urc,    double&    e_urc,    double&    l_urc,    double&   
u_urc,
        double&    u,        double&    e_u,    double&    l_u,    double&   
u_u)
{
    long     i, j;
    double uij, ui, uj, pi, pj, pij, lpi, lpj, lpij;
    double uiji, uijj, uijcp, uiss, ujss, uijss;

    /*--- PRELIMINARY CALCULATIONS ---*/
    ui = uj = uij = uiss = ujss = uijss = uiji = uijj = uijcp = 0.;

    for (i=0; i<nr; i++) { pi = rowtot[i]/totn;
        if (pi>0) { lpi=log(pi); ui+=(pi*lpi); uiss+=(pi*lpi*lpi); }
        for (j=0; j<nc; j++) {
            pj = coltot[j]/totn;     pij = tab[i*rowStride+j*colStride]/totn;

            if (pj>0) {
                lpj=log(pj); uj+=(pij*lpj); ujss+=(pij*lpj*lpj);
                if (pi>0) uijcp += (pij*lpi*lpj);
                if (pij>0) {    assert(pi>0 && pj>0);
                    lpij=log(pij);
                    uij += (pij*lpij);
                    uijss += (pij*lpij*lpij);
                    uiji += (pij*lpij*lpi);
                    uijj += (pij*lpij*lpj);
                }
            }
        }
    }
}

int main(int argc, const char * argv[])
{

    // insert code here...
    std::cout << "Hello, World!\n";
    return 0;
}



Analyze target sa-test

Analyze sa-test/main.cpp
    cd /Users/hecht/Desktop/sa-test
    setenv LANG en_US.US-ASCII
   
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
-x c++ -arch x86_64 -fmessage-length=0 -std=gnu++11 -stdlib=libc++
-Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers
-Wno-missing-prototypes -Wreturn-type -Wno-non-virtual-dtor
-Wno-overloaded-virtual -Wno-exit-time-destructors -Wformat -Wno-missing-braces
-Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label
-Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body
-Wuninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants
-Wno-conversion -Wconstant-conversion -Wint-conversion -Wenum-conversion
-Wshorten-64-to-32 -Wno-newline-eof -Wno-c++11-extensions -DDEBUG=1 -isysroot
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk
-fasm-blocks -fstrict-aliasing -Wdeprecated-declarations -Winvalid-offsetof
-mmacosx-version-min=10.8 -g -fvisibility-inlines-hidden -Wno-sign-conversion
-Xclang -analyzer-output=plist-multi-file -Xclang -analyzer-checker -Xclang
security.insecureAPI.UncheckedReturn -Xclang -analyzer-checker -Xclang
security.insecureAPI.getpw -Xclang -analyzer-checker -Xclang
security.insecureAPI.gets -Xclang -analyzer-checker -Xclang
security.insecureAPI.mkstemp -Xclang -analyzer-checker -Xclang
security.insecureAPI.mktemp -Xclang -analyzer-disable-checker -Xclang
security.insecureAPI.rand -Xclang -analyzer-disable-checker -Xclang
security.insecureAPI.strcpy -Xclang -analyzer-checker -Xclang
security.insecureAPI.vfork -iquote
/Users/hecht/Library/Developer/Xcode/DerivedData/sa-test-aonsrgxjbwasygdpieoztmczengq/Build/Intermediates/sa-test.build/Debug/sa-test.build/sa-test-generated-files.hmap
-I/Users/hecht/Library/Developer/Xcode/DerivedData/sa-test-aonsrgxjbwasygdpieoztmczengq/Build/Intermediates/sa-test.build/Debug/sa-test.build/sa-test-own-target-headers.hmap
-I/Users/hecht/Library/Developer/Xcode/DerivedData/sa-test-aonsrgxjbwasygdpieoztmczengq/Build/Intermediates/sa-test.build/Debug/sa-test.build/sa-test-all-target-headers.hmap
-iquote
/Users/hecht/Library/Developer/Xcode/DerivedData/sa-test-aonsrgxjbwasygdpieoztmczengq/Build/Intermediates/sa-test.build/Debug/sa-test.build/sa-test-project-headers.hmap
-I/Users/hecht/Library/Developer/Xcode/DerivedData/sa-test-aonsrgxjbwasygdpieoztmczengq/Build/Products/Debug/include
-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
-I/Users/hecht/Library/Developer/Xcode/DerivedData/sa-test-aonsrgxjbwasygdpieoztmczengq/Build/Intermediates/sa-test.build/Debug/sa-test.build/DerivedSources/x86_64
-I/Users/hecht/Library/Developer/Xcode/DerivedData/sa-test-aonsrgxjbwasygdpieoztmczengq/Build/Intermediates/sa-test.build/Debug/sa-test.build/DerivedSources
-F/Users/hecht/Library/Developer/Xcode/DerivedData/sa-test-aonsrgxjbwasygdpieoztmczengq/Build/Products/Debug
-MMD -MT dependencies -MF
/Users/hecht/Library/Developer/Xcode/DerivedData/sa-test-aonsrgxjbwasygdpieoztmczengq/Build/Intermediates/sa-test.build/Debug/sa-test.build/StaticAnalyzer/sa-test/sa-test/normal/x86_64/main.d
--analyze /Users/hecht/Desktop/sa-test/sa-test/main.cpp -o
/Users/hecht/Library/Developer/Xcode/DerivedData/sa-test-aonsrgxjbwasygdpieoztmczengq/Build/Intermediates/sa-test.build/Debug/sa-test.build/StaticAnalyzer/sa-test/sa-test/normal/x86_64/main.plist

sa-test/sa-test/main.cpp:39:28: warning: The right operand of '*' is a garbage
value                                i    1 warning generated.


The structure of the code is this:

double lpi;
...
if(pi > 0) lpi = <some value>;
...
if(pi > 0)
   <use lpi>

Not sure why this is flagged as a garbage value?

-- 
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/20130807/9ca7ecaa/attachment.html>


More information about the llvm-bugs mailing list