From 2d7c5dccc470536bc6bd2186e41b0bf9b240ec5e Mon Sep 17 00:00:00 2001 From: ph10 Date: Thu, 23 Apr 2020 16:50:45 +0000 Subject: Added tests for __attribute__((uninitialized)) to both the configure and CMake build files. Used to disable initialization of the match stack frames vector (clang has an automatic initialization feature). git-svn-id: svn://vcs.exim.org/pcre2/code/trunk@1246 6239d852-aaf2-0410-a92c-79f79f948069 --- src/config.h.in | 3 +++ src/pcre2_internal.h | 11 +++++++++++ src/pcre2_match.c | 3 ++- 3 files changed, 16 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/config.h.in b/src/config.h.in index 6b8eb7e..5406da0 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -52,6 +52,9 @@ sure both macros are undefined; an emulation function will then be used. */ LF does in an ASCII/Unicode environment. */ #undef EBCDIC_NL25 +/* Define this if your compiler supports __attribute__((uninitialized)) */ +#undef HAVE_ATTRIBUTE_UNINITIALIZED + /* Define to 1 if you have the `bcopy' function. */ #undef HAVE_BCOPY diff --git a/src/pcre2_internal.h b/src/pcre2_internal.h index cb81199..d8fad1e 100644 --- a/src/pcre2_internal.h +++ b/src/pcre2_internal.h @@ -76,6 +76,17 @@ typedef int BOOL; #include #endif +/* -ftrivial-auto-var-init support supports initializing all local variables +to avoid some classes of bug, but this can cause an unacceptable slowdown +for large on-stack arrays in hot functions. This macro lets us annotate +such arrays. */ + +#ifdef HAVE_ATTRIBUTE_UNINITIALIZED +#define PCRE2_KEEP_UNINITIALIZED __attribute__((uninitialized)) +#else +#define PCRE2_KEEP_UNINITIALIZED +#endif + /* Older versions of MSVC lack snprintf(). This define allows for warning/error-free compilation and testing with MSVC compilers back to at least MSVC 10/2010. Except for VC6 (which is missing some fundamentals and fails). */ diff --git a/src/pcre2_match.c b/src/pcre2_match.c index 5115b53..11289d5 100644 --- a/src/pcre2_match.c +++ b/src/pcre2_match.c @@ -6164,7 +6164,8 @@ proves to be too small, it is replaced by a larger one on the heap. To get a vector of the size required that is aligned for pointers, allocate it as a vector of pointers. */ -PCRE2_SPTR stack_frames_vector[START_FRAMES_SIZE/sizeof(PCRE2_SPTR)]; +PCRE2_SPTR stack_frames_vector[START_FRAMES_SIZE/sizeof(PCRE2_SPTR)] + PCRE2_KEEP_UNINITIALIZED; mb->stack_frames = (heapframe *)stack_frames_vector; /* A length equal to PCRE2_ZERO_TERMINATED implies a zero-terminated -- cgit v1.2.1