LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 4407 - missing warnings on case value overflow
Summary: missing warnings on case value overflow
Status: RESOLVED FIXED
Alias: None
Product: clang
Classification: Unclassified
Component: Frontend (show other bugs)
Version: trunk
Hardware: All All
: P normal
Assignee: Zhanyong Wan
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-06-17 12:41 PDT by Nick Lewycky
Modified: 2010-03-12 00:57 PST (History)
2 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nick Lewycky 2009-06-17 12:41:18 PDT
1. Clang should warn on a case value that exceeds the range of the type in switch.

int test1(const char *foo) {
  int success = 0;
  switch(foo[0]) {
    case 1234:  /* XXX */
      success = 1;
      break;
    default:
      break;
  }
  return success;
}

2. Clang should warn on switch(bool) since it's almost certainly wrong (developers seem okay with using if-statements instead).

int test2(const char *foo) {
  int success = 0;
  switch (foo && foo[0]) {  /* XXX */
    case 0:
      success = 1;
      break;
    case 1:
      break;
  }
  return success;
}
Comment 1 Zhanyong Wan 2009-10-14 15:30:03 PDT
This report contains two separate issues.  I created http://llvm.org/bugs/show_bug.cgi?id=5190 to track the second one.  Let's track the first one only here.
Comment 2 Zhanyong Wan 2009-10-14 15:37:48 PDT
Proposed patch uploaded to http://codereview.appspot.com/130078 for review.
Comment 3 Zhanyong Wan 2009-10-15 23:46:24 PDT
Patch sent to cfe-commits for review.
Comment 4 Zhanyong Wan 2009-10-16 11:51:26 PDT
Fixed in r84259.