aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-03-25 11:46:24 +0000
committerGitHub <noreply@github.com>2022-03-25 11:46:24 +0000
commit5a15694ee22500458a17f064b42fc7b8051984db (patch)
tree66c80ed740780967291dd45cc94709c33f643ddf /gcc
parenta7e723469220b6765463d27b3e19ffd27f1baadd (diff)
parent7fa6e72b1a1a18a8b511a796514bc32591b26e2f (diff)
downloadgcc-5a15694ee22500458a17f064b42fc7b8051984db.zip
gcc-5a15694ee22500458a17f064b42fc7b8051984db.tar.gz
gcc-5a15694ee22500458a17f064b42fc7b8051984db.tar.bz2
Merge #1063
1063: Handle :meta fragments properly r=CohenArthur a=CohenArthur This expands :meta fragments properly and allows us to strip assignment expressions Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/ast/rust-expr.h5
-rw-r--r--gcc/rust/expand/rust-attribute-visitor.cc8
-rw-r--r--gcc/rust/expand/rust-attribute-visitor.h8
-rw-r--r--gcc/rust/expand/rust-macro-expand.cc6
-rw-r--r--gcc/rust/parse/rust-parse-impl.h17
-rw-r--r--gcc/rust/parse/rust-parse.h2
-rw-r--r--gcc/testsuite/rust/execute/torture/cfg5.rs13
-rw-r--r--gcc/testsuite/rust/execute/torture/macros27.rs24
8 files changed, 63 insertions, 20 deletions
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index 7336db2..1966a59 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -704,8 +704,9 @@ public:
// Call OperatorExpr constructor to initialise left_expr
AssignmentExpr (std::unique_ptr<Expr> value_to_assign_to,
- std::unique_ptr<Expr> value_to_assign, Location locus)
- : OperatorExpr (std::move (value_to_assign_to), std::vector<Attribute> (),
+ std::unique_ptr<Expr> value_to_assign,
+ std::vector<Attribute> outer_attribs, Location locus)
+ : OperatorExpr (std::move (value_to_assign_to), std::move (outer_attribs),
locus),
right_expr (std::move (value_to_assign))
{}
diff --git a/gcc/rust/expand/rust-attribute-visitor.cc b/gcc/rust/expand/rust-attribute-visitor.cc
index 3de6608..8f2a6c7 100644
--- a/gcc/rust/expand/rust-attribute-visitor.cc
+++ b/gcc/rust/expand/rust-attribute-visitor.cc
@@ -628,8 +628,12 @@ AttrVisitor::visit (AST::TypeCastExpr &expr)
void
AttrVisitor::visit (AST::AssignmentExpr &expr)
{
- /* outer attributes never allowed before these. while cannot strip
- * two direct descendant expressions, can strip ones below that */
+ expander.expand_cfg_attrs (expr.get_outer_attrs ());
+ if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ {
+ expr.mark_for_strip ();
+ return;
+ }
/* should have no possibility for outer attrs as would be parsed
* with outer expr */
diff --git a/gcc/rust/expand/rust-attribute-visitor.h b/gcc/rust/expand/rust-attribute-visitor.h
index 6da6583..1c6410d 100644
--- a/gcc/rust/expand/rust-attribute-visitor.h
+++ b/gcc/rust/expand/rust-attribute-visitor.h
@@ -71,8 +71,12 @@ public:
it = values.erase (it);
for (auto &node : fragment.get_nodes ())
{
- it = values.insert (it, extractor (node));
- it++;
+ auto new_node = extractor (node);
+ if (new_node != nullptr && !new_node->is_marked_for_strip ())
+ {
+ it = values.insert (it, std::move (new_node));
+ it++;
+ }
}
}
else if (value->is_marked_for_strip ())
diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc
index 6227344..2620fea 100644
--- a/gcc/rust/expand/rust-macro-expand.cc
+++ b/gcc/rust/expand/rust-macro-expand.cc
@@ -490,11 +490,7 @@ MacroExpander::match_fragment (Parser<MacroInvocLexer> &parser,
// is meta attributes?
case AST::MacroFragSpec::META:
- // parser.parse_inner_attribute ?
- // parser.parse_outer_attribute ?
- // parser.parse_attribute_body ?
- // parser.parse_doc_comment ?
- gcc_unreachable ();
+ parser.parse_attribute_body ();
break;
case AST::MacroFragSpec::TT:
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index bcf4eca..48c39de 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -11719,7 +11719,7 @@ Parser<ManagedTokenSource>::parse_stmt_or_expr_without_block ()
{
// should be expr without block
std::unique_ptr<AST::ExprWithoutBlock> expr
- = parse_expr_without_block ();
+ = parse_expr_without_block (std::move (outer_attrs));
if (lexer.peek_token ()->get_id () == SEMICOLON)
{
@@ -11764,7 +11764,7 @@ Parser<ManagedTokenSource>::parse_stmt_or_expr_without_block ()
// FIXME: old code was good until composability was required
// return parse_path_based_stmt_or_expr(std::move(outer_attrs));
std::unique_ptr<AST::ExprWithoutBlock> expr
- = parse_expr_without_block ();
+ = parse_expr_without_block (std::move (outer_attrs));
if (lexer.peek_token ()->get_id () == SEMICOLON)
{
@@ -11787,7 +11787,7 @@ Parser<ManagedTokenSource>::parse_stmt_or_expr_without_block ()
* expression then make it statement if semi afterwards */
std::unique_ptr<AST::ExprWithoutBlock> expr
- = parse_expr_without_block ();
+ = parse_expr_without_block (std::move (outer_attrs));
if (lexer.peek_token ()->get_id () == SEMICOLON)
{
@@ -12462,7 +12462,7 @@ Parser<ManagedTokenSource>::parse_expr (int right_binding_power,
// parse null denotation (unary part of expression)
std::unique_ptr<AST::Expr> expr
- = null_denotation (current_token, std::move (outer_attrs), restrictions);
+ = null_denotation (current_token, {}, restrictions);
if (expr == nullptr)
{
@@ -12477,8 +12477,8 @@ Parser<ManagedTokenSource>::parse_expr (int right_binding_power,
current_token = lexer.peek_token ();
lexer.skip_token ();
- expr = left_denotation (current_token, std::move (expr), AST::AttrVec (),
- restrictions);
+ expr = left_denotation (current_token, std::move (expr),
+ std::move (outer_attrs), restrictions);
if (expr == nullptr)
{
@@ -13811,7 +13811,7 @@ template <typename ManagedTokenSource>
std::unique_ptr<AST::AssignmentExpr>
Parser<ManagedTokenSource>::parse_assig_expr (
const_TokenPtr tok ATTRIBUTE_UNUSED, std::unique_ptr<AST::Expr> left,
- AST::AttrVec outer_attrs ATTRIBUTE_UNUSED, ParseRestrictions restrictions)
+ AST::AttrVec outer_attrs, ParseRestrictions restrictions)
{
// parse RHS (as tok has already been consumed in parse_expression)
std::unique_ptr<AST::Expr> right
@@ -13824,7 +13824,8 @@ Parser<ManagedTokenSource>::parse_assig_expr (
Location locus = left->get_locus ();
return std::unique_ptr<AST::AssignmentExpr> (
- new AST::AssignmentExpr (std::move (left), std::move (right), locus));
+ new AST::AssignmentExpr (std::move (left), std::move (right),
+ std::move (outer_attrs), locus));
}
/* Returns the left binding power for the given CompoundAssignmentExpr type.
diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h
index 5653293..945bce7 100644
--- a/gcc/rust/parse/rust-parse.h
+++ b/gcc/rust/parse/rust-parse.h
@@ -143,6 +143,7 @@ public:
AST::Visibility parse_visibility ();
std::unique_ptr<AST::IdentifierPattern> parse_identifier_pattern ();
std::unique_ptr<AST::TokenTree> parse_token_tree ();
+ AST::Attribute parse_attribute_body ();
private:
void skip_after_semicolon ();
@@ -162,7 +163,6 @@ private:
AST::Attribute parse_inner_attribute ();
AST::AttrVec parse_outer_attributes ();
AST::Attribute parse_outer_attribute ();
- AST::Attribute parse_attribute_body ();
std::unique_ptr<AST::AttrInput> parse_attr_input ();
AST::Attribute parse_doc_comment ();
diff --git a/gcc/testsuite/rust/execute/torture/cfg5.rs b/gcc/testsuite/rust/execute/torture/cfg5.rs
new file mode 100644
index 0000000..581a29b
--- /dev/null
+++ b/gcc/testsuite/rust/execute/torture/cfg5.rs
@@ -0,0 +1,13 @@
+// { dg-additional-options "-w -frust-cfg=A" }
+
+fn main() -> i32 {
+ let mut a = 0;
+
+ #[cfg(A)]
+ a = 3;
+
+ #[cfg(B)]
+ a = 40;
+
+ a - 3
+}
diff --git a/gcc/testsuite/rust/execute/torture/macros27.rs b/gcc/testsuite/rust/execute/torture/macros27.rs
new file mode 100644
index 0000000..d515bb2
--- /dev/null
+++ b/gcc/testsuite/rust/execute/torture/macros27.rs
@@ -0,0 +1,24 @@
+// { dg-additional-options "-frust-cfg=A" }
+
+macro_rules! attr {
+ (#[$attr:meta] $s:stmt) => {
+ #[$attr]
+ $s;
+ };
+}
+
+fn main() -> i32 {
+ let mut a = 0;
+
+ attr! {
+ #[cfg(A)]
+ a = 3
+ };
+
+ attr! {
+ #[cfg(B)]
+ a = 40
+ };
+
+ a - 3
+}