This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH, libcpp]: Correctly advance the pointer to an aligned address.


Hello!

The formulae to advance the pointer to an aligned address is:

/* This macro rounds x up to the y boundary.  */
#define ROUND_UP(x,y) (((x) + (y) - 1) & ~((y) - 1))

Another example of missing "-1" can be found in libcpp,
lex.c/search_line_sse42. Luckily, we already checked for unaligned
input, so the bug is benign, but nevertheless, we should use the
correct value.

2015-11-03  Uros Bizjak  <ubizjak@gmail.com>

    * lex.c (search_line_sse42): Correctly advance the pointer to an
    aligned address.

Patch was bootstrapped and regression tested on x86_64-linux-gnu {,-m32}.

Committed to mainline SVN as obvious.

Uros.

Index: lex.c
===================================================================
--- lex.c       (revision 229712)
+++ lex.c       (working copy)
@@ -447,7 +447,7 @@ search_line_sse42 (const uchar *s, const uchar *en
       /* Advance the pointer to an aligned address.  We will re-scan a
         few bytes, but we no longer need care for reading past the
         end of a page, since we're guaranteed a match.  */
-      s = (const uchar *)((si + 16) & -16);
+      s = (const uchar *)((si + 15) & -16);
     }

   /* Main loop, processing 16 bytes at a time.  */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]