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