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

            Bug ID: 24026
           Summary: No warning on shifting a negative value
           Product: clang
           Version: 3.6
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    Classification: Unclassified

When we shift a negative number, clang does not emit a warning. This is
undefined behavior, which is already captured by ubsan. 

$: cat t.c
#include <stdio.h>
int main(int argc, char **argv) {
  int a = -1 << 3;
  printf("%d\n", a);
  return a;
}
$: clang-3.6 t.c ; ./a.out
-8
$: clang-3.6 -fsanitize=undefined t.c ; ./a.out
t.c:3:14: runtime error: left shift of negative value -1
-8
$: 
$: gcc-trunk -pedantic -Wshift-negative-value t.c
t.c: In function ‘main’:
t.c:3:14: warning: left shift of negative value [-Wshift-negative-value]
   int a = -1 << 3;
              ^

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to