Bug 46460 - warn for shifting more than the bits in the (promoted) type is undefined
Summary: warn for shifting more than the bits in the (promoted) type is undefined
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.2.1
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
: 46517 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-11-13 01:36 UTC by keefeg
Modified: 2014-04-29 13:06 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2010-11-13 15:06:51


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description keefeg 2010-11-13 01:36:18 UTC
% cat bug.c
#include <stdio.h>

int main(void) {
  unsigned int ShouldBeZero;
  int cnt = 32;

  ShouldBeZero = 0xFFFFFFFF >> cnt;

  printf("Should print 0 here: %u\n", ShouldBeZero);

  return 0;
}

% cc -o bug bug.c
% ./bug
Should print 0 here: 4294967295

% cc -o bug -O3 bug.c
% ./bug
Should print 0 here: 0

% gcc -v
Using built-in specs.
Target: amd64-undermydesk-freebsd
Configured with: FreeBSD/amd64 system compiler
Thread model: posix
gcc version 4.2.1 20070719  [FreeBSD]

% sysctl -a | grep 'hw\.model'
hw.model: AMD Phenom(tm) II X4 955 Processor
Comment 1 Andrew Pinski 2010-11-13 05:31:15 UTC
Shifting more than the bits in the (promoted) type is undefined.
Comment 2 Manuel López-Ibáñez 2010-11-13 15:06:51 UTC
REOPEN as enhancement request for a warning. (No warning in 4.4.3)
Comment 3 Andreas Schwab 2010-11-17 09:45:16 UTC
*** Bug 46517 has been marked as a duplicate of this bug. ***
Comment 4 Marek Polacek 2014-04-29 13:06:46 UTC
We have -fsanitize=shift for this now.