From ab658f56a56ea548b1f293a4a3ada68feb11b417 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 7 Jun 2019 13:40:26 +0000 Subject: compiler: do simple deadcode elimination Normally the backend will do deadcode elimination and this is sufficient. However, the escape analysis operates on the AST that may have deadcode, and may cause things to escape that otherwise do not. This CL adds a simple deadcode elimination, run before the escape analysis. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/181080 From-SVN: r272043 --- gcc/go/gofrontend/expressions.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'gcc/go/gofrontend/expressions.h') diff --git a/gcc/go/gofrontend/expressions.h b/gcc/go/gofrontend/expressions.h index 09c71ad..6ba7fe1 100644 --- a/gcc/go/gofrontend/expressions.h +++ b/gcc/go/gofrontend/expressions.h @@ -581,6 +581,12 @@ class Expression string_constant_value(std::string* val) const { return this->do_string_constant_value(val); } + // If this is not a constant expression with boolean type, return + // false. If it is one, return true, and set VAL to the value. + bool + boolean_constant_value(bool* val) const + { return this->do_boolean_constant_value(val); } + // This is called if the value of this expression is being // discarded. This issues warnings about computed values being // unused. This returns true if all is well, false if it issued an @@ -1125,6 +1131,12 @@ class Expression do_string_constant_value(std::string*) const { return false; } + // Return whether this is a constant expression of boolean type, and + // set VAL to the value. + virtual bool + do_boolean_constant_value(bool*) const + { return false; } + // Called by the parser if the value is being discarded. virtual bool do_discarding_value(); @@ -1771,6 +1783,9 @@ class Type_conversion_expression : public Expression bool do_string_constant_value(std::string*) const; + bool + do_boolean_constant_value(bool*) const; + Type* do_type() { return this->type_; } @@ -1965,6 +1980,9 @@ class Unary_expression : public Expression bool do_numeric_constant_value(Numeric_constant*) const; + bool + do_boolean_constant_value(bool*) const; + Type* do_type(); @@ -2120,6 +2138,9 @@ class Binary_expression : public Expression do_numeric_constant_value(Numeric_constant*) const; bool + do_boolean_constant_value(bool*) const; + + bool do_discarding_value(); Type* -- cgit v1.1