[llvm-bugs] [Bug 36477] New: clang-analyzer-core.uninitialized.Assign: False positive with reinterpret_cast

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Feb 22 11:15:33 PST 2018


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

            Bug ID: 36477
           Summary: clang-analyzer-core.uninitialized.Assign: False
                    positive with reinterpret_cast
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Static Analyzer
          Assignee: dcoughlin at apple.com
          Reporter: russ at eatnumber1.com
                CC: llvm-bugs at lists.llvm.org

I've been encountering a case where Clang Static Analyzer raises
clang-analyzer-core.uninitialized.Assign. I've narrowed down the culprit code
to the following sample case:

    struct myint {
      int d;
    };

    struct foo {
      myint a;
    };

    int myfn1() {
      foo myfoo {5};
      const unsigned char *a = reinterpret_cast<const unsigned char
*>(&myfoo.a);
      char ret = a[1];
      return ret;
    }

The warning generated is:

$ scan-build clang++ -std=c++11 -c -O0 ~/a.cc
scan-build: Using '/usr/bin/clang' for static analysis
/usr/local/google/home/eatnumber1/a.cc:12:3: warning: Assigned value is garbage
or undefined
  char ret = a[1];
  ^~~~~~~~   ~~~~
1 warning generated.
scan-build: 1 bugs found.
scan-build: Run 'scan-view /tmp/scan-build-2017-10-13-151811-27304-1' to
examine bug reports.

If I change `struct foo` to the following:

    struct foo {
      int a;
    };

then the warning is not emitted.

What's going on here?

-- 
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/20180222/66a4ff46/attachment.html>


More information about the llvm-bugs mailing list