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

            Bug ID: 25235
           Summary: clang-analyzer-core.uninitialized.Assign doesn't
                    understand bits sets/read operations
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    Classification: Unclassified

Given an uninitialized variable:

uint32_t var;

and a function to set the i-th bit of var to a value: 

template <typename Int>
constexpr void set(Int& x, unsigned b, bool value) {
  static_assert(std::is_integral<Int>{}, "");
  assert(bit < CHAR_BIT * sizeof(Int{}));
  if (value) {
    x |= (Int{1} << b);
  } else {
    x &= ~(Int{1} << b);
  }
}

Then static analyzer complains when:

set(var, 3, true);

is used to set the 3rd bit of var to true because set reads and writes not only
the 3rd bit, but obviously the whole variable, which is uninitialized.

Probably static_analyzer will also fail when reading the 3rd bit back from var.

Since bit operations and bit masks are very common, static analyzer should
probably track the bits or at least understand the basic bit manipulation
operations.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to