GNU bug report logs - #65491
[PATCH] Improve performance allocating vectors

Previous Next

Package: emacs;

Reported by: Ihor Radchenko <yantar92 <at> posteo.net>

Date: Thu, 24 Aug 2023 10:00:02 UTC

Severity: wishlist

Tags: patch

Full log


View this message in rfc822 format

From: Po Lu <luangruo <at> yahoo.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 65491 <at> debbugs.gnu.org, Mattias EngdegÄrd <mattias.engdegard <at> gmail.com>, Eli Zaretskii <eliz <at> gnu.org>
Subject: bug#65491: [PATCH] Improve performance allocating vectors
Date: Mon, 18 Sep 2023 11:08:16 +0800
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:

>>> Even converting them back to their original pointer (which is what we do
>>> with tag/untag pairs) is documented to be well-defined if you compile
>>> using GCC.
>> Only if the consequent pointer designates the same object as the initial
>> pointer (of which I see no scrutable definition within GCC's
>> documentation.)
>
> IIUC the "if" here is talking about the fact that if the object is
> deallocated between the two casts, then you're on your own, of course.

Nope, (gcc)Arrays and Pointers is quite unequivocal:

   * `The result of converting a pointer to an integer or vice versa
     (C90 6.3.4, C99 and C11 6.3.2.3).'

     A cast from pointer to integer discards most-significant bits if
     the pointer representation is larger than the integer type,
     sign-extends(1) if the pointer representation is smaller than the
     integer type, otherwise the bits are unchanged.

     A cast from integer to pointer discards most-significant bits if
     the pointer representation is smaller than the integer type,
     extends according to the signedness of the integer type if the
     pointer representation is larger than the integer type, otherwise
     the bits are unchanged.

     When casting from pointer to integer and back again, the resulting
     pointer must reference the same object as the original pointer,
     otherwise the behavior is undefined.  That is, one may not use
     integer arithmetic to avoid the undefined behavior of pointer
     arithmetic as proscribed in C99 and C11 6.5.6/8.

and directly cites the apposite portions of the Standard.

> IIUC Mattias bumped into this after he made a few "innocent looking"
> changes to the vector allocation code.

I'll let Mattias fill us in.




This bug report was last modified 1 year and 263 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.