llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.24k stars 11.66k forks source link

clang-diagnostic-array-bounds warning for impossible case in switch statement #35463

Open nickdesaulniers opened 6 years ago

nickdesaulniers commented 6 years ago
Bugzilla Link 36115
Version unspecified
OS Linux
CC @EugeneZelenko

Extended Description

STR:

void w () {
  int y [10];
  switch (10) {
    case 300:
      y[300] = 4;
    default:
      //break;
  }
}

clang-tidy -warnings-as-errors=clang-diagnostic-array-bounds test_case.c

/tmp/test_case.c:6:7: error: array index 300 is past the end of the array (which contains 10 elements) [clang-diagnostic-array-bounds,-warnings-as-errors] y[300] = 4; ^ /tmp/test_case.c:3:3: note: array 'y' declared here int y [10]; ^

My test case is definitely contrived, but I see effectively the same thing running clang-tidy on the Linux kernel in include/linux/signal.h:122

nathanchance commented 2 years ago

mentioned in issue llvm/llvm-bugzilla-archive#51682

nickdesaulniers commented 6 years ago

Clang also produces the same warning.

EugeneZelenko commented 6 years ago

clang-diagnostic group is alias for Clang warnings. Could you please verify that Clang produces same warning? In such cases report should be changed to Clang.