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: dcough...@apple.com
          Reporter: r...@eatnumber1.com
                CC: llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to