aboutsummaryrefslogtreecommitdiff
path: root/gcc/flags.h
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/flags.h')
-rw-r--r--gcc/flags.h47
1 files changed, 45 insertions, 2 deletions
diff --git a/gcc/flags.h b/gcc/flags.h
index 2671ec3..1996bd1 100644
--- a/gcc/flags.h
+++ b/gcc/flags.h
@@ -114,6 +114,11 @@ extern HOST_WIDE_INT larger_than_size;
extern int warn_strict_aliasing;
+/* Nonzero means warn about optimizations which rely on undefined
+ signed overflow. */
+
+extern int warn_strict_overflow;
+
/* Temporarily suppress certain warnings.
This is set while reading code from a system header file. */
@@ -289,8 +294,13 @@ extern const char *flag_random_seed;
(TYPE_UNSIGNED (TYPE) || flag_wrapv)
/* True if overflow is undefined for the given integral type. We may
- optimize on the assumption that values in the type never
- overflow. */
+ optimize on the assumption that values in the type never overflow.
+
+ IMPORTANT NOTE: Any optimization based on TYPE_OVERFLOW_UNDEFINED
+ must issue a warning based on warn_strict_overflow. In some cases
+ it will be appropriate to issue the warning immediately, and in
+ other cases it will be appropriate to simply set a flag and let the
+ caller decide whether a warning is appropriate or not. */
#define TYPE_OVERFLOW_UNDEFINED(TYPE) \
(!TYPE_UNSIGNED (TYPE) && !flag_wrapv && !flag_trapv && flag_strict_overflow)
@@ -299,4 +309,37 @@ extern const char *flag_random_seed;
#define TYPE_OVERFLOW_TRAPS(TYPE) \
(!TYPE_UNSIGNED (TYPE) && flag_trapv)
+/* Names for the different levels of -Wstrict-overflow=N. The numeric
+ values here correspond to N. */
+
+enum warn_strict_overflow_code
+{
+ /* Overflow warning that should be issued with -Wall: a questionable
+ construct that is easy to avoid even when using macros. Example:
+ folding (x + CONSTANT > x) to 1. */
+ WARN_STRICT_OVERFLOW_ALL = 1,
+ /* Overflow warning about folding a comparison to a constant because
+ of undefined signed overflow, other than cases covered by
+ WARN_STRICT_OVERFLOW_ALL. Example: folding (abs (x) >= 0) to 1
+ (this is false when x == INT_MIN). */
+ WARN_STRICT_OVERFLOW_CONDITIONAL = 2,
+ /* Overflow warning about changes to comparisons other than folding
+ them to a constant. Example: folding (x + 1 > 1) to (x > 0). */
+ WARN_STRICT_OVERFLOW_COMPARISON = 3,
+ /* Overflow warnings not covered by the above cases. Example:
+ folding ((x * 10) / 5) to (x * 2). */
+ WARN_STRICT_OVERFLOW_MISC = 4,
+ /* Overflow warnings about reducing magnitude of constants in
+ comparison. Example: folding (x + 2 > y) to (x + 1 >= y). */
+ WARN_STRICT_OVERFLOW_MAGNITUDE = 5
+};
+
+/* Whether to emit an overflow warning whose code is C. */
+
+static inline bool
+issue_strict_overflow_warning (enum warn_strict_overflow_code c)
+{
+ return warn_strict_overflow >= (int) c;
+}
+
#endif /* ! GCC_FLAGS_H */