compiler: call error_statement for fallthrough in last case
authorIan Lance Taylor <ian@gcc.gnu.org>
Fri, 15 Sep 2017 21:25:17 +0000 (21:25 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Fri, 15 Sep 2017 21:25:17 +0000 (21:25 +0000)
    It is possible to do this check in backend, by walking the
    block and check whether the last statement is a goto. But it
    seems easier to do it in the frontend, where it can simply use
    is_fallthrough.

    Reviewed-on: https://go-review.googlesource.com/63690

From-SVN: r252851

gcc/go/gofrontend/MERGE
gcc/go/gofrontend/statements.cc

index a63d921ab577d2a24f21f0db62874eed0b8dd5cc..aafc5269095e60cfc62a7e3764507f341154ab68 100644 (file)
@@ -1,4 +1,4 @@
-de7b370901c4fc6852eaa7372282bb699429ec4a
+70cf67704699c8bcaf6f52437812367cdc4ad169
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
index eb370f844812c7fce41faf253286a8617f77318b..bea57cd6836b7ac67389f71cabf45378267d9eb5 100644 (file)
@@ -3707,6 +3707,12 @@ Case_clauses::get_backend(Translate_context* context,
       std::vector<Bexpression*> cases;
       Bstatement* stat = p->get_backend(context, break_label, &case_constants,
                                        &cases);
+      // The final clause can't fall through.
+      if (i == c - 1 && p->is_fallthrough())
+        {
+          go_assert(saw_errors());
+          stat = context->backend()->error_statement();
+        }
       (*all_cases)[i].swap(cases);
       (*all_statements)[i] = stat;
     }