This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH, libcpp]: Correctly advance the pointer to an aligned address.
- From: Uros Bizjak <ubizjak at gmail dot com>
- To: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Cc: Richard Henderson <rth at redhat dot com>
- Date: Tue, 3 Nov 2015 20:02:18 +0100
- Subject: [PATCH, libcpp]: Correctly advance the pointer to an aligned address.
- Authentication-results: sourceware.org; auth=none
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. */