[Bf-blender-cvs] [11494e9472d] temp-unreachable-abort: BLI: add macro to indicate unreachable code

Jacques Lucke noreply at git.blender.org
Sat Mar 20 19:56:29 CET 2021


Commit: 11494e9472db54c0dc078c9d97fe9c53b763641b
Author: Jacques Lucke
Date:   Sat Mar 20 19:56:19 2021 +0100
Branches: temp-unreachable-abort
https://developer.blender.org/rB11494e9472db54c0dc078c9d97fe9c53b763641b

BLI: add macro to indicate unreachable code

===================================================================

M	source/blender/blenkernel/intern/attribute_access.cc
M	source/blender/blenkernel/intern/geometry_set.cc
M	source/blender/blenlib/BLI_listbase_wrapper.hh
A	source/blender/blenlib/BLI_unreachable.h
M	source/blender/blenlib/BLI_utildefines.h
M	source/blender/blenlib/CMakeLists.txt
M	source/blender/blenlib/intern/delaunay_2d.cc
M	source/blender/blenlib/intern/expr_pylike_eval.c
M	source/blender/blenlib/intern/mesh_intersect.cc
M	source/blender/blenlib/intern/polyfill_2d_beautify.c
M	source/blender/bmesh/tools/bmesh_bevel.c
M	source/blender/editors/animation/fmodifier_ui.c
M	source/blender/editors/object/object_add.c
M	source/blender/editors/sculpt_paint/sculpt_geodesic.c
M	source/blender/editors/space_buttons/space_buttons.c
M	source/blender/editors/space_node/node_draw.cc
M	source/blender/functions/FN_array_spans.hh
M	source/blender/functions/FN_multi_function_data_type.hh
M	source/blender/functions/FN_multi_function_param_type.hh
M	source/blender/functions/FN_spans.hh
M	source/blender/functions/intern/multi_function_network_evaluation.cc
M	source/blender/makesrna/intern/rna_access.c
M	source/blender/modifiers/intern/MOD_volume_displace.cc
M	source/blender/nodes/function/nodes/node_fn_boolean_math.cc
M	source/blender/nodes/function/nodes/node_fn_float_compare.cc
M	source/blender/nodes/geometry/nodes/node_geo_attribute_math.cc
M	source/blender/nodes/geometry/nodes/node_geo_attribute_vector_math.cc
M	source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_circle.cc
M	source/blender/nodes/intern/node_geometry_exec.cc
M	source/blender/nodes/intern/node_tree_ref.cc
M	source/blender/nodes/shader/nodes/node_shader_vector_math.cc
M	source/blender/nodes/shader/nodes/node_shader_vector_rotate.cc
M	source/blender/windowmanager/intern/wm_files.c
M	source/blender/windowmanager/xr/intern/wm_xr_session.c

===================================================================

diff --git a/source/blender/blenkernel/intern/attribute_access.cc b/source/blender/blenkernel/intern/attribute_access.cc
index 91b5b01e3eb..410a9b2e53d 100644
--- a/source/blender/blenkernel/intern/attribute_access.cc
+++ b/source/blender/blenkernel/intern/attribute_access.cc
@@ -299,8 +299,7 @@ static int attribute_data_type_complexity(const CustomDataType data_type)
 #endif
     default:
       /* Only accept "generic" custom data types used by the attribute system. */
-      BLI_assert(false);
-      return 0;
+      BLI_UNREACHABLE_ABORT;
   }
 }
 
@@ -341,8 +340,7 @@ static int attribute_domain_priority(const AttributeDomain domain)
       return 4;
     default:
       /* Domain not supported in nodes yet. */
-      BLI_assert(false);
-      return 0;
+      BLI_UNREACHABLE_ABORT;
   }
 }
 
@@ -703,8 +701,7 @@ bool GeometryComponent::attribute_domain_supported(const AttributeDomain domain)
 
 int GeometryComponent::attribute_domain_size(const AttributeDomain UNUSED(domain)) const
 {
-  BLI_assert(false);
-  return 0;
+  BLI_UNREACHABLE_ABORT;
 }
 
 ReadAttributePtr GeometryComponent::attribute_try_get_for_read(
diff --git a/source/blender/blenkernel/intern/geometry_set.cc b/source/blender/blenkernel/intern/geometry_set.cc
index f47d88cbeed..58f30ef1d7d 100644
--- a/source/blender/blenkernel/intern/geometry_set.cc
+++ b/source/blender/blenkernel/intern/geometry_set.cc
@@ -65,8 +65,7 @@ GeometryComponent *GeometryComponent::create(GeometryComponentType component_typ
     case GEO_COMPONENT_TYPE_VOLUME:
       return new VolumeComponent();
   }
-  BLI_assert(false);
-  return nullptr;
+  BLI_UNREACHABLE_ABORT;
 }
 
 void GeometryComponent::user_add() const
diff --git a/source/blender/blenlib/BLI_listbase_wrapper.hh b/source/blender/blenlib/BLI_listbase_wrapper.hh
index ed2a2b5e5ec..6313075db9c 100644
--- a/source/blender/blenlib/BLI_listbase_wrapper.hh
+++ b/source/blender/blenlib/BLI_listbase_wrapper.hh
@@ -26,6 +26,7 @@
  */
 
 #include "BLI_listbase.h"
+#include "BLI_unreachable.h"
 #include "DNA_listBase.h"
 
 namespace blender {
@@ -105,8 +106,7 @@ template<typename T> class ListBaseWrapper {
       }
       index++;
     }
-    BLI_assert(false);
-    return -1;
+    BLI_UNREACHABLE_ABORT;
   }
 };
 
diff --git a/source/blender/blenlib/BLI_unreachable.h b/source/blender/blenlib/BLI_unreachable.h
new file mode 100644
index 00000000000..2a38a7f578c
--- /dev/null
+++ b/source/blender/blenlib/BLI_unreachable.h
@@ -0,0 +1,33 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#pragma once
+
+#include "stdlib.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Is used to indicate that a line of code should never be reached at run-time. It is not necessary
+ * to return a value after this. */
+#define BLI_UNREACHABLE_ABORT \
+  BLI_assert(false); \
+  abort()
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h
index 1c6e6ffe578..183f6060cab 100644
--- a/source/blender/blenlib/BLI_utildefines.h
+++ b/source/blender/blenlib/BLI_utildefines.h
@@ -28,6 +28,7 @@
 /* avoid many includes for now */
 #include "BLI_compiler_compat.h"
 #include "BLI_sys_types.h"
+#include "BLI_unreachable.h"
 #include "BLI_utildefines_variadic.h"
 
 /* We could remove in future. */
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index 5a851b7b2cb..18ad9021558 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -284,6 +284,7 @@ set(SRC
   BLI_timecode.h
   BLI_timeit.hh
   BLI_timer.h
+  BLI_unreachable.h
   BLI_user_counter.hh
   BLI_utildefines.h
   BLI_utildefines_iter.h
diff --git a/source/blender/blenlib/intern/delaunay_2d.cc b/source/blender/blenlib/intern/delaunay_2d.cc
index 06a749ab921..86427bbbe1c 100644
--- a/source/blender/blenlib/intern/delaunay_2d.cc
+++ b/source/blender/blenlib/intern/delaunay_2d.cc
@@ -1920,14 +1920,12 @@ void add_edge_constraint(
     constexpr int unreasonably_large_crossings = 100000;
     if (!ok || crossings.size() == unreasonably_large_crossings) {
       /* Shouldn't happen but if does, just bail out. */
-      BLI_assert(false);
-      return;
+      BLI_UNREACHABLE_ABORT;
     }
     if (crossings[n].lambda == 0) {
       if (crossings[n].vert->visit_index == visit) {
         /* Shouldn't happen but if it does, just bail out. */
-        BLI_assert(false);
-        return;
+        BLI_UNREACHABLE_ABORT;
       }
       crossings[n].vert->visit_index = visit;
     }
diff --git a/source/blender/blenlib/intern/expr_pylike_eval.c b/source/blender/blenlib/intern/expr_pylike_eval.c
index f8618c54ea4..92189290c8e 100644
--- a/source/blender/blenlib/intern/expr_pylike_eval.c
+++ b/source/blender/blenlib/intern/expr_pylike_eval.c
@@ -642,8 +642,7 @@ static bool parse_add_func(ExprParseState *state, eOpCode code, int args, void *
       break;
 
     default:
-      BLI_assert(false);
-      return false;
+      BLI_UNREACHABLE_ABORT;
   }
 
   parse_add_op(state, code, 1 - args)->arg.ptr = funcptr;
diff --git a/source/blender/blenlib/intern/mesh_intersect.cc b/source/blender/blenlib/intern/mesh_intersect.cc
index b2b8dd4e900..d26c2f79a93 100644
--- a/source/blender/blenlib/intern/mesh_intersect.cc
+++ b/source/blender/blenlib/intern/mesh_intersect.cc
@@ -1936,8 +1936,7 @@ static IMesh extract_subdivided_tri(const CDT_data &cd,
   }
   if (t_in_cdt == -1) {
     std::cout << "Could not find " << t << " in cdt input tris\n";
-    BLI_assert(false);
-    return IMesh();
+    BLI_UNREACHABLE_ABORT;
   }
   int t_orig = in_tm.face(t)->orig;
   constexpr int inline_buf_size = 20;
diff --git a/source/blender/blenlib/intern/polyfill_2d_beautify.c b/source/blender/blenlib/intern/polyfill_2d_beautify.c
index 7bfca149ffb..f8a028330b8 100644
--- a/source/blender/blenlib/intern/polyfill_2d_beautify.c
+++ b/source/blender/blenlib/intern/polyfill_2d_beautify.c
@@ -83,8 +83,7 @@ static int oedge_cmp(const void *a1, const void *a2)
     return -1;
   }
   /* Should never get here, no two edges should be the same. */
-  BLI_assert(false);
-  return 0;
+  BLI_UNREACHABLE_ABORT;
 }
 
 BLI_INLINE bool is_boundary_edge(uint i_a, uint i_b, const uint coord_last)
diff --git a/source/blender/bmesh/tools/bmesh_bevel.c b/source/blender/bmesh/tools/bmesh_bevel.c
index 6cdf3278908..e71625de6c9 100644
--- a/source/blender/bmesh/tools/bmesh_bevel.c
+++ b/source/blender/bmesh/tools/bmesh_bevel.c
@@ -1199,8 +1199,7 @@ static bool edge_edge_angle_less_than_180(const BMEdge *e1, const BMEdge *e2, co
     v2 = e2->v1;
   }
   else {
-    BLI_assert(false);
-    return false;
+    BLI_UNREACHABLE_ABORT;
   }
   sub_v3_v3v3(dir1, v1->co, v->co);
   sub_v3_v3v3(dir2, v2->co, v->co);
diff --git a/source/blender/editors/animation/fmodifier_ui.c b/source/blender/editors/animation/fmodifier_ui.c
index 653bd72b364..4f4746fd799 100644
--- a/source/blender/editors/animation/fmodifier_ui.c
+++ b/source/blender/editors/animation/fmodifier_ui.c
@@ -83,8 +83,7 @@ static ListBase *fmodifier_list_space_specific(const bContext *C)
   }
 
   /* This should not be called in any other space. */
-  BLI_assert(false);
-  return NULL;
+  BLI_UNREACHABLE_ABORT;
 }
 
 /**
diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c
index e4527740164..134e8f9bf55 100644
--- a/source/blender/editors/object/object_add.c
+++ b/source/blender/editors/object/object_add.c
@@ -831,7 +831,7 @@ static const char *get_effector_defname(ePFieldType type)
   }
 
   BLI_assert(false);
-  return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Field");
+  BLI_UNREACHABLE_ABORT;
 }
 
 static int effector_add_exec(bContext *C, wmOperator *op)
diff --git a/source/blender/editors/sculpt_paint/sculpt_geodesic.c b/source/blender/editors/sculpt_paint/sculpt_geodesic.c
index d86d0938300..7577c4e8f30 100644
--- a/source/blender/editors/sculpt_paint/sculpt_geodesic.c
+++ b/source/blender/editors/sculpt_paint/sculpt_geodesic.c
@@ -315,8 +315,7 @@ float *SCULPT_geodesic_distances_create(Object *ob,
     case PBVH_GRIDS:
       return SCULPT_geodesic_fallback_create(ob, initial_vertices);
   }
-  BLI_assert(false);
-  return NULL;
+  BLI_UNREACHABLE_ABORT;
 }
 
 float *SCULPT_geodesic_from_vertex_and_symm(Sculpt *sd,
diff --git a/source/blender/editors/space_buttons/space_buttons.c b/source/blender/editors/space_buttons/space_buttons.c
index 43d45db38e2..6b1d64d85f4 100644
--- a/source/blender/editors/space_buttons/space_buttons.c
+++ b/source/blender/editors/space_buttons/space_buttons.c
@@ -308,8 +308,7 @@ static const char *buttons_main_region_context_string(const short mainb)
   }
 
   /* All the cases should be handled. */
-  BLI_assert(false);
-  return "";
+  BLI_UNREACHABLE_ABORT;
 }
 
 static void buttons_main_region_layout_properties(const bContext *C,
diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc
index f64ce771b25..c366818cf3c 100644
--- a/source/blender/editors/space_node/node_draw.cc
+++ b/source/blender/editors/space_node/node_draw.cc
@@ -1196,7 +1196,7 @@ static int node_error_type_to_icon(const NodeWarningType type)
   }
 
   BLI_assert(false);
-  return ICON_ERROR;
+  BLI_UNREACHABLE_ABORT;
 }
 
 static uint8_t node_error_type_priority(const NodeWarningType type)
@@ -1209,9 +1209,7 @@ static uint8_t node_error_type_priority(const NodeWarningType type)
     case NodeWarningType::Info:
       return 1;
   }
-
-  BLI_assert(false);
-  return 0;
+  BLI_UNREACHABLE_ABORT;
 }
 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list