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