This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/78809] Inline strcmp with small constant strings
- From: "qing.zhao at oracle dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 24 Oct 2017 19:04:17 +0000
- Subject: [Bug middle-end/78809] Inline strcmp with small constant strings
- Auto-submitted: auto-generated
- References: <bug-78809-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78809
--- Comment #15 from Qing Zhao <qing.zhao at oracle dot com> ---
(In reply to Wilco from comment 14)
> The only reason we have to do a character by character comparison is because we
> cannot read beyond the end of a string. However when we know the size or
> alignment we can safely process a string one word at a time.
is it possible that “NULL_terminator” is in the middle of the string even
though we
know the size or alignment? for example:
const char s[8] = “abcd\0abc”; // null byte in the middle of the string
int f2(void) { return __builtin_strcmp(s, "abc") != 0; }
int f3(void) { return __builtin_strcmp(s, “abc”); }
can either of the above f2 or f3 been optimized to memcmp? seems not.