Add YS_FALLTHROUGH macro to mark case fall-through
authorXiretza <xiretza@xiretza.xyz>
Mon, 4 May 2020 19:12:30 +0000 (21:12 +0200)
committerXiretza <xiretza@xiretza.xyz>
Thu, 7 May 2020 11:39:34 +0000 (13:39 +0200)
C++17 introduced [[fallthrough]], GCC and clang had their own vendored
attributes before that. MSVC doesn't seem to have such a warning at all.

backends/cxxrtl/cxxrtl.cc
backends/firrtl/firrtl.cc
frontends/ast/genrtlil.cc
frontends/ast/simplify.cc
kernel/yosys.h

index e7711962f20dc1c835eb9e6d2791c1d4c9a18eb6..133f5666337a8472c4c2070c7bcccb3894185187 100644 (file)
@@ -2346,16 +2346,22 @@ struct CxxrtlBackend : public Backend {
                        case 6:
                                worker.max_opt_level = true;
                                worker.run_proc_flatten = true;
+                               YS_FALLTHROUGH
                        case 5:
                                worker.run_opt_clean_purge = true;
+                               YS_FALLTHROUGH
                        case 4:
                                worker.localize_public = true;
+                               YS_FALLTHROUGH
                        case 3:
                                worker.elide_public = true;
+                               YS_FALLTHROUGH
                        case 2:
                                worker.localize_internal = true;
+                               YS_FALLTHROUGH
                        case 1:
                                worker.elide_internal = true;
+                               YS_FALLTHROUGH
                        case 0:
                                break;
                        default:
index 40d05a03654639f66f7c43fe192ab40b93e5e661..f6dae1d8cf84bb332a5653131a60e5a127b34b47 100644 (file)
@@ -343,7 +343,7 @@ struct FirrtlWorker
                                switch (dir) {
                                        case FD_INOUT:
                                                log_warning("Instance port connection %s.%s is INOUT; treating as OUT\n", cell_type.c_str(), log_signal(it->second));
-                                               /* FALLTHRU */
+                                               YS_FALLTHROUGH
                                        case FD_OUT:
                                                sourceExpr = firstName;
                                                sinkExpr = secondExpr;
@@ -351,7 +351,7 @@ struct FirrtlWorker
                                                break;
                                        case FD_NODIRECTION:
                                                log_warning("Instance port connection %s.%s is NODIRECTION; treating as IN\n", cell_type.c_str(), log_signal(it->second));
-                                               /* FALLTHRU */
+                                               YS_FALLTHROUGH
                                        case FD_IN:
                                                sourceExpr = secondExpr;
                                                sinkExpr = firstName;
index 99676271502d5d89a07674a740cae83e5ae7b672..b5cdf270fb5838f5c94b7083873217fed87e3f9e 100644 (file)
@@ -923,7 +923,7 @@ void AstNode::detectSignWidthWorker(int &width_hint, bool &sign_hint, bool *foun
                        }
                        break;
                }
-               /* fall through */
+               YS_FALLTHROUGH
 
        // everything should have been handled above -> print error if not.
        default:
@@ -1019,7 +1019,7 @@ RTLIL::SigSpec AstNode::genRTLIL(int width_hint, bool sign_hint)
                if (GetSize(children) >= 1 && children[0]->type == AST_CONSTANT) {
                        current_module->parameter_default_values[str] = children[0]->asParaConst();
                }
-               /* fall through */
+               YS_FALLTHROUGH
        case AST_LOCALPARAM:
                if (flag_pwires)
                {
@@ -1807,7 +1807,8 @@ RTLIL::SigSpec AstNode::genRTLIL(int width_hint, bool sign_hint)
                                is_signed = sign_hint;
                                return SigSpec(wire);
                        }
-               } /* fall through */
+               }
+               YS_FALLTHROUGH
 
        // everything should have been handled above -> print error if not.
        default:
index 252219094db7895ca11a967dc64685cc69eee13b..892e845545eaf6f3da570bece9a5678f57ba0d80 100644 (file)
@@ -91,7 +91,7 @@ std::string AstNode::process_format_str(const std::string &sformat, int next_arg
                                case 'D':
                                        if (got_len)
                                                goto unsupported_format;
-                                       /* fall through */
+                                       YS_FALLTHROUGH
                                case 'x':
                                case 'X':
                                        if (next_arg >= GetSize(children))
index af1e376b12ceae3d334f3268010bc0fd5c6310cf..62f76a63fe6c6f24f853ec6d42b0ce052a2a6497 100644 (file)
@@ -155,6 +155,16 @@ extern Tcl_Obj *Tcl_ObjSetVar2(Tcl_Interp *interp, Tcl_Obj *part1Ptr, Tcl_Obj *p
 #  define YS_NORETURN
 #endif
 
+#if __cplusplus >= 201703L
+#  define YS_FALLTHROUGH [[fallthrough]];
+#elif defined(__GNUC__)
+#  define YS_FALLTHROUGH [[gnu::fallthrough]];
+#elif defined(__clang__)
+#  define YS_FALLTHROUGH [[clang::fallthrough]];
+#else
+#  define YS_FALLTHROUGH
+#endif
+
 YOSYS_NAMESPACE_BEGIN
 
 // Note: All headers included in hashlib.h must be included