Skip to content

Commit eff57c4

Browse files
committed
hv_undef_flags: eliminate spurious -Warray-bounds warning
Eliminates: In file included from perl.h:6205, from hv.c:35: hv.c: In function ‘Perl_hv_undef_flags’: hv.h:460:26: warning: array subscript [0, 9223372036854775807] is outside array bounds of ‘char[0]’ [-Warray-bounds] 460 | #define HEK_FLAGS(hek) (*((unsigned char *)(HEK_KEY(hek))+HEK_LEN(hek)+1)) | ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ embed.h:292:78: note: in definition of macro ‘hv_common’ 292 | mmon(a,b,c,d,e,f,g,h) Perl_hv_common(aTHX_ a,b,c,d,e,f,g,h) | ^ hv.h:474:34: note: in expansion of macro ‘HEK_FLAGS’ 474 | #define HEK_UTF8(hek) (HEK_FLAGS(hek) & HVhek_UTF8) | ^~~~~~~~~ hv.h:579:55: note: in expansion of macro ‘HEK_UTF8’ 579 | hv_common((hv), NULL, HEK_KEY(hek), HEK_LEN(hek), HEK_UTF8(hek), \ | ^~~~~~~~ hv.c:2268:19: note: in expansion of macro ‘hv_deletehek’ 2268 | (void)hv_deletehek(PL_stashcache, HvNAME_HEK(hv), G_DISCARD); | ^~~~~~~~~~~~ This does appear to be spurious, the gcc documentation claims not to check array bounds on trailing 1 element arrays for backward compatibility. This warning would be reasonable if the hek itself was allocated on the stack, part of an array of HEKs, or embedded in another struct, but HvNAME_HEK() returns a pointer to a HEK, for which gcc has no knowledge of the source. This warning only appears in debugging builds, but the only difference from non-debugging builds is the HEKfARG() within the DEBUG_o(), which is a simple cast to (void *), which I don't see having an effect on whether the compiler considers HEK itself as part of a structure, or of unknown origin. So I expect it's just a gcc bug, and there are know issues with this warning.
1 parent a7b106d commit eff57c4

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

hv.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2263,9 +2263,10 @@ Perl_hv_undef_flags(pTHX_ HV *hv, U32 flags)
22632263
* in sv_clear(), and changes here should be done there too */
22642264
if (PL_phase != PERL_PHASE_DESTRUCT && HvHasNAME(hv)) {
22652265
if (PL_stashcache) {
2266+
HEK *hek = HvNAME_HEK(hv);
22662267
DEBUG_o(Perl_deb(aTHX_ "hv_undef_flags clearing PL_stashcache for '%"
2267-
HEKf "'\n", HEKfARG(HvNAME_HEK(hv))));
2268-
(void)hv_deletehek(PL_stashcache, HvNAME_HEK(hv), G_DISCARD);
2268+
HEKf "'\n", HEKfARG(hek)));
2269+
(void)hv_deletehek(PL_stashcache, hek, G_DISCARD);
22692270
}
22702271
hv_name_set(hv, NULL, 0, 0);
22712272
}

0 commit comments

Comments
 (0)