diff options
| author | Paul Eggert | 2013-10-10 23:32:29 -0700 |
|---|---|---|
| committer | Paul Eggert | 2013-10-10 23:32:29 -0700 |
| commit | b9ff995e4c091ca99c8752bb996e155ce7147a00 (patch) | |
| tree | 2606b847e60957359df7942004b774b4c68b119f | |
| parent | 33ac026599404c7d5177eecb4fcd0aa527180ee2 (diff) | |
| download | emacs-b9ff995e4c091ca99c8752bb996e155ce7147a00.tar.gz emacs-b9ff995e4c091ca99c8752bb996e155ce7147a00.zip | |
* lisp.h (eassume): New macro.
Also, include <verify.h>, for 'assume'.
* alloc.c (bool_vector_payload_bytes, Fmake_bool_vector)
(vroundup, vector_nbytes):
* data.c (bool_vector_spare_mask, bool_vector_binop_driver)
(Fbool_vector_not, Fbool_vector_count_matches)
(Fbool_vector_count_matches_at):
Use eassume, not eassert.
* casetab.c (set_identity, shuffle):
* composite.c (composition_gstring_put_cache):
* dispnew.c (update_frame_1):
* ftfont.c (ftfont_shape_by_flt):
* image.c (gif_load):
* intervals.c (offset_intervals):
* macfont.m (macfont_shape):
Remove calls to 'assume' that are no longer needed, because
--enable-gcc-warnings no longer generates bogus warnings
when these calls are removed.
| -rw-r--r-- | src/ChangeLog | 21 | ||||
| -rw-r--r-- | src/alloc.c | 10 | ||||
| -rw-r--r-- | src/casetab.c | 2 | ||||
| -rw-r--r-- | src/composite.c | 1 | ||||
| -rw-r--r-- | src/data.c | 10 | ||||
| -rw-r--r-- | src/dispnew.c | 1 | ||||
| -rw-r--r-- | src/ftfont.c | 1 | ||||
| -rw-r--r-- | src/image.c | 5 | ||||
| -rw-r--r-- | src/intervals.c | 5 | ||||
| -rw-r--r-- | src/lisp.h | 41 | ||||
| -rw-r--r-- | src/macfont.m | 1 |
11 files changed, 64 insertions, 34 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index bfa9f2fae7d..df44bca7b1c 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,24 @@ | |||
| 1 | 2013-10-11 Paul Eggert <eggert@cs.ucla.edu> | ||
| 2 | |||
| 3 | * lisp.h (eassume): New macro. | ||
| 4 | Also, include <verify.h>, for 'assume'. | ||
| 5 | * alloc.c (bool_vector_payload_bytes, Fmake_bool_vector) | ||
| 6 | (vroundup, vector_nbytes): | ||
| 7 | * data.c (bool_vector_spare_mask, bool_vector_binop_driver) | ||
| 8 | (Fbool_vector_not, Fbool_vector_count_matches) | ||
| 9 | (Fbool_vector_count_matches_at): | ||
| 10 | Use eassume, not eassert. | ||
| 11 | * casetab.c (set_identity, shuffle): | ||
| 12 | * composite.c (composition_gstring_put_cache): | ||
| 13 | * dispnew.c (update_frame_1): | ||
| 14 | * ftfont.c (ftfont_shape_by_flt): | ||
| 15 | * image.c (gif_load): | ||
| 16 | * intervals.c (offset_intervals): | ||
| 17 | * macfont.m (macfont_shape): | ||
| 18 | Remove calls to 'assume' that are no longer needed, because | ||
| 19 | --enable-gcc-warnings no longer generates bogus warnings | ||
| 20 | when these calls are removed. | ||
| 21 | |||
| 1 | 2013-10-11 Dmitry Antipov <dmantipov@yandex.ru> | 22 | 2013-10-11 Dmitry Antipov <dmantipov@yandex.ru> |
| 2 | 23 | ||
| 3 | * xdisp.c (deep_copy_glyph_row): Remove unused locals. | 24 | * xdisp.c (deep_copy_glyph_row): Remove unused locals. |
diff --git a/src/alloc.c b/src/alloc.c index 17f1b19b3c0..0667353c1a8 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -2027,7 +2027,7 @@ bool_vector_payload_bytes (ptrdiff_t nr_bits, | |||
| 2027 | ptrdiff_t exact_needed_bytes; | 2027 | ptrdiff_t exact_needed_bytes; |
| 2028 | ptrdiff_t needed_bytes; | 2028 | ptrdiff_t needed_bytes; |
| 2029 | 2029 | ||
| 2030 | eassert (nr_bits >= 0); | 2030 | eassume (nr_bits >= 0); |
| 2031 | 2031 | ||
| 2032 | exact_needed_bytes = ROUNDUP ((size_t) nr_bits, CHAR_BIT) / CHAR_BIT; | 2032 | exact_needed_bytes = ROUNDUP ((size_t) nr_bits, CHAR_BIT) / CHAR_BIT; |
| 2033 | needed_bytes = ROUNDUP ((size_t) nr_bits, BITS_PER_BITS_WORD) / CHAR_BIT; | 2033 | needed_bytes = ROUNDUP ((size_t) nr_bits, BITS_PER_BITS_WORD) / CHAR_BIT; |
| @@ -2064,8 +2064,8 @@ LENGTH must be a number. INIT matters only in whether it is t or nil. */) | |||
| 2064 | total_payload_bytes = bool_vector_payload_bytes | 2064 | total_payload_bytes = bool_vector_payload_bytes |
| 2065 | (XFASTINT (length), &exact_payload_bytes); | 2065 | (XFASTINT (length), &exact_payload_bytes); |
| 2066 | 2066 | ||
| 2067 | eassert (exact_payload_bytes <= total_payload_bytes); | 2067 | eassume (exact_payload_bytes <= total_payload_bytes); |
| 2068 | eassert (0 <= exact_payload_bytes); | 2068 | eassume (0 <= exact_payload_bytes); |
| 2069 | 2069 | ||
| 2070 | needed_elements = ROUNDUP ((size_t) ((bool_header_size - header_size) | 2070 | needed_elements = ROUNDUP ((size_t) ((bool_header_size - header_size) |
| 2071 | + total_payload_bytes), | 2071 | + total_payload_bytes), |
| @@ -2622,7 +2622,7 @@ verify (VECTOR_BLOCK_SIZE <= (1 << PSEUDOVECTOR_SIZE_BITS)); | |||
| 2622 | /* Round up X to nearest mult-of-ROUNDUP_SIZE --- use at compile time. */ | 2622 | /* Round up X to nearest mult-of-ROUNDUP_SIZE --- use at compile time. */ |
| 2623 | #define vroundup_ct(x) ROUNDUP ((size_t) (x), roundup_size) | 2623 | #define vroundup_ct(x) ROUNDUP ((size_t) (x), roundup_size) |
| 2624 | /* Round up X to nearest mult-of-ROUNDUP_SIZE --- use at runtime. */ | 2624 | /* Round up X to nearest mult-of-ROUNDUP_SIZE --- use at runtime. */ |
| 2625 | #define vroundup(x) (assume ((x) >= 0), vroundup_ct (x)) | 2625 | #define vroundup(x) (eassume ((x) >= 0), vroundup_ct (x)) |
| 2626 | 2626 | ||
| 2627 | /* Rounding helps to maintain alignment constraints if USE_LSB_TAG. */ | 2627 | /* Rounding helps to maintain alignment constraints if USE_LSB_TAG. */ |
| 2628 | 2628 | ||
| @@ -2820,7 +2820,7 @@ vector_nbytes (struct Lisp_Vector *v) | |||
| 2820 | ptrdiff_t payload_bytes = | 2820 | ptrdiff_t payload_bytes = |
| 2821 | bool_vector_payload_bytes (bv->size, NULL); | 2821 | bool_vector_payload_bytes (bv->size, NULL); |
| 2822 | 2822 | ||
| 2823 | eassert (payload_bytes >= 0); | 2823 | eassume (payload_bytes >= 0); |
| 2824 | size = bool_header_size + ROUNDUP (payload_bytes, word_size); | 2824 | size = bool_header_size + ROUNDUP (payload_bytes, word_size); |
| 2825 | } | 2825 | } |
| 2826 | else | 2826 | else |
diff --git a/src/casetab.c b/src/casetab.c index 69cd784f4cc..e4907f5b628 100644 --- a/src/casetab.c +++ b/src/casetab.c | |||
| @@ -205,7 +205,6 @@ set_identity (Lisp_Object table, Lisp_Object c, Lisp_Object elt) | |||
| 205 | from = to = XINT (c); | 205 | from = to = XINT (c); |
| 206 | 206 | ||
| 207 | to++; | 207 | to++; |
| 208 | assume (to <= MAX_CHAR + 1); | ||
| 209 | for (; from < to; from++) | 208 | for (; from < to; from++) |
| 210 | CHAR_TABLE_SET (table, from, make_number (from)); | 209 | CHAR_TABLE_SET (table, from, make_number (from)); |
| 211 | } | 210 | } |
| @@ -232,7 +231,6 @@ shuffle (Lisp_Object table, Lisp_Object c, Lisp_Object elt) | |||
| 232 | from = to = XINT (c); | 231 | from = to = XINT (c); |
| 233 | 232 | ||
| 234 | to++; | 233 | to++; |
| 235 | assume (to <= MAX_CHAR + 1); | ||
| 236 | for (; from < to; from++) | 234 | for (; from < to; from++) |
| 237 | { | 235 | { |
| 238 | Lisp_Object tem = Faref (table, elt); | 236 | Lisp_Object tem = Faref (table, elt); |
diff --git a/src/composite.c b/src/composite.c index 4f125522e38..689ae95fa17 100644 --- a/src/composite.c +++ b/src/composite.c | |||
| @@ -674,7 +674,6 @@ composition_gstring_put_cache (Lisp_Object gstring, ptrdiff_t len) | |||
| 674 | len = j; | 674 | len = j; |
| 675 | } | 675 | } |
| 676 | 676 | ||
| 677 | assume (len <= TYPE_MAXIMUM (ptrdiff_t) - 2); | ||
| 678 | copy = Fmake_vector (make_number (len + 2), Qnil); | 677 | copy = Fmake_vector (make_number (len + 2), Qnil); |
| 679 | LGSTRING_SET_HEADER (copy, Fcopy_sequence (header)); | 678 | LGSTRING_SET_HEADER (copy, Fcopy_sequence (header)); |
| 680 | for (i = 0; i < len; i++) | 679 | for (i = 0; i < len; i++) |
diff --git a/src/data.c b/src/data.c index 8045cd138ea..b4257243fb3 100644 --- a/src/data.c +++ b/src/data.c | |||
| @@ -2969,7 +2969,7 @@ lowercase l) for small endian machines. */) | |||
| 2969 | static bits_word | 2969 | static bits_word |
| 2970 | bool_vector_spare_mask (ptrdiff_t nr_bits) | 2970 | bool_vector_spare_mask (ptrdiff_t nr_bits) |
| 2971 | { | 2971 | { |
| 2972 | eassert (nr_bits > 0); | 2972 | eassume (nr_bits > 0); |
| 2973 | return (((bits_word) 1) << (nr_bits % BITS_PER_BITS_WORD)) - 1; | 2973 | return (((bits_word) 1) << (nr_bits % BITS_PER_BITS_WORD)) - 1; |
| 2974 | } | 2974 | } |
| 2975 | 2975 | ||
| @@ -3019,7 +3019,7 @@ bool_vector_binop_driver (Lisp_Object op1, | |||
| 3019 | nr_bits = min (nr_bits, XBOOL_VECTOR (dest)->size); | 3019 | nr_bits = min (nr_bits, XBOOL_VECTOR (dest)->size); |
| 3020 | } | 3020 | } |
| 3021 | 3021 | ||
| 3022 | eassert (nr_bits >= 0); | 3022 | eassume (nr_bits >= 0); |
| 3023 | nr_words = ROUNDUP (nr_bits, BITS_PER_BITS_WORD) / BITS_PER_BITS_WORD; | 3023 | nr_words = ROUNDUP (nr_bits, BITS_PER_BITS_WORD) / BITS_PER_BITS_WORD; |
| 3024 | 3024 | ||
| 3025 | adata = (bits_word *) XBOOL_VECTOR (dest)->data; | 3025 | adata = (bits_word *) XBOOL_VECTOR (dest)->data; |
| @@ -3185,7 +3185,7 @@ Return the destination vector. */) | |||
| 3185 | bdata = (bits_word *) XBOOL_VECTOR (b)->data; | 3185 | bdata = (bits_word *) XBOOL_VECTOR (b)->data; |
| 3186 | adata = (bits_word *) XBOOL_VECTOR (a)->data; | 3186 | adata = (bits_word *) XBOOL_VECTOR (a)->data; |
| 3187 | 3187 | ||
| 3188 | eassert (nr_bits >= 0); | 3188 | eassume (nr_bits >= 0); |
| 3189 | 3189 | ||
| 3190 | for (i = 0; i < nr_bits / BITS_PER_BITS_WORD; i++) | 3190 | for (i = 0; i < nr_bits / BITS_PER_BITS_WORD; i++) |
| 3191 | bdata[i] = ~adata[i]; | 3191 | bdata[i] = ~adata[i]; |
| @@ -3220,7 +3220,7 @@ A must be a bool vector. B is a generalized bool. */) | |||
| 3220 | match = NILP (b) ? -1 : 0; | 3220 | match = NILP (b) ? -1 : 0; |
| 3221 | adata = (bits_word *) XBOOL_VECTOR (a)->data; | 3221 | adata = (bits_word *) XBOOL_VECTOR (a)->data; |
| 3222 | 3222 | ||
| 3223 | eassert (nr_bits >= 0); | 3223 | eassume (nr_bits >= 0); |
| 3224 | 3224 | ||
| 3225 | for (i = 0; i < nr_bits / BITS_PER_BITS_WORD; ++i) | 3225 | for (i = 0; i < nr_bits / BITS_PER_BITS_WORD; ++i) |
| 3226 | count += popcount_bits_word (adata[i] ^ match); | 3226 | count += popcount_bits_word (adata[i] ^ match); |
| @@ -3262,7 +3262,7 @@ index into the vector. */) | |||
| 3262 | 3262 | ||
| 3263 | adata = (bits_word *) XBOOL_VECTOR (a)->data; | 3263 | adata = (bits_word *) XBOOL_VECTOR (a)->data; |
| 3264 | 3264 | ||
| 3265 | assume (nr_bits >= 0); | 3265 | eassume (nr_bits >= 0); |
| 3266 | nr_words = ROUNDUP (nr_bits, BITS_PER_BITS_WORD) / BITS_PER_BITS_WORD; | 3266 | nr_words = ROUNDUP (nr_bits, BITS_PER_BITS_WORD) / BITS_PER_BITS_WORD; |
| 3267 | 3267 | ||
| 3268 | pos = XFASTINT (i) / BITS_PER_BITS_WORD; | 3268 | pos = XFASTINT (i) / BITS_PER_BITS_WORD; |
diff --git a/src/dispnew.c b/src/dispnew.c index f5adb359f22..e3a1c1b49cb 100644 --- a/src/dispnew.c +++ b/src/dispnew.c | |||
| @@ -4480,7 +4480,6 @@ update_frame_1 (struct frame *f, bool force_p, bool inhibit_id_p) | |||
| 4480 | } | 4480 | } |
| 4481 | } | 4481 | } |
| 4482 | 4482 | ||
| 4483 | assume (0 <= FRAME_LINES (f)); | ||
| 4484 | pause_p = 0 < i && i < FRAME_LINES (f) - 1; | 4483 | pause_p = 0 < i && i < FRAME_LINES (f) - 1; |
| 4485 | 4484 | ||
| 4486 | /* Now just clean up termcap drivers and set cursor, etc. */ | 4485 | /* Now just clean up termcap drivers and set cursor, etc. */ |
diff --git a/src/ftfont.c b/src/ftfont.c index 4e58d83fd64..eeee56891ec 100644 --- a/src/ftfont.c +++ b/src/ftfont.c | |||
| @@ -2425,7 +2425,6 @@ ftfont_shape_by_flt (Lisp_Object lgstring, struct font *font, | |||
| 2425 | } | 2425 | } |
| 2426 | 2426 | ||
| 2427 | len = i; | 2427 | len = i; |
| 2428 | assume (len <= STRING_BYTES_BOUND); | ||
| 2429 | 2428 | ||
| 2430 | if (with_variation_selector) | 2429 | if (with_variation_selector) |
| 2431 | { | 2430 | { |
diff --git a/src/image.c b/src/image.c index 86780c62a0b..ca2ef67c0b9 100644 --- a/src/image.c +++ b/src/image.c | |||
| @@ -7571,10 +7571,7 @@ gif_load (struct frame *f, struct image *img) | |||
| 7571 | y++, row += interlace_increment[pass]) | 7571 | y++, row += interlace_increment[pass]) |
| 7572 | { | 7572 | { |
| 7573 | while (subimg_height <= row) | 7573 | while (subimg_height <= row) |
| 7574 | { | 7574 | row = interlace_start[++pass]; |
| 7575 | assume (pass < 3); | ||
| 7576 | row = interlace_start[++pass]; | ||
| 7577 | } | ||
| 7578 | 7575 | ||
| 7579 | for (x = 0; x < subimg_width; x++) | 7576 | for (x = 0; x < subimg_width; x++) |
| 7580 | { | 7577 | { |
diff --git a/src/intervals.c b/src/intervals.c index a9c4f5aed0b..5aa68a359d6 100644 --- a/src/intervals.c +++ b/src/intervals.c | |||
| @@ -1404,10 +1404,7 @@ offset_intervals (struct buffer *buffer, ptrdiff_t start, ptrdiff_t length) | |||
| 1404 | adjust_intervals_for_insertion (buffer_intervals (buffer), | 1404 | adjust_intervals_for_insertion (buffer_intervals (buffer), |
| 1405 | start, length); | 1405 | start, length); |
| 1406 | else | 1406 | else |
| 1407 | { | 1407 | adjust_intervals_for_deletion (buffer, start, -length); |
| 1408 | assume (- TYPE_MAXIMUM (ptrdiff_t) <= length); | ||
| 1409 | adjust_intervals_for_deletion (buffer, start, -length); | ||
| 1410 | } | ||
| 1411 | } | 1408 | } |
| 1412 | 1409 | ||
| 1413 | /* Merge interval I with its lexicographic successor. The resulting | 1410 | /* Merge interval I with its lexicographic successor. The resulting |
diff --git a/src/lisp.h b/src/lisp.h index 6638cc66e9f..e4a2caa1083 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -31,6 +31,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 31 | #include <limits.h> | 31 | #include <limits.h> |
| 32 | 32 | ||
| 33 | #include <intprops.h> | 33 | #include <intprops.h> |
| 34 | #include <verify.h> | ||
| 34 | 35 | ||
| 35 | INLINE_HEADER_BEGIN | 36 | INLINE_HEADER_BEGIN |
| 36 | 37 | ||
| @@ -113,28 +114,48 @@ typedef EMACS_UINT uprintmax_t; | |||
| 113 | 114 | ||
| 114 | /* Extra internal type checking? */ | 115 | /* Extra internal type checking? */ |
| 115 | 116 | ||
| 116 | /* Define an Emacs version of 'assert (COND)'. COND should be free of | 117 | /* Define Emacs versions of <assert.h>'s 'assert (COND)' and <verify.h>'s |
| 117 | side effects; it may be evaluated zero or more times. */ | 118 | 'assume (COND)'. COND should be free of side effects, as it may or |
| 119 | may not be evaluated. | ||
| 120 | |||
| 121 | 'eassert (COND)' checks COND at runtime if ENABLE_CHECKING is | ||
| 122 | defined and suppress_checking is false, and does nothing otherwise. | ||
| 123 | Emacs dies if COND is checked and is false. The suppress_checking | ||
| 124 | variable is initialized to 0 in alloc.c. Set it to 1 using a | ||
| 125 | debugger to temporarily disable aborting on detected internal | ||
| 126 | inconsistencies or error conditions. | ||
| 127 | |||
| 128 | In some cases, a good compiler may be able to optimize away the | ||
| 129 | eassert macro even if ENABLE_CHECKING is true, e.g., if XSTRING (x) | ||
| 130 | uses eassert to test STRINGP (x), but a particular use of XSTRING | ||
| 131 | is invoked only after testing that STRINGP (x) is true, making the | ||
| 132 | test redundant. | ||
| 133 | |||
| 134 | eassume is like eassert except that it also causes the compiler to | ||
| 135 | assume that COND is true afterwards, regardless of whether runtime | ||
| 136 | checking is enabled. This can improve performance in some cases, | ||
| 137 | though it can degrade performance in others. It's often suboptimal | ||
| 138 | for COND to call external functions or access volatile storage. */ | ||
| 139 | |||
| 118 | #ifndef ENABLE_CHECKING | 140 | #ifndef ENABLE_CHECKING |
| 119 | # define eassert(cond) ((void) (0 && (cond))) /* Check that COND compiles. */ | 141 | # define eassert(cond) ((void) (0 && (cond))) /* Check that COND compiles. */ |
| 142 | # define eassume(cond) assume (cond) | ||
| 120 | #else /* ENABLE_CHECKING */ | 143 | #else /* ENABLE_CHECKING */ |
| 121 | 144 | ||
| 122 | extern _Noreturn void die (const char *, const char *, int); | 145 | extern _Noreturn void die (const char *, const char *, int); |
| 123 | 146 | ||
| 124 | /* The suppress_checking variable is initialized to 0 in alloc.c. Set | ||
| 125 | it to 1 using a debugger to temporarily disable aborting on | ||
| 126 | detected internal inconsistencies or error conditions. | ||
| 127 | |||
| 128 | In some cases, a good compiler may be able to optimize away the | ||
| 129 | eassert macro altogether, e.g., if XSTRING (x) uses eassert to test | ||
| 130 | STRINGP (x), but a particular use of XSTRING is invoked only after | ||
| 131 | testing that STRINGP (x) is true, making the test redundant. */ | ||
| 132 | extern bool suppress_checking EXTERNALLY_VISIBLE; | 147 | extern bool suppress_checking EXTERNALLY_VISIBLE; |
| 133 | 148 | ||
| 134 | # define eassert(cond) \ | 149 | # define eassert(cond) \ |
| 135 | (suppress_checking || (cond) \ | 150 | (suppress_checking || (cond) \ |
| 136 | ? (void) 0 \ | 151 | ? (void) 0 \ |
| 137 | : die (# cond, __FILE__, __LINE__)) | 152 | : die (# cond, __FILE__, __LINE__)) |
| 153 | # define eassume(cond) \ | ||
| 154 | (suppress_checking \ | ||
| 155 | ? assume (cond) \ | ||
| 156 | : (cond) \ | ||
| 157 | ? (void) 0 \ | ||
| 158 | : die (# cond, __FILE__, __LINE__)) | ||
| 138 | #endif /* ENABLE_CHECKING */ | 159 | #endif /* ENABLE_CHECKING */ |
| 139 | 160 | ||
| 140 | 161 | ||
diff --git a/src/macfont.m b/src/macfont.m index 206a810c239..b3bf96d8c4e 100644 --- a/src/macfont.m +++ b/src/macfont.m | |||
| @@ -2817,7 +2817,6 @@ macfont_shape (Lisp_Object lgstring) | |||
| 2817 | } | 2817 | } |
| 2818 | 2818 | ||
| 2819 | len = i; | 2819 | len = i; |
| 2820 | assume (len <= TYPE_MAXIMUM (EMACS_INT) - 2); | ||
| 2821 | 2820 | ||
| 2822 | if (INT_MAX / 2 < len) | 2821 | if (INT_MAX / 2 < len) |
| 2823 | memory_full (SIZE_MAX); | 2822 | memory_full (SIZE_MAX); |