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