Skip to content

Commit

Permalink
Fix up GCC compiler detection in ManyConfigTests (#670)
Browse files Browse the repository at this point in the history
Also, add fixes/suppressions for the inevitable warnings that have appeared due to the CI job not running with warnings.
  • Loading branch information
NWilson authored Jan 13, 2025
1 parent 95181ff commit 03c0977
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 19 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,7 @@ jobs:
env:
# Disallowing shadowing would be very spammy for unity builds, because the
# same variable name can be used in multiple files.
# We disable format truncation/overflow because the heuristics used for
# these warnings are not very good, and are apparently affected by the
# inliner, which is used much less aggressively in unity builds.
CFLAGS_UNITY: "-Wno-shadow -Wno-format-truncation -Wno-format-overflow"
CFLAGS_UNITY: "-Wno-shadow"
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
Expand Down Expand Up @@ -321,7 +318,7 @@ jobs:

- name: Configure
shell: msys2 {0}
run: cmake -G Ninja -DPCRE2_BUILD_PCRE2_16=ON -DPCRE2_BUILD_PCRE2_32=ON -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=ON -DPCRE2_DEBUG=ON -DCMAKE_C_FLAGS="$CFLAGS_GCC_STYLE -Wno-format-truncation -Wno-format-overflow" -DCMAKE_COMPILE_WARNING_AS_ERROR=ON -DCMAKE_BUILD_TYPE=Release -B build
run: cmake -G Ninja -DPCRE2_BUILD_PCRE2_16=ON -DPCRE2_BUILD_PCRE2_32=ON -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=ON -DPCRE2_DEBUG=ON -DCMAKE_C_FLAGS="$CFLAGS_GCC_STYLE" -DCMAKE_COMPILE_WARNING_AS_ERROR=ON -DCMAKE_BUILD_TYPE=Release -B build

- name: Build
shell: msys2 {0}
Expand Down Expand Up @@ -392,7 +389,7 @@ jobs:
run: |
set -e
# TODO: Set -DCMAKE_COMPILE_WARNING_AS_ERROR=ON (there's currently a build failure on S390x)
cmake -G Ninja -DPCRE2_SUPPORT_JIT=ON -DPCRE2_BUILD_PCRE2_16=ON -DPCRE2_BUILD_PCRE2_32=ON -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=ON -DPCRE2_DEBUG=ON -DCMAKE_C_FLAGS="$CFLAGS_GCC_STYLE -Wno-format-truncation -Wno-format-overflow" -DCMAKE_COMPILE_WARNING_AS_ERROR=OFF -DCMAKE_BUILD_TYPE=RelWithDebInfo -B build
cmake -G Ninja -DPCRE2_SUPPORT_JIT=ON -DPCRE2_BUILD_PCRE2_16=ON -DPCRE2_BUILD_PCRE2_32=ON -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=ON -DPCRE2_DEBUG=ON -DCMAKE_C_FLAGS="$CFLAGS_GCC_STYLE" -DCMAKE_COMPILE_WARNING_AS_ERROR=OFF -DCMAKE_BUILD_TYPE=RelWithDebInfo -B build
ninja -C build
(cd build && ctest -j3 --output-on-failure)
Expand Down
12 changes: 6 additions & 6 deletions maint/ManyConfigTests
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,11 @@ OFLAGS="-O0"
CC="${CC:=cc}"
ISGCC=0

# If the compiler is gcc, add a lot of warning switches.
# If the compiler is GCC or Clang, add a lot of warning switches.

$CC --version >/tmp/pcre2ccversion 2>/dev/null
if [ $? -eq 0 ] && grep GCC /tmp/pcre2ccversion >/dev/null; then
CC_VER_OUTPUT=`printf '#ifdef __GNUC__\nGCC=yes\n#endif\n' | $CC -E -`
if [ $? -eq 0 ] && (echo "$CC_VER_OUTPUT" | grep GCC=yes) >/dev/null; then
echo "Treating $CC as GCC"
ISGCC=1
CFLAGS="$CFLAGS -Wall"
CFLAGS="$CFLAGS -Wextra"
Expand All @@ -138,10 +139,9 @@ if [ $? -eq 0 ] && grep GCC /tmp/pcre2ccversion >/dev/null; then
CFLAGS="$CFLAGS -Wstrict-prototypes"
CFLAGS="$CFLAGS -Warray-bounds"
CFLAGS="$CFLAGS -Wformat-overflow=2"
CFLAGS="$CFLAGS -Wformat-truncation=2"
CFLAGS="$CFLAGS -Wformat-truncation=1"
CFLAGS="$CFLAGS -Wdeclaration-after-statement"
fi
rm -f /tmp/pcre2ccversion

# This function runs a single test with the set of configuration options that
# are in $opts. The source directory must be set in srcdir. The function must
Expand All @@ -162,7 +162,7 @@ runtest()

if [ $dummy -eq 1 ]; then return; fi

CFLAGS="$CFLAGS" \
CC="$CC" CFLAGS="$CFLAGS" \
$srcdir/configure $opts >/dev/null 2>teststderrM
if [ $? -ne 0 ]; then
echo " "
Expand Down
1 change: 1 addition & 0 deletions src/pcre2_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -8115,6 +8115,7 @@ for (;; pptr++)
cb->external_flags |= PCRE2_HASBKC; /* Record */
#if PCRE2_CODE_UNIT_WIDTH == 32
meta_arg = OP_ALLANY;
(void)utf; /* Avoid compiler warning. */
#else
if (!utf) meta_arg = OP_ALLANY;
#endif
Expand Down
11 changes: 11 additions & 0 deletions src/pcre2_compile_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,9 @@ if (xoptions & PCRE2_EXTRA_CASELESS_RESTRICT)

if (xoptions & PCRE2_EXTRA_TURKISH_CASING)
class_options |= PARSE_CLASS_TURKISH_UTF;
#else
(void)options; /* Avoid compiler warning. */
(void)xoptions; /* Avoid compiler warning. */
#endif

/* Compute required space for the range. */
Expand Down Expand Up @@ -904,6 +907,10 @@ uint8_t *classbits = cb->classbits.classbits;
uint32_t c, byte_start, byte_end;
uint32_t classbits_end = (end <= 0xff ? end : 0xff);

#ifndef SUPPORT_UNICODE
(void)xoptions; /* Avoid compiler warning. */
#endif

/* If caseless matching is required, scan the range and process alternate
cases. In Unicode, there are 8-bit characters that have alternate cases that
are greater than 255 and vice-versa (though these may be ignored if caseless
Expand Down Expand Up @@ -1079,6 +1086,10 @@ BOOL utf = FALSE;
uint32_t xclass_props;
PCRE2_UCHAR *class_uchardata;
class_ranges* cranges;
#else
(void)has_bitmap; /* Avoid compiler warning. */
(void)errorcodeptr; /* Avoid compiler warning. */
(void)lengthptr; /* Avoid compiler warning. */
#endif

/* If an XClass contains a negative special such as \S, we need to flip the
Expand Down
2 changes: 2 additions & 0 deletions src/pcre2_jit_char_inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,8 @@ BOOL has_cmov, last_range_set;
sljit_u32 category_list = 0;
sljit_u32 items;
int typereg = TMP1;
#else
(void)c; /* Avoid compiler warning. */
#endif /* SUPPORT_UNICODE */

SLJIT_ASSERT(common->locals_size >= SSIZE_OF(sw));
Expand Down
4 changes: 4 additions & 0 deletions src/pcre2_match.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,10 @@ PCRE2_SIZE length;
PCRE2_SPTR eptr;
PCRE2_SPTR eptr_start;

#ifndef SUPPORT_UNICODE
(void)caseopts; /* Avoid compiler warning. */
#endif

/* Deal with an unset group. The default is no match, but there is an option to
match an empty string. */

Expand Down
20 changes: 13 additions & 7 deletions src/pcre2grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -3440,16 +3440,18 @@ if (isdirectory(pathname))
while ((nextfile = readdirectory(dir)) != NULL)
{
int frc;
size_t fnlength = strlen(pathname) + strlen(nextfile) + 2;
if (fnlength > FNBUFSIZ)
int prc;
if (strlen(pathname) + strlen(nextfile) + 2 > sizeof(childpath) ||
(prc = snprintf(childpath, sizeof(childpath), "%s%c%s", pathname,
FILESEP, nextfile)) < 0 ||
prc >= (int)sizeof(childpath))
{
/* LCOV_EXCL_START - this is a "never" event */
fprintf(stderr, "pcre2grep: recursive filename is too long\n");
rc = 2;
break;
/* LCOV_EXCL_STOP */
}
snprintf(childpath, sizeof(childpath), "%s%c%s", pathname, FILESEP, nextfile);

/* If the realpath() function is available, we can try to prevent endless
recursion caused by a symlink pointing to a parent directory (GitHub
Expand Down Expand Up @@ -3509,15 +3511,19 @@ if (iswild(pathname))
while ((nextfile = readdirectory(dir)) != NULL)
{
int frc;
if (strlen(pathname) + strlen(nextfile) + 1 > sizeof(buffer))
int prc;
if (strlen(pathname) + strlen(nextfile) + 1 > sizeof(buffer) ||
(prc = snprintf(buffer, sizeof(buffer), "%s%s", pathname,
nextfile)) < 0 ||
prc >= (int)sizeof(buffer))
{
/* LCOV_EXCL_START - this is a "never" event */
fprintf(stderr, "pcre2grep: wildcard filename is too long\n");
rc = 2;
break;
/* LCOV_EXCL_STOP */
}
snprintf(buffer, sizeof(buffer), "%s%s", pathname, nextfile);

frc = grep_or_recurse(buffer, dir_recurse, FALSE);
if (frc > 1) rc = frc;
else if (frc == 0 && rc == 1) rc = 0;
Expand Down Expand Up @@ -4064,10 +4070,10 @@ for (i = 1; i < argc; i++)
(int)strlen(arg) : (int)(argequals - arg);

if ((ret = snprintf(buff1, sizeof(buff1), "%.*s", baselen, op->long_name),
ret < 0 || ret > (int)sizeof(buff1)) ||
ret < 0 || ret >= (int)sizeof(buff1)) ||
(ret = snprintf(buff2, sizeof(buff2), "%s%.*s", buff1,
fulllen - baselen - 2, opbra + 1),
ret < 0 || ret > (int)sizeof(buff2)))
ret < 0 || ret >= (int)sizeof(buff2)))
{
/* LCOV_EXCL_START - this is a "never" event */
fprintf(stderr, "pcre2grep: Buffer overflow when parsing %s option\n",
Expand Down

0 comments on commit 03c0977

Please sign in to comment.