Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 027e91c

Browse files
[[ UninitialisedVars ]] Improve MCUnreachable uses
* Add `MCUnreachableReturn` macro, which allows to return (with a value if needed) right after a call to `MCUnreachable` * Add `__MCUnreachable` for GCC, Clang and LLVM-compiled engine in Release mode, which calls `__builtin_unreachable`
1 parent e60ea26 commit 027e91c

15 files changed

Lines changed: 47 additions & 67 deletions

engine/src/combiners.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,7 @@ template<Operation x_combiner, bool x_dst_alpha, bool x_src_alpha> INLINE uint32
402402
r = 0x00ffffff;
403403
break;
404404
default:
405-
MCUnreachable();
406-
// MCUnreachable has no action in Release mode
407-
return 0;
405+
MCUnreachableReturn(0);
408406
}
409407

410408
if (x_src_alpha && x_dst_alpha)
@@ -536,9 +534,7 @@ template<int x_combiner, bool x_dst_alpha, bool x_src_alpha> INLINE uint32_t ari
536534
}
537535
break;
538536
default:
539-
MCUnreachable();
540-
// MCUnreachable has no action in Release mode
541-
return 0;
537+
MCUnreachableReturn(0);
542538
}
543539

544540
if (x_src_alpha && x_dst_alpha)
@@ -652,9 +648,7 @@ template<int x_combiner, bool x_dst_alpha, bool x_src_alpha> INLINE uint32_t bas
652648
r = packed_multiply_bounded(src, packed_inverse(dst)) + dst;
653649
break;
654650
default:
655-
MCUnreachable();
656-
// MCUnreachable has no action in Release mode
657-
return 0;
651+
MCUnreachableReturn(0);
658652
}
659653

660654
return r;
@@ -880,9 +874,7 @@ template<int x_combiner, bool x_dst_alpha, bool x_src_alpha> INLINE uint32_t adv
880874
t_alpha = t_src_alpha + t_dst_alpha - downscale(t_src_alpha_dst_alpha);
881875
break;
882876
default:
883-
MCUnreachable();
884-
// MCUnreachable has no action in Release mode
885-
return 0;
877+
MCUnreachableReturn(0);
886878
}
887879

888880
if (x_dst_alpha)

engine/src/exec-strings.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2711,10 +2711,7 @@ void MCStringsExecSort(MCExecContext& ctxt, Sort_type p_dir, Sort_type p_form, M
27112711

27122712
default:
27132713
delete[] t_indicies;
2714-
ctxt . Throw();
2715-
MCUnreachable();
2716-
// MCUnreachable has no effect on Fast or Release mode
2717-
return;
2714+
MCUnreachableReturn();
27182715
}
27192716

27202717
MCStringsSortIndirect(t_indicies, p_count, t_sort_compare, t_sort_keys);

engine/src/foundation-legacy.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,9 +1798,7 @@ static bool save_array_to_stream(void *p_context, MCArrayRef p_array, MCNameRef
17981798
}
17991799
break;
18001800
default:
1801-
MCUnreachable();
1802-
// MCUnreachable has no action in Release mode
1803-
return false;
1801+
MCUnreachableReturn(false);
18041802
}
18051803

18061804
IO_stat t_stat;

engine/src/gradient.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,8 +1176,7 @@ template<MCGradientFillKind x_type> static inline int4 compute_index(int4 p_x, i
11761176
}
11771177
break;
11781178
default:
1179-
MCUnreachable();
1180-
return NULL;
1179+
MCUnreachableReturn(0);
11811180
}
11821181
if (p_mirror)
11831182
{

engine/src/handler.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,9 +1025,7 @@ void MCHandler::compile(MCSyntaxFactoryRef ctxt)
10251025
t_type = kMCSyntaxHandlerTypeAfterMessage;
10261026
break;
10271027
default:
1028-
MCUnreachable();
1029-
// MCUnreachable has no action in Release mode
1030-
return;
1028+
MCUnreachableReturn();
10311029
}
10321030

10331031
MCSyntaxFactoryBeginHandler(ctxt, t_type, name);

engine/src/mac-pasteboard.mm

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,7 @@ bool MCPlatformPasteboardStore(MCPlatformPasteboardRef p_pasteboard, MCPlatformP
394394
// t_flavor_string = @"";
395395
// break;
396396
default:
397-
MCUnreachable();
398-
// MCUnreachable has no action in Release mode
399-
return false;
397+
MCUnreachableReturn(false);
400398
}
401399
[t_flavor_strings addObject: t_flavor_string];
402400
}

engine/src/mbliphoneapp.mm

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -803,9 +803,7 @@ - (void)orientationChanged:(NSNotification *)notification
803803
t_new_orientation = UIInterfaceOrientationLandscapeLeft;
804804
break;
805805
default:
806-
MCUnreachable();
807-
// MCUnreachable() has no effect in Release mode
808-
return;
806+
MCUnreachableReturn();
809807
}
810808

811809
// Store the pending notification.

engine/src/metacontext.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,7 @@ void MCMetaContext::clear(const MCRectangle *rect)
663663

664664
MCRegionRef MCMetaContext::computemaskregion(void)
665665
{
666-
MCUnreachable();
667-
return NULL;
666+
MCUnreachableReturn(NULL);
668667
}
669668

670669

engine/src/operator.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,7 @@ Parse_stat MCIs::parse(MCScriptPoint &sp, Boolean the)
11621162
else if (te -> type == TT_CLASS)
11631163
delimiter = (Chunk_term)te -> which;
11641164
else
1165-
MCUnreachable();
1165+
MCUnreachableReturn(PS_ERROR);
11661166

11671167
if (delimiter == CT_CHARACTER)
11681168
if (form == IT_NOT)
@@ -2055,9 +2055,7 @@ void MCIs::compile(MCSyntaxFactoryRef ctxt)
20552055
t_method = form == IT_NORMAL ? kMCGraphicsEvalIsARectangleMethodInfo : kMCGraphicsEvalIsNotARectangleMethodInfo;
20562056
break;
20572057
default:
2058-
MCUnreachable();
2059-
// MCUnreachable has no action in Release mode
2060-
return;
2058+
MCUnreachableReturn();
20612059
}
20622060

20632061
right -> compile(ctxt);
@@ -2096,9 +2094,7 @@ void MCIs::compile(MCSyntaxFactoryRef ctxt)
20962094
t_method = form == IT_AMONG ? kMCStringsEvalIsAmongTheItemsOfMethodInfo : kMCStringsEvalIsNotAmongTheItemsOfMethodInfo;
20972095
break;
20982096
default:
2099-
MCUnreachable();
2100-
// MCUnreachable has no action in Release mode
2101-
return;
2097+
MCUnreachableReturn();
21022098
}
21032099
break;
21042100
case IT_IN:
@@ -2130,9 +2126,7 @@ void MCIs::compile(MCSyntaxFactoryRef ctxt)
21302126
t_is_unary = true;
21312127
break;
21322128
default:
2133-
MCUnreachable();
2134-
// MCUnreachable has no action in Release mode
2135-
return;
2129+
MCUnreachableReturn();
21362130
}
21372131
if (!t_is_unary)
21382132
left -> compile(ctxt);
@@ -2302,9 +2296,7 @@ void MCThere::compile(MCSyntaxFactoryRef ctxt)
23022296
t_method = form == IT_NORMAL ? kMCFilesEvalThereIsAFolderMethodInfo : kMCFilesEvalThereIsNotAFolderMethodInfo;
23032297
break;
23042298
default:
2305-
MCUnreachable();
2306-
// MCUnreachable has no action in Release mode
2307-
return;
2299+
MCUnreachableReturn();
23082300
}
23092301
}
23102302
else

engine/src/redraw.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,7 @@ MCLayerModeHint MCControl::layer_computeattrs(bool p_commit)
213213
}
214214
else
215215
{
216-
MCUnreachable();
217-
// MCUnreachable has no action in Release mode. Return current value
218-
return m_layer_mode;
216+
MCUnreachableReturn(m_layer_mode);
219217
}
220218

221219
// Now compute the sprite attribute.

0 commit comments

Comments
 (0)