From a9ba21889ab928d76b6c9b7867dc2df08d608ed5 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Tue, 23 Jul 2019 18:19:40 +0300 Subject: [PATCH] C: generate unreachable hint after throw statement to avoid compiler warnings --- .../backend/c/generate/CodeGenerationVisitor.java | 4 ++++ core/src/main/resources/org/teavm/backend/c/runtime.h | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/core/src/main/java/org/teavm/backend/c/generate/CodeGenerationVisitor.java b/core/src/main/java/org/teavm/backend/c/generate/CodeGenerationVisitor.java index 8b76c9c8c..34fd40db9 100644 --- a/core/src/main/java/org/teavm/backend/c/generate/CodeGenerationVisitor.java +++ b/core/src/main/java/org/teavm/backend/c/generate/CodeGenerationVisitor.java @@ -1217,6 +1217,10 @@ public class CodeGenerationVisitor implements ExprVisitor, StatementVisitor { } writer.println(";"); + if (context.isLongjmp()) { + writer.println("TEAVM_UNREACHABLE"); + } + popLocation(statement.getLocation()); } diff --git a/core/src/main/resources/org/teavm/backend/c/runtime.h b/core/src/main/resources/org/teavm/backend/c/runtime.h index 2bbc0b3d7..0deac2877 100644 --- a/core/src/main/resources/org/teavm/backend/c/runtime.h +++ b/core/src/main/resources/org/teavm/backend/c/runtime.h @@ -418,6 +418,17 @@ inline static void* teavm_nullCheck(void* o) { } return o; } + +#ifdef __GNUC__ + #define TEAVM_UNREACHABLE __builtin_unreachable(); +#endif +#ifdef _MSC_VER + #define TEAVM_UNREACHABLE __assume(0); +#endif +#ifndef TEAVM_UNREACHABLE + #define TEAVM_UNREACHABLE return; +#endif + #else #define TEAVM_JUMP_SUPPORTED 0 #define TEAVM_JUMP_TO_FRAME(frame, id)