diff options
author | David Mitchell <davem@iabyn.com> | 2020-10-30 20:50:58 +0000 |
---|---|---|
committer | David Mitchell <davem@iabyn.com> | 2020-10-30 20:50:58 +0000 |
commit | e050064b67c501e9fdc7bc3f513ba2b8b9e795f8 (patch) | |
tree | e22e1acf43eaf92b1a72b0d734f5373ea6cd81a9 /op.c | |
parent | c8c367581c3333c38d07481e2ea8d81171403c81 (diff) | |
download | perl-e050064b67c501e9fdc7bc3f513ba2b8b9e795f8.tar.gz |
Perl_custom_op_get_field(): remove undef behaviour
Thus function has a couple a switches with
default:
NOT_REACHED; /* NOTREACHED */
but clang is complaining that the value returned by the function is
undefined if those default branches are taken, since the 'any' variable
doesn't get set in that path.
Replace the NOTREACHED with a croak("panic: ..."). It's possible (albeit
not intended) for Perl_custom_op_get_field() to be called with a 'field'
arg which triggers the default case. So if this ever happens, make it
clear that something has gone wrong, rather than just silently
continuing on non-debugging builds.
In any case, this shuts up clang.
Diffstat (limited to 'op.c')
-rw-r--r-- | op.c | 14 |
1 files changed, 6 insertions, 8 deletions
@@ -18100,6 +18100,7 @@ Perl_custom_op_get_field(pTHX_ const OP *o, const xop_flags_enum field) else xop = INT2PTR(XOP *, SvIV(HeVAL(he))); } + { XOPRETANY any; if(field == XOPe_xop_ptr) { @@ -18121,7 +18122,10 @@ Perl_custom_op_get_field(pTHX_ const OP *o, const xop_flags_enum field) any.xop_peep = xop->xop_peep; break; default: - NOT_REACHED; /* NOTREACHED */ + field_panic: + Perl_croak(aTHX_ + "panic: custom_op_get_field(): invalid field %d\n", + (int)field); break; } } else { @@ -18139,17 +18143,11 @@ Perl_custom_op_get_field(pTHX_ const OP *o, const xop_flags_enum field) any.xop_peep = XOPd_xop_peep; break; default: - NOT_REACHED; /* NOTREACHED */ + goto field_panic; break; } } } - /* On some platforms (HP-UX, IA64) gcc emits a warning for this function: - * op.c: In function 'Perl_custom_op_get_field': - * op.c:...: warning: 'any.xop_name' may be used uninitialized in this function [-Wmaybe-uninitialized] - * This is because on those platforms (with -DEBUGGING) NOT_REACHED - * expands to assert(0), which expands to ((0) ? (void)0 : - * __assert(...)), and gcc doesn't know that __assert can never return. */ return any; } } |