Skip to content

Commit 03c0977

Browse files
authored
Fix up GCC compiler detection in ManyConfigTests (#670)
Also, add fixes/suppressions for the inevitable warnings that have appeared due to the CI job not running with warnings.
1 parent 95181ff commit 03c0977

File tree

7 files changed

+40
-19
lines changed

7 files changed

+40
-19
lines changed

.github/workflows/dev.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,7 @@ jobs:
269269
env:
270270
# Disallowing shadowing would be very spammy for unity builds, because the
271271
# same variable name can be used in multiple files.
272-
# We disable format truncation/overflow because the heuristics used for
273-
# these warnings are not very good, and are apparently affected by the
274-
# inliner, which is used much less aggressively in unity builds.
275-
CFLAGS_UNITY: "-Wno-shadow -Wno-format-truncation -Wno-format-overflow"
272+
CFLAGS_UNITY: "-Wno-shadow"
276273
steps:
277274
- name: Checkout
278275
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
@@ -321,7 +318,7 @@ jobs:
321318

322319
- name: Configure
323320
shell: msys2 {0}
324-
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
321+
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
325322

326323
- name: Build
327324
shell: msys2 {0}
@@ -392,7 +389,7 @@ jobs:
392389
run: |
393390
set -e
394391
# TODO: Set -DCMAKE_COMPILE_WARNING_AS_ERROR=ON (there's currently a build failure on S390x)
395-
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
392+
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
396393
ninja -C build
397394
(cd build && ctest -j3 --output-on-failure)
398395

maint/ManyConfigTests

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,11 @@ OFLAGS="-O0"
113113
CC="${CC:=cc}"
114114
ISGCC=0
115115

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

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

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

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

165-
CFLAGS="$CFLAGS" \
165+
CC="$CC" CFLAGS="$CFLAGS" \
166166
$srcdir/configure $opts >/dev/null 2>teststderrM
167167
if [ $? -ne 0 ]; then
168168
echo " "

src/pcre2_compile.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8115,6 +8115,7 @@ for (;; pptr++)
81158115
cb->external_flags |= PCRE2_HASBKC; /* Record */
81168116
#if PCRE2_CODE_UNIT_WIDTH == 32
81178117
meta_arg = OP_ALLANY;
8118+
(void)utf; /* Avoid compiler warning. */
81188119
#else
81198120
if (!utf) meta_arg = OP_ALLANY;
81208121
#endif

src/pcre2_compile_class.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,9 @@ if (xoptions & PCRE2_EXTRA_CASELESS_RESTRICT)
524524

525525
if (xoptions & PCRE2_EXTRA_TURKISH_CASING)
526526
class_options |= PARSE_CLASS_TURKISH_UTF;
527+
#else
528+
(void)options; /* Avoid compiler warning. */
529+
(void)xoptions; /* Avoid compiler warning. */
527530
#endif
528531

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

910+
#ifndef SUPPORT_UNICODE
911+
(void)xoptions; /* Avoid compiler warning. */
912+
#endif
913+
907914
/* If caseless matching is required, scan the range and process alternate
908915
cases. In Unicode, there are 8-bit characters that have alternate cases that
909916
are greater than 255 and vice-versa (though these may be ignored if caseless
@@ -1079,6 +1086,10 @@ BOOL utf = FALSE;
10791086
uint32_t xclass_props;
10801087
PCRE2_UCHAR *class_uchardata;
10811088
class_ranges* cranges;
1089+
#else
1090+
(void)has_bitmap; /* Avoid compiler warning. */
1091+
(void)errorcodeptr; /* Avoid compiler warning. */
1092+
(void)lengthptr; /* Avoid compiler warning. */
10821093
#endif
10831094

10841095
/* If an XClass contains a negative special such as \S, we need to flip the

src/pcre2_jit_char_inc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,8 @@ BOOL has_cmov, last_range_set;
519519
sljit_u32 category_list = 0;
520520
sljit_u32 items;
521521
int typereg = TMP1;
522+
#else
523+
(void)c; /* Avoid compiler warning. */
522524
#endif /* SUPPORT_UNICODE */
523525

524526
SLJIT_ASSERT(common->locals_size >= SSIZE_OF(sw));

src/pcre2_match.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,10 @@ PCRE2_SIZE length;
365365
PCRE2_SPTR eptr;
366366
PCRE2_SPTR eptr_start;
367367

368+
#ifndef SUPPORT_UNICODE
369+
(void)caseopts; /* Avoid compiler warning. */
370+
#endif
371+
368372
/* Deal with an unset group. The default is no match, but there is an option to
369373
match an empty string. */
370374

src/pcre2grep.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3440,16 +3440,18 @@ if (isdirectory(pathname))
34403440
while ((nextfile = readdirectory(dir)) != NULL)
34413441
{
34423442
int frc;
3443-
size_t fnlength = strlen(pathname) + strlen(nextfile) + 2;
3444-
if (fnlength > FNBUFSIZ)
3443+
int prc;
3444+
if (strlen(pathname) + strlen(nextfile) + 2 > sizeof(childpath) ||
3445+
(prc = snprintf(childpath, sizeof(childpath), "%s%c%s", pathname,
3446+
FILESEP, nextfile)) < 0 ||
3447+
prc >= (int)sizeof(childpath))
34453448
{
34463449
/* LCOV_EXCL_START - this is a "never" event */
34473450
fprintf(stderr, "pcre2grep: recursive filename is too long\n");
34483451
rc = 2;
34493452
break;
34503453
/* LCOV_EXCL_STOP */
34513454
}
3452-
snprintf(childpath, sizeof(childpath), "%s%c%s", pathname, FILESEP, nextfile);
34533455

34543456
/* If the realpath() function is available, we can try to prevent endless
34553457
recursion caused by a symlink pointing to a parent directory (GitHub
@@ -3509,15 +3511,19 @@ if (iswild(pathname))
35093511
while ((nextfile = readdirectory(dir)) != NULL)
35103512
{
35113513
int frc;
3512-
if (strlen(pathname) + strlen(nextfile) + 1 > sizeof(buffer))
3514+
int prc;
3515+
if (strlen(pathname) + strlen(nextfile) + 1 > sizeof(buffer) ||
3516+
(prc = snprintf(buffer, sizeof(buffer), "%s%s", pathname,
3517+
nextfile)) < 0 ||
3518+
prc >= (int)sizeof(buffer))
35133519
{
35143520
/* LCOV_EXCL_START - this is a "never" event */
35153521
fprintf(stderr, "pcre2grep: wildcard filename is too long\n");
35163522
rc = 2;
35173523
break;
35183524
/* LCOV_EXCL_STOP */
35193525
}
3520-
snprintf(buffer, sizeof(buffer), "%s%s", pathname, nextfile);
3526+
35213527
frc = grep_or_recurse(buffer, dir_recurse, FALSE);
35223528
if (frc > 1) rc = frc;
35233529
else if (frc == 0 && rc == 1) rc = 0;
@@ -4064,10 +4070,10 @@ for (i = 1; i < argc; i++)
40644070
(int)strlen(arg) : (int)(argequals - arg);
40654071

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

0 commit comments

Comments
 (0)