[llvm-bugs] [Bug 25881] New: emit warnings if bit operations (especially << and >>) performed on signed values

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Dec 18 05:30:23 PST 2015


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

            Bug ID: 25881
           Summary: emit warnings if bit operations (especially << and >>)
                    performed on signed values
           Product: new-bugs
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: socketpair at gmail.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

for '<<'

6.5.7/4 [...] If E1 has a signed type and nonnegative value, and E1×2E2 is
representable in the result type, then that is the resulting value; otherwise,
the behavior is undefined.


and for '>>'

6.5.7/5 [...] If E1 has a signed type and a negative value, the resulting value
is implementation- defined.

I think, other operations, like &, |, ^, ~ should issue warning when applied to
signed variables.

So, next program do not emit warning now:

int main() {
    volatile int qwe = -10;
    return qwe >> 3;
}

$ clang-3.7 qwe.c -Wall -Wextra

Also, static analyzis should also find that.

-- 
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/20151218/defea4d7/attachment.html>


More information about the llvm-bugs mailing list