summaryrefslogtreecommitdiffstats
path: root/clang/test/Analysis/diagnostics/track_subexpressions.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/test/Analysis/diagnostics/track_subexpressions.cpp')
-rw-r--r--clang/test/Analysis/diagnostics/track_subexpressions.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/clang/test/Analysis/diagnostics/track_subexpressions.cpp b/clang/test/Analysis/diagnostics/track_subexpressions.cpp
new file mode 100644
index 00000000000..e5a6b8ff115
--- /dev/null
+++ b/clang/test/Analysis/diagnostics/track_subexpressions.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_analyze_cc1 -x c++ -analyzer-checker=core -analyzer-output=text -verify %s
+
+typedef unsigned char uint8_t;
+
+#define UINT8_MAX 255
+#define TCP_MAXWIN 65535
+
+uint8_t get_uint8_max() {
+ uint8_t rcvscale = UINT8_MAX; // expected-note{{'rcvscale' initialized to 255}}
+ return rcvscale; // expected-note{{Returning the value 255 (loaded from 'rcvscale')}}
+}
+
+void shift_by_undefined_value() {
+ uint8_t shift_amount = get_uint8_max(); // expected-note{{'shift_amount' initialized to 255}}
+ // expected-note@-1{{Calling 'get_uint8_max'}}
+ // expected-note@-2{{Returning from 'get_uint8_max'}}
+ (void)(TCP_MAXWIN << shift_amount); // expected-warning{{The result of the left shift is undefined due to shifting by '255', which is greater or equal to the width of type 'int'}}
+ // expected-note@-1{{The result of the left shift is undefined due to shifting by '255', which is greater or equal to the width of type 'int'}}
+}
OpenPOWER on IntegriCloud