diff options
author | Ian Lance Taylor <iant@golang.org> | 2017-12-02 00:38:54 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2017-12-02 00:38:54 +0000 |
commit | 9638589faff5b5ec33afba0b5a4560a3f0b5aaa6 (patch) | |
tree | 8d0aee02a39a2db4df11c4755923b7677cdae58a /gcc/go/go-gcc.cc | |
parent | d7d5f241f08bfbe5c888b24b380220851816387e (diff) | |
download | gcc-9638589faff5b5ec33afba0b5a4560a3f0b5aaa6.zip gcc-9638589faff5b5ec33afba0b5a4560a3f0b5aaa6.tar.gz gcc-9638589faff5b5ec33afba0b5a4560a3f0b5aaa6.tar.bz2 |
compiler: avoid GCC middle-end control warnings
GCC has started emitting "control reaches end of non-void function"
warnings. Avoid them for Go by 1) marking the builtin function panic
and the compiler-generated function __go_runtime_error as not
returning and 2) adding a default case to the switch used for select
statements that simply calls __builtin_unreachable.
Fixes golang/go#22767
Reviewed-on: https://go-review.googlesource.com/80416
* go-gcc.cc (Gcc_backend::Gcc_backend): Define
__builtin_unreachable.
(Gcc_backend::function): Add does_not_return parameter.
From-SVN: r255346
Diffstat (limited to 'gcc/go/go-gcc.cc')
-rw-r--r-- | gcc/go/go-gcc.cc | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/gcc/go/go-gcc.cc b/gcc/go/go-gcc.cc index 1b0190d..730e2da 100644 --- a/gcc/go/go-gcc.cc +++ b/gcc/go/go-gcc.cc @@ -486,7 +486,8 @@ class Gcc_backend : public Backend Bfunction* function(Btype* fntype, const std::string& name, const std::string& asm_name, bool is_visible, bool is_declaration, bool is_inlinable, - bool disable_split_stack, bool in_unique_section, Location); + bool disable_split_stack, bool does_not_return, + bool in_unique_section, Location); Bstatement* function_defer_statement(Bfunction* function, Bexpression* undefer, @@ -760,6 +761,12 @@ Gcc_backend::Gcc_backend() const_ptr_type_node, NULL_TREE), false, false); + + // The compiler uses __builtin_unreachable for cases that can not + // occur. + this->define_builtin(BUILT_IN_UNREACHABLE, "__builtin_unreachable", NULL, + build_function_type(void_type_node, void_list_node), + true, true); } // Get an unnamed integer type. @@ -3012,8 +3019,8 @@ Bfunction* Gcc_backend::function(Btype* fntype, const std::string& name, const std::string& asm_name, bool is_visible, bool is_declaration, bool is_inlinable, - bool disable_split_stack, bool in_unique_section, - Location location) + bool disable_split_stack, bool does_not_return, + bool in_unique_section, Location location) { tree functype = fntype->get_tree(); if (functype != error_mark_node) @@ -3049,6 +3056,8 @@ Gcc_backend::function(Btype* fntype, const std::string& name, tree attr = get_identifier ("no_split_stack"); DECL_ATTRIBUTES(decl) = tree_cons(attr, NULL_TREE, NULL_TREE); } + if (does_not_return) + TREE_THIS_VOLATILE(decl) = 1; if (in_unique_section) resolve_unique_section(decl, 0, 1); |