[cfe-dev] unsigned variable preserves signed value?

Balázs Kéri via cfe-dev cfe-dev at lists.llvm.org
Fri Nov 15 03:49:43 PST 2019


Hi,

In the following code:

void test1(int i) {
  unsigned short j = i;
  if (j < 0) {
    int a = j;
    clang_analyzer_eval(a < 0); // expected-warning{{FALSE}}
  }
}

The condition 'a < 0' is evaluated as true by the analyzer (and 'j < 0'
too). Normally the branch can not be entered at all because 'j < 0' can not
be true. Is this the correct way of how this should work? It looks like
that the variable 'a' points to the same memory region as 'i' that contains
a signed value. The problem does not appear if 'unsigned int' is used for
'j'.

Balázs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20191115/2daf000a/attachment.html>


More information about the cfe-dev mailing list