aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/c-family/c-common.cc2
-rw-r--r--gcc/c-family/c-common.h2
-rw-r--r--gcc/diagnostic.cc2
-rw-r--r--gcc/opt-problem.cc2
-rw-r--r--gcc/rust/Make-lang.in13
-rw-r--r--gcc/rust/ast/rust-expr.h130
-rw-r--r--gcc/rust/backend/rust-compile-expr.cc2
-rw-r--r--gcc/rust/hir/rust-ast-lower-expr.h2
-rw-r--r--gcc/rust/hir/tree/rust-hir-expr.h102
-rw-r--r--gcc/rust/parse/rust-parse-impl.h5
-rw-r--r--gcc/rust/rust-lang.cc24
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-pattern.cc2
-rw-r--r--gcc/selftest-run-tests.cc2
-rw-r--r--gcc/selftest.h1
-rw-r--r--gcc/testsuite/rust/compile/match5.rs2
15 files changed, 64 insertions, 229 deletions
diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc
index d9674ea..d02016e 100644
--- a/gcc/c-family/c-common.cc
+++ b/gcc/c-family/c-common.cc
@@ -9111,6 +9111,8 @@ c_family_tests (void)
c_indentation_c_tests ();
c_pretty_print_c_tests ();
c_spellcheck_cc_tests ();
+ c_diagnostic_c_tests ();
+ c_opt_problem_cc_tests ();
}
} // namespace selftest
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index ee0c4de..817e1b6 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -1512,8 +1512,10 @@ extern tree braced_lists_to_strings (tree, tree);
namespace selftest {
/* Declarations for specific families of tests within c-family,
by source file, in alphabetical order. */
+ extern void c_diagnostic_c_tests (void);
extern void c_format_c_tests (void);
extern void c_indentation_c_tests (void);
+ extern void c_opt_problem_cc_tests (void);
extern void c_pretty_print_c_tests (void);
extern void c_spellcheck_cc_tests (void);
diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc
index 97e2e2c..9c2f445 100644
--- a/gcc/diagnostic.cc
+++ b/gcc/diagnostic.cc
@@ -2466,7 +2466,7 @@ test_num_digits ()
/* Run all of the selftests within this file. */
void
-diagnostic_c_tests ()
+c_diagnostic_c_tests ()
{
test_print_escaped_string ();
test_print_parseable_fixits_none ();
diff --git a/gcc/opt-problem.cc b/gcc/opt-problem.cc
index e45d14e..11fec57 100644
--- a/gcc/opt-problem.cc
+++ b/gcc/opt-problem.cc
@@ -324,7 +324,7 @@ test_opt_result_failure_at (const line_table_case &case_)
/* Run all of the selftests within this file. */
void
-opt_problem_cc_tests ()
+c_opt_problem_cc_tests ()
{
test_opt_result_success ();
for_each_line_table_case (test_opt_result_failure_at);
diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index 659c5b9..d2f7962 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -209,8 +209,16 @@ rust.uninstall:
-rm -f $(RUST_ALL_OBJS)
# ^those two are a maybe
-# No rust-specific selftests
-selftest-rust:
+# Enable selftests for the rust frontend
+selftest-rust: s-selftest-rust
+
+RUST_SELFTEST_FLAGS = -xrs $(SELFTEST_FLAGS)
+RUST_SELFTEST_DEPS = rust1$(exeext) $(SELFTEST_DEPS)
+
+# Run the rust selftests
+s-selftest-rust: $(RUST_SELFTEST_DEPS)
+ $(GCC_FOR_TARGET) $(RUST_SELFTEST_FLAGS)
+ $(STAMP) $@
# Install info documentation for the front end, if it is present in the source directory. This target
# should have dependencies on info files that should be installed.
@@ -319,4 +327,3 @@ rust/%.o: rust/typecheck/%.cc
rust/%.o: rust/lint/%.cc
$(COMPILE) $(RUST_CXXFLAGS) $(RUST_INCLUDES) $<
$(POSTCOMPILE)
-
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index a2ce1d8..3f3ed5c 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -4225,7 +4225,7 @@ private:
// inlined from MatchArmGuard
std::unique_ptr<Expr> guard_expr;
- // TODO: should this store location data?
+ Location locus;
public:
// Returns whether the MatchArm has a match arm guard expression
@@ -4233,11 +4233,11 @@ public:
// Constructor for match arm with a guard expression
MatchArm (std::vector<std::unique_ptr<Pattern> > match_arm_patterns,
- std::unique_ptr<Expr> guard_expr = nullptr,
+ Location locus, std::unique_ptr<Expr> guard_expr = nullptr,
std::vector<Attribute> outer_attrs = std::vector<Attribute> ())
: outer_attrs (std::move (outer_attrs)),
match_arm_patterns (std::move (match_arm_patterns)),
- guard_expr (std::move (guard_expr))
+ guard_expr (std::move (guard_expr)), locus (locus)
{}
// Copy constructor with clone
@@ -4250,6 +4250,8 @@ public:
match_arm_patterns.reserve (other.match_arm_patterns.size ());
for (const auto &e : other.match_arm_patterns)
match_arm_patterns.push_back (e->clone_pattern ());
+
+ locus = other.locus;
}
~MatchArm () = default;
@@ -4281,7 +4283,8 @@ public:
// Creates a match arm in an error state.
static MatchArm create_error ()
{
- return MatchArm (std::vector<std::unique_ptr<Pattern> > ());
+ Location locus = Location ();
+ return MatchArm (std::vector<std::unique_ptr<Pattern> > (), locus);
}
std::string as_string () const;
@@ -4305,36 +4308,9 @@ public:
{
return match_arm_patterns;
}
-};
-
-/*
-// Base "match case" for a match expression - abstract
-class MatchCase
-{
- MatchArm arm;
-
-protected:
- MatchCase (MatchArm arm) : arm (std::move (arm)) {}
-
- // Should not require copy constructor or assignment operator overloading
- // Clone function implementation as pure virtual method
- virtual MatchCase *clone_match_case_impl () const = 0;
-
-public:
- virtual ~MatchCase () {}
-
- // Unique pointer custom clone function
- std::unique_ptr<MatchCase> clone_match_case () const
- {
- return std::unique_ptr<MatchCase> (clone_match_case_impl ());
- }
-
- virtual std::string as_string () const;
-
- virtual void accept_vis (ASTVisitor &vis) = 0;
+ Location get_locus () const { return locus; }
};
-*/
/* A "match case" - a correlated match arm and resulting expression. Not
* abstract. */
@@ -4391,96 +4367,6 @@ public:
NodeId get_node_id () const { return node_id; }
};
-#if 0
-// Block expression match case
-class MatchCaseBlockExpr : public MatchCase
-{
- std::unique_ptr<BlockExpr> block_expr;
-
- // TODO: should this store location data?
-
-public:
- MatchCaseBlockExpr (MatchArm arm, std::unique_ptr<BlockExpr> block_expr)
- : MatchCase (std::move (arm)), block_expr (std::move (block_expr))
- {}
-
- // Copy constructor requires clone
- MatchCaseBlockExpr (MatchCaseBlockExpr const &other)
- : MatchCase (other), block_expr (other.block_expr->clone_block_expr ())
- {}
-
- // Overload assignment operator to have clone
- MatchCaseBlockExpr &operator= (MatchCaseBlockExpr const &other)
- {
- MatchCase::operator= (other);
- block_expr = other.block_expr->clone_block_expr ();
- // arm = other.arm;
-
- return *this;
- }
-
- // move constructors
- MatchCaseBlockExpr (MatchCaseBlockExpr &&other) = default;
- MatchCaseBlockExpr &operator= (MatchCaseBlockExpr &&other) = default;
-
- std::string as_string () const override;
-
- void accept_vis (ASTVisitor &vis) override;
-
-protected:
- /* Use covariance to implement clone function as returning this object rather
- * than base */
- MatchCaseBlockExpr *clone_match_case_impl () const override
- {
- return new MatchCaseBlockExpr (*this);
- }
-};
-
-// Expression (except block expression) match case
-class MatchCaseExpr : public MatchCase
-{
- std::unique_ptr<Expr> expr;
-
- // TODO: should this store location data?
-
-public:
- MatchCaseExpr (MatchArm arm, std::unique_ptr<Expr> expr)
- : MatchCase (std::move (arm)), expr (std::move (expr))
- {}
-
- // Copy constructor requires clone
- MatchCaseExpr (MatchCaseExpr const &other)
- : MatchCase (other), expr (other.expr->clone_expr ())
- {}
-
- // Overload assignment operator to have clone
- MatchCaseExpr &operator= (MatchCaseExpr const &other)
- {
- MatchCase::operator= (other);
- expr = other.expr->clone_expr ();
- // arm = other.arm;
-
- return *this;
- }
-
- // move constructors
- MatchCaseExpr (MatchCaseExpr &&other) = default;
- MatchCaseExpr &operator= (MatchCaseExpr &&other) = default;
-
- std::string as_string () const override;
-
- void accept_vis (ASTVisitor &vis) override;
-
-protected:
- /* Use covariance to implement clone function as returning this object rather
- * than base */
- MatchCaseExpr *clone_match_case_impl () const override
- {
- return new MatchCaseExpr (*this);
- }
-};
-#endif
-
// Match expression AST node
class MatchExpr : public ExprWithBlock
{
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc
index d61a568..d49a6dc 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -274,7 +274,7 @@ CompileExpr::visit (HIR::MatchExpr &expr)
rust_assert (kase_arm.get_patterns ().size () > 0);
// generate implicit label
- Location arm_locus = kase_arm.get_patterns ().at (0)->get_locus ();
+ Location arm_locus = kase_arm.get_locus ();
tree case_label = ctx->get_backend ()->label (
fndecl, "" /* empty creates an artificial label */, arm_locus);
diff --git a/gcc/rust/hir/rust-ast-lower-expr.h b/gcc/rust/hir/rust-ast-lower-expr.h
index 1386b6b..1cc3f1d 100644
--- a/gcc/rust/hir/rust-ast-lower-expr.h
+++ b/gcc/rust/hir/rust-ast-lower-expr.h
@@ -693,7 +693,7 @@ public:
match_arm_patterns.push_back (std::unique_ptr<HIR::Pattern> (ptrn));
}
- HIR::MatchArm arm (std::move (match_arm_patterns),
+ HIR::MatchArm arm (std::move (match_arm_patterns), expr.get_locus (),
std::unique_ptr<HIR::Expr> (kase_guard_expr),
match_case.get_arm ().get_outer_attrs ());
diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h
index 2203fc3..b8d3354 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.h
+++ b/gcc/rust/hir/tree/rust-hir-expr.h
@@ -3713,6 +3713,7 @@ private:
AST::AttrVec outer_attrs;
std::vector<std::unique_ptr<Pattern> > match_arm_patterns;
std::unique_ptr<Expr> guard_expr;
+ Location locus;
public:
// Returns whether the MatchArm has a match arm guard expression
@@ -3720,11 +3721,11 @@ public:
// Constructor for match arm with a guard expression
MatchArm (std::vector<std::unique_ptr<Pattern> > match_arm_patterns,
- std::unique_ptr<Expr> guard_expr = nullptr,
+ Location locus, std::unique_ptr<Expr> guard_expr = nullptr,
AST::AttrVec outer_attrs = AST::AttrVec ())
: outer_attrs (std::move (outer_attrs)),
match_arm_patterns (std::move (match_arm_patterns)),
- guard_expr (std::move (guard_expr))
+ guard_expr (std::move (guard_expr)), locus (locus)
{}
// Copy constructor with clone
@@ -3737,6 +3738,8 @@ public:
match_arm_patterns.reserve (other.match_arm_patterns.size ());
for (const auto &e : other.match_arm_patterns)
match_arm_patterns.push_back (e->clone_pattern ());
+
+ locus = other.locus;
}
~MatchArm () = default;
@@ -3766,7 +3769,8 @@ public:
// Creates a match arm in an error state.
static MatchArm create_error ()
{
- return MatchArm (std::vector<std::unique_ptr<Pattern> > ());
+ Location locus = Location ();
+ return MatchArm (std::vector<std::unique_ptr<Pattern> > (), locus);
}
std::string as_string () const;
@@ -3775,6 +3779,8 @@ public:
{
return match_arm_patterns;
}
+
+ Location get_locus () const { return locus; }
};
/* A "match case" - a correlated match arm and resulting expression. Not
@@ -3819,96 +3825,6 @@ public:
std::unique_ptr<Expr> &get_expr () { return expr; }
};
-#if 0
-// Block expression match case
-class MatchCaseBlockExpr : public MatchCase
-{
- std::unique_ptr<BlockExpr> block_expr;
-
- // TODO: should this store location data?
-
-public:
- MatchCaseBlockExpr (MatchArm arm, std::unique_ptr<BlockExpr> block_expr)
- : MatchCase (std::move (arm)), block_expr (std::move (block_expr))
- {}
-
- // Copy constructor requires clone
- MatchCaseBlockExpr (MatchCaseBlockExpr const &other)
- : MatchCase (other), block_expr (other.block_expr->clone_block_expr ())
- {}
-
- // Overload assignment operator to have clone
- MatchCaseBlockExpr &operator= (MatchCaseBlockExpr const &other)
- {
- MatchCase::operator= (other);
- block_expr = other.block_expr->clone_block_expr ();
- // arm = other.arm;
-
- return *this;
- }
-
- // move constructors
- MatchCaseBlockExpr (MatchCaseBlockExpr &&other) = default;
- MatchCaseBlockExpr &operator= (MatchCaseBlockExpr &&other) = default;
-
- std::string as_string () const override;
-
- void accept_vis (HIRFullVisitor &vis) override;
-
-protected:
- /* Use covariance to implement clone function as returning this object rather
- * than base */
- MatchCaseBlockExpr *clone_match_case_impl () const override
- {
- return new MatchCaseBlockExpr (*this);
- }
-};
-
-// Expression (except block expression) match case
-class MatchCaseExpr : public MatchCase
-{
- std::unique_ptr<Expr> expr;
-
- // TODO: should this store location data?
-
-public:
- MatchCaseExpr (MatchArm arm, std::unique_ptr<Expr> expr)
- : MatchCase (std::move (arm)), expr (std::move (expr))
- {}
-
- // Copy constructor requires clone
- MatchCaseExpr (MatchCaseExpr const &other)
- : MatchCase (other), expr (other.expr->clone_expr ())
- {}
-
- // Overload assignment operator to have clone
- MatchCaseExpr &operator= (MatchCaseExpr const &other)
- {
- MatchCase::operator= (other);
- expr = other.expr->clone_expr ();
- // arm = other.arm;
-
- return *this;
- }
-
- // move constructors
- MatchCaseExpr (MatchCaseExpr &&other) = default;
- MatchCaseExpr &operator= (MatchCaseExpr &&other) = default;
-
- std::string as_string () const override;
-
- void accept_vis (HIRFullVisitor &vis) override;
-
-protected:
- /* Use covariance to implement clone function as returning this object rather
- * than base */
- MatchCaseExpr *clone_match_case_impl () const override
- {
- return new MatchCaseExpr (*this);
- }
-};
-#endif
-
// Match expression HIR node
class MatchExpr : public ExprWithBlock
{
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 0e39e48..6d393b0 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -8560,8 +8560,9 @@ Parser<ManagedTokenSource>::parse_match_arm ()
// DEBUG
rust_debug ("successfully parsed match arm");
- return AST::MatchArm (std::move (match_arm_patterns), std::move (guard_expr),
- std::move (outer_attrs));
+ return AST::MatchArm (std::move (match_arm_patterns),
+ lexer.peek_token ()->get_locus (),
+ std::move (guard_expr), std::move (outer_attrs));
}
/* Parses the patterns used in a match arm. End token id is the id of the token
diff --git a/gcc/rust/rust-lang.cc b/gcc/rust/rust-lang.cc
index a0f14d4..fbab9b1 100644
--- a/gcc/rust/rust-lang.cc
+++ b/gcc/rust/rust-lang.cc
@@ -32,6 +32,7 @@
#include "convert.h"
#include "langhooks.h"
#include "langhooks-def.h"
+#include "selftest.h"
#include <mpfr.h>
// note: header files must be in this order or else forward declarations don't
@@ -434,6 +435,29 @@ rust_localize_identifier (const char *ident)
#define LANG_HOOKS_GIMPLIFY_EXPR grs_langhook_gimplify_expr
#define LANG_HOOKS_EH_PERSONALITY grs_langhook_eh_personality
+#if CHECKING_P
+
+#undef LANG_HOOKS_RUN_LANG_SELFTESTS
+#define LANG_HOOKS_RUN_LANG_SELFTESTS selftest::run_rust_tests
+
+namespace selftest {
+
+static void
+simple_assert ()
+{
+ ASSERT_TRUE (true);
+}
+
+void
+run_rust_tests ()
+{
+ // Call tests for the rust frontend here
+ simple_assert ();
+}
+} // namespace selftest
+
+#endif /* !CHECKING_P */
+
// Expands all LANG_HOOKS_x of GCC
struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
diff --git a/gcc/rust/typecheck/rust-hir-type-check-pattern.cc b/gcc/rust/typecheck/rust-hir-type-check-pattern.cc
index 524ef46..e4ec49b 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-pattern.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-pattern.cc
@@ -58,7 +58,7 @@ TypeCheckPattern::visit (HIR::TupleStructPattern &pattern)
rust_error_at (
pattern.get_locus (),
- "expected tuple struct or tuple variant, found %s variant %s::%s",
+ "expected tuple struct or tuple variant, found %s variant %<%s::%s%>",
variant_type.c_str (), adt->get_name ().c_str (),
variant->get_identifier ().c_str ());
return;
diff --git a/gcc/selftest-run-tests.cc b/gcc/selftest-run-tests.cc
index 4123e54..0c5bf4c 100644
--- a/gcc/selftest-run-tests.cc
+++ b/gcc/selftest-run-tests.cc
@@ -76,7 +76,6 @@ selftest::run_tests ()
json_cc_tests ();
cgraph_c_tests ();
optinfo_emit_json_cc_tests ();
- opt_problem_cc_tests ();
ordered_hash_map_tests_cc_tests ();
splay_tree_cc_tests ();
@@ -95,7 +94,6 @@ selftest::run_tests ()
/* Higher-level tests, or for components that other selftests don't
rely on. */
diagnostic_show_locus_c_tests ();
- diagnostic_c_tests ();
diagnostic_format_json_cc_tests ();
edit_context_c_tests ();
fold_const_c_tests ();
diff --git a/gcc/selftest.h b/gcc/selftest.h
index 386c0d9..6d62461 100644
--- a/gcc/selftest.h
+++ b/gcc/selftest.h
@@ -238,7 +238,6 @@ extern void hash_map_tests_c_tests ();
extern void hash_set_tests_c_tests ();
extern void input_c_tests ();
extern void json_cc_tests ();
-extern void opt_problem_cc_tests ();
extern void optinfo_emit_json_cc_tests ();
extern void opts_c_tests ();
extern void ordered_hash_map_tests_cc_tests ();
diff --git a/gcc/testsuite/rust/compile/match5.rs b/gcc/testsuite/rust/compile/match5.rs
index 6f3d6e4..a5f934d 100644
--- a/gcc/testsuite/rust/compile/match5.rs
+++ b/gcc/testsuite/rust/compile/match5.rs
@@ -10,6 +10,6 @@ fn inspect(f: Foo) {
Foo::A => {}
Foo::B => {}
Foo::C(a) => {}
- Foo::D(x, y) => {} // { dg-error "expected tuple struct or tuple variant, found struct variant Foo::D" }
+ Foo::D(x, y) => {} // { dg-error "expected tuple struct or tuple variant, found struct variant 'Foo::D'" }
}
}