[LLVMbugs] [Bug 24337] New: False negative for -Wdivision-by-zero

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Aug 2 14:50:49 PDT 2015


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

            Bug ID: 24337
           Summary: False negative for -Wdivision-by-zero
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: davide at freebsd.org
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

int main(void)
{
  int z = 0;
  int x = 1 / z;
  (void)x;
  int y = 1 / 0;
  (void)y;
  return (0);
}

clang warns on the assignment of y, but it doesn't on the assignment of x.
For what it's worth, GCC seems to have the same behaviour, but the two cases
seems pretty much identical to me so I think we should warn on the first as
well.

I dug into that a little bit more, and we seem to fail evaluatingAsInt the RHS
of the expression:

7428        if (RHS.get()->EvaluateAsInt(RHSValue, S.Context)) {
[...]

(gdb) p RHS.get()->dump()
ImplicitCastExpr 0x8080c9f38 'int' <LValueToRValue>
`-DeclRefExpr 0x8080c9f10 'int' lvalue Var 0x8080c9de8 'z' 'int'
$7 = void

Is this a limitation or is this the expected behaviour? Any ideas on how to fix
this?

-- 
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/20150802/f83bf738/attachment.html>


More information about the llvm-bugs mailing list