# HG changeset patch # User Petter T. # Date 1699134821 -3600 # Node ID 713c819e8b142f78cbaae1bed406a740ee7aca89 # Parent dec46ae4323195f702e30ebd5cbe34adb7ac4198 Don't do static_cast before type check (bug #64858) * pt-bytecode-vm.cc: Move static_cast inside if-statement to avoid undefined behaviour warning. diff -r dec46ae43231 -r 713c819e8b14 libinterp/parse-tree/pt-bytecode-vm.cc --- a/libinterp/parse-tree/pt-bytecode-vm.cc Sun Nov 05 10:25:29 2023 +0100 +++ b/libinterp/parse-tree/pt-bytecode-vm.cc Sat Nov 04 22:53:41 2023 +0100 @@ -1775,17 +1775,25 @@ // If the slot value is defined it is a octave_cached_value, since only // this opcode and SET_FOLDED_CST writes to the slot. + bool did_it = false; octave_base_value *ovb = bsp[slot].ovb; - octave_cached_value *ovbc = static_cast (ovb); - if (ovb->is_defined () && ovbc->cache_is_valid ()) - { - // Use the cached value. Push it to the stack. - PUSH_OV (ovbc->get_cached_value ()); - // Jump over the initialization code (the folded code) of the cached value - int target = USHORT_FROM_UCHARS (b0, b1); - ip = code + target; - } - else + if (ovb->is_defined ()) + { + octave_cached_value *ovbc = static_cast (ovb); + if (ovbc->cache_is_valid ()) + { + // Use the cached value. Push it to the stack. + PUSH_OV (ovbc->get_cached_value ()); + // Jump over the initialization code (the folded code) of the + // cached value + int target = USHORT_FROM_UCHARS (b0, b1); + ip = code + target; + + did_it = true; + } + } + + if (! did_it) { // Put a octave_cached_value in the slot for SET_FOLDED_CST bsp[slot].ov = octave_value {new octave_cached_value};