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