summaryrefslogtreecommitdiffstats
path: root/clang/test/Analysis/enum-cast-out-of-range.c
diff options
context:
space:
mode:
authorKristof Umann <kristof.umann@ericsson.com>2019-08-23 14:21:13 +0000
committerKristof Umann <kristof.umann@ericsson.com>2019-08-23 14:21:13 +0000
commit09ce8ec78a958e24a7e22009d6bce1a4c17b6cad (patch)
tree0935ebbb32403615b50bd16d9434c26d6b370e17 /clang/test/Analysis/enum-cast-out-of-range.c
parentb55dea4e8a1e5502ed1ce4adbae2a50563d63f71 (diff)
downloadbcm5719-llvm-09ce8ec78a958e24a7e22009d6bce1a4c17b6cad.tar.gz
bcm5719-llvm-09ce8ec78a958e24a7e22009d6bce1a4c17b6cad.zip
[analyzer] Avoid unnecessary enum range check on LValueToRValue casts
Summary: EnumCastOutOfRangeChecker should not perform enum range checks on LValueToRValue casts, since this type of cast does not actually change the underlying type. Performing the unnecessary check actually triggered an assertion failure deeper in EnumCastOutOfRange for certain input (which is captured in the accompanying test code). Reviewers: #clang, Szelethus, gamesh411, NoQ Reviewed By: Szelethus, gamesh411, NoQ Subscribers: NoQ, gamesh411, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, dkrupp, Charusso, bjope, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66014 llvm-svn: 369760
Diffstat (limited to 'clang/test/Analysis/enum-cast-out-of-range.c')
-rw-r--r--clang/test/Analysis/enum-cast-out-of-range.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/clang/test/Analysis/enum-cast-out-of-range.c b/clang/test/Analysis/enum-cast-out-of-range.c
new file mode 100644
index 00000000000..03e1100c38f
--- /dev/null
+++ b/clang/test/Analysis/enum-cast-out-of-range.c
@@ -0,0 +1,34 @@
+// RUN: %clang_analyze_cc1 \
+// RUN: -analyzer-checker=core,alpha.cplusplus.EnumCastOutOfRange \
+// RUN: -verify %s
+
+enum En_t {
+ En_0 = -4,
+ En_1,
+ En_2 = 1,
+ En_3,
+ En_4 = 4
+};
+
+void unscopedUnspecifiedCStyle() {
+ enum En_t Below = (enum En_t)(-5); // expected-warning {{not in the valid range}}
+ enum En_t NegVal1 = (enum En_t)(-4); // OK.
+ enum En_t NegVal2 = (enum En_t)(-3); // OK.
+ enum En_t InRange1 = (enum En_t)(-2); // expected-warning {{not in the valid range}}
+ enum En_t InRange2 = (enum En_t)(-1); // expected-warning {{not in the valid range}}
+ enum En_t InRange3 = (enum En_t)(0); // expected-warning {{not in the valid range}}
+ enum En_t PosVal1 = (enum En_t)(1); // OK.
+ enum En_t PosVal2 = (enum En_t)(2); // OK.
+ enum En_t InRange4 = (enum En_t)(3); // expected-warning {{not in the valid range}}
+ enum En_t PosVal3 = (enum En_t)(4); // OK.
+ enum En_t Above = (enum En_t)(5); // expected-warning {{not in the valid range}}
+}
+
+enum En_t unused;
+void unusedExpr() {
+ // Following line is not something that EnumCastOutOfRangeChecker should
+ // evaluate. Checker should either ignore this line or process it without
+ // producing any warnings. However, compilation will (and should) still
+ // generate a warning having nothing to do with this checker.
+ unused; // expected-warning {{expression result unused}}
+}
OpenPOWER on IntegriCloud