7e86df
From e050064b67c501e9fdc7bc3f513ba2b8b9e795f8 Mon Sep 17 00:00:00 2001
7e86df
From: David Mitchell <davem@iabyn.com>
7e86df
Date: Fri, 30 Oct 2020 20:50:58 +0000
7e86df
Subject: [PATCH] Perl_custom_op_get_field(): remove undef behaviour
7e86df
MIME-Version: 1.0
7e86df
Content-Type: text/plain; charset=UTF-8
7e86df
Content-Transfer-Encoding: 8bit
7e86df
7e86df
Thus function has a couple a switches with
7e86df
7e86df
               default:
7e86df
                   NOT_REACHED; /* NOTREACHED */
7e86df
7e86df
but clang is complaining that the value returned by the function is
7e86df
undefined if those default branches are taken, since the 'any' variable
7e86df
doesn't get set in that path.
7e86df
7e86df
Replace the NOTREACHED with a croak("panic: ..."). It's possible (albeit
7e86df
not intended) for Perl_custom_op_get_field() to be called with a 'field'
7e86df
arg which triggers the default case. So if this ever happens, make it
7e86df
clear that something has gone wrong, rather than just silently
7e86df
continuing on non-debugging builds.
7e86df
7e86df
In any case, this shuts up clang.
7e86df
7e86df
Signed-off-by: Petr Písař <ppisar@redhat.com>
7e86df
---
7e86df
 op.c | 14 ++++++--------
7e86df
 1 file changed, 6 insertions(+), 8 deletions(-)
7e86df
7e86df
diff --git a/op.c b/op.c
7e86df
index c30c6b7c8f..2933e2ed7d 100644
7e86df
--- a/op.c
7e86df
+++ b/op.c
7e86df
@@ -18100,6 +18100,7 @@ Perl_custom_op_get_field(pTHX_ const OP *o, const xop_flags_enum field)
7e86df
 	else
7e86df
 	    xop = INT2PTR(XOP *, SvIV(HeVAL(he)));
7e86df
     }
7e86df
+
7e86df
     {
7e86df
 	XOPRETANY any;
7e86df
 	if(field == XOPe_xop_ptr) {
7e86df
@@ -18121,7 +18122,10 @@ Perl_custom_op_get_field(pTHX_ const OP *o, const xop_flags_enum field)
7e86df
 		    any.xop_peep = xop->xop_peep;
7e86df
 		    break;
7e86df
 		default:
7e86df
-		    NOT_REACHED; /* NOTREACHED */
7e86df
+                  field_panic:
7e86df
+                    Perl_croak(aTHX_
7e86df
+                        "panic: custom_op_get_field(): invalid field %d\n",
7e86df
+                        (int)field);
7e86df
 		    break;
7e86df
 		}
7e86df
 	    } else {
7e86df
@@ -18139,17 +18143,11 @@ Perl_custom_op_get_field(pTHX_ const OP *o, const xop_flags_enum field)
7e86df
 		    any.xop_peep = XOPd_xop_peep;
7e86df
 		    break;
7e86df
 		default:
7e86df
-		    NOT_REACHED; /* NOTREACHED */
7e86df
+                    goto field_panic;
7e86df
 		    break;
7e86df
 		}
7e86df
 	    }
7e86df
 	}
7e86df
-        /* On some platforms (HP-UX, IA64) gcc emits a warning for this function:
7e86df
-         * op.c: In function 'Perl_custom_op_get_field':
7e86df
-         * op.c:...: warning: 'any.xop_name' may be used uninitialized in this function [-Wmaybe-uninitialized]
7e86df
-         * This is because on those platforms (with -DEBUGGING) NOT_REACHED
7e86df
-         * expands to assert(0), which expands to ((0) ? (void)0 :
7e86df
-         * __assert(...)), and gcc doesn't know that __assert can never return. */
7e86df
 	return any;
7e86df
     }
7e86df
 }
7e86df
-- 
7e86df
2.25.4
7e86df