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

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
      char ret = a[1];
      return ret;

The warning generated is:

$ scan-build clang++ -std=c++11 -c -O0 ~/
scan-build: Using '/usr/bin/clang' for static analysis
/usr/local/google/home/eatnumber1/ 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.
llvm-bugs mailing list

Reply via email to