diff options
| author | Paul Eggert | 2020-08-03 15:21:58 -0700 |
|---|---|---|
| committer | Paul Eggert | 2020-08-03 19:08:58 -0700 |
| commit | a4ed198e8f3754a59cabbb03ab6bae8a49597ee0 (patch) | |
| tree | 16b32bfde1b9c9becc75859aff248709ecf72b43 /src/alloc.c | |
| parent | ca419812d35f252fca2708ffdd132c223d094c0f (diff) | |
| download | emacs-a4ed198e8f3754a59cabbb03ab6bae8a49597ee0.tar.gz emacs-a4ed198e8f3754a59cabbb03ab6bae8a49597ee0.zip | |
Simplify pointer computation in mark_maybe_object
* src/alloc.c (mark_maybe_object):
Use simpler way to avoid -fsanitize=undefined false alarms,
by converting the word tag to intptr_t first.
Omit now-unnecessary runtime overflow check.
(mark_memory): Work even if UINTPTR_MAX <= INT_MAX (!).
Diffstat (limited to 'src/alloc.c')
| -rw-r--r-- | src/alloc.c | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/src/alloc.c b/src/alloc.c index 5220ef84783..3a02ef3f8c4 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -4625,7 +4625,7 @@ mark_maybe_object (Lisp_Object obj) | |||
| 4625 | #endif | 4625 | #endif |
| 4626 | 4626 | ||
| 4627 | int type_tag = XTYPE (obj); | 4627 | int type_tag = XTYPE (obj); |
| 4628 | intptr_t offset; | 4628 | intptr_t pointer_word_tag = LISP_WORD_TAG (type_tag), offset, ipo; |
| 4629 | 4629 | ||
| 4630 | switch (type_tag) | 4630 | switch (type_tag) |
| 4631 | { | 4631 | { |
| @@ -4641,19 +4641,8 @@ mark_maybe_object (Lisp_Object obj) | |||
| 4641 | break; | 4641 | break; |
| 4642 | } | 4642 | } |
| 4643 | 4643 | ||
| 4644 | bool overflow | 4644 | INT_ADD_WRAPV ((intptr_t) XLP (obj), offset - pointer_word_tag, &ipo); |
| 4645 | = INT_SUBTRACT_WRAPV (offset, LISP_WORD_TAG (type_tag), &offset); | 4645 | void *po = (void *) ipo; |
| 4646 | #if !defined WIDE_EMACS_INT || USE_LSB_TAG | ||
| 4647 | /* If we don't use wide integers, then `intptr_t' should always be | ||
| 4648 | large enough to not overflow. Furthermore, when using the least | ||
| 4649 | significant bits as tag bits, the tag is small enough to not | ||
| 4650 | overflow either. */ | ||
| 4651 | eassert (!overflow); | ||
| 4652 | #else | ||
| 4653 | (void) overflow; | ||
| 4654 | #endif | ||
| 4655 | INT_ADD_WRAPV (offset, (intptr_t) (char *) XLP (obj), &offset); | ||
| 4656 | void *po = (char *) offset; | ||
| 4657 | 4646 | ||
| 4658 | /* If the pointer is in the dump image and the dump has a record | 4647 | /* If the pointer is in the dump image and the dump has a record |
| 4659 | of the object starting at the place where the pointer points, we | 4648 | of the object starting at the place where the pointer points, we |
| @@ -4856,7 +4845,7 @@ mark_memory (void const *start, void const *end) | |||
| 4856 | 4845 | ||
| 4857 | for (pp = start; (void const *) pp < end; pp += GC_POINTER_ALIGNMENT) | 4846 | for (pp = start; (void const *) pp < end; pp += GC_POINTER_ALIGNMENT) |
| 4858 | { | 4847 | { |
| 4859 | char *p = *(char *const *) pp; | 4848 | void *p = *(void *const *) pp; |
| 4860 | mark_maybe_pointer (p); | 4849 | mark_maybe_pointer (p); |
| 4861 | 4850 | ||
| 4862 | /* Unmask any struct Lisp_Symbol pointer that make_lisp_symbol | 4851 | /* Unmask any struct Lisp_Symbol pointer that make_lisp_symbol |
| @@ -4864,8 +4853,9 @@ mark_memory (void const *start, void const *end) | |||
| 4864 | On a host with 32-bit pointers and 64-bit Lisp_Objects, | 4853 | On a host with 32-bit pointers and 64-bit Lisp_Objects, |
| 4865 | a Lisp_Object might be split into registers saved into | 4854 | a Lisp_Object might be split into registers saved into |
| 4866 | non-adjacent words and P might be the low-order word's value. */ | 4855 | non-adjacent words and P might be the low-order word's value. */ |
| 4867 | p = (char *) ((uintptr_t) p + (uintptr_t) lispsym); | 4856 | intptr_t ip; |
| 4868 | mark_maybe_pointer (p); | 4857 | INT_ADD_WRAPV ((intptr_t) p, (intptr_t) lispsym, &ip); |
| 4858 | mark_maybe_pointer ((void *) ip); | ||
| 4869 | 4859 | ||
| 4870 | verify (alignof (Lisp_Object) % GC_POINTER_ALIGNMENT == 0); | 4860 | verify (alignof (Lisp_Object) % GC_POINTER_ALIGNMENT == 0); |
| 4871 | if (alignof (Lisp_Object) == GC_POINTER_ALIGNMENT | 4861 | if (alignof (Lisp_Object) == GC_POINTER_ALIGNMENT |