diff options
author | antego <antego@users.noreply.github.com> | 2022-04-24 10:14:29 +1000 |
---|---|---|
committer | antego <antego@users.noreply.github.com> | 2022-04-26 18:28:30 +1000 |
commit | d780b204d84433fa3bd88853985e073b02b8f3a2 (patch) | |
tree | 4046d8b3a3c0cfc3f42ff8e780b01bc0374db1af /gcc | |
parent | b74044fb6278e373da607a8f1f5df2193ce27d65 (diff) | |
download | gcc-d780b204d84433fa3bd88853985e073b02b8f3a2.zip gcc-d780b204d84433fa3bd88853985e073b02b8f3a2.tar.gz gcc-d780b204d84433fa3bd88853985e073b02b8f3a2.tar.bz2 |
Implement macro expansion in `IfExpr`, `IfExprConseqElse`, `IfExprConseqIf`, `IfExprConseqIfLet`.
Addresses #1141
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/expand/rust-attribute-visitor.cc | 12 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/macro42.rs | 31 |
2 files changed, 43 insertions, 0 deletions
diff --git a/gcc/rust/expand/rust-attribute-visitor.cc b/gcc/rust/expand/rust-attribute-visitor.cc index e420d09..842fbdf 100644 --- a/gcc/rust/expand/rust-attribute-visitor.cc +++ b/gcc/rust/expand/rust-attribute-visitor.cc @@ -1630,6 +1630,9 @@ AttrVisitor::visit (AST::IfExpr &expr) // can't strip condition expr itself, but can strip sub-expressions auto &condition_expr = expr.get_condition_expr (); condition_expr->accept_vis (*this); + auto cond_fragment = expander.take_expanded_fragment (*this); + if (cond_fragment.should_expand ()) + condition_expr = cond_fragment.take_expression_fragment (); if (condition_expr->is_marked_for_strip ()) rust_error_at (condition_expr->get_locus (), "cannot strip expression in this position - outer " @@ -1657,6 +1660,9 @@ AttrVisitor::visit (AST::IfExprConseqElse &expr) // can't strip condition expr itself, but can strip sub-expressions auto &condition_expr = expr.get_condition_expr (); condition_expr->accept_vis (*this); + auto cond_fragment = expander.take_expanded_fragment (*this); + if (cond_fragment.should_expand ()) + condition_expr = cond_fragment.take_expression_fragment (); if (condition_expr->is_marked_for_strip ()) rust_error_at (condition_expr->get_locus (), "cannot strip expression in this position - outer " @@ -1692,6 +1698,9 @@ AttrVisitor::visit (AST::IfExprConseqIf &expr) // can't strip condition expr itself, but can strip sub-expressions auto &condition_expr = expr.get_condition_expr (); condition_expr->accept_vis (*this); + auto cond_fragment = expander.take_expanded_fragment (*this); + if (cond_fragment.should_expand ()) + condition_expr = cond_fragment.take_expression_fragment (); if (condition_expr->is_marked_for_strip ()) rust_error_at (condition_expr->get_locus (), "cannot strip expression in this position - outer " @@ -1727,6 +1736,9 @@ AttrVisitor::visit (AST::IfExprConseqIfLet &expr) // can't strip condition expr itself, but can strip sub-expressions auto &condition_expr = expr.get_condition_expr (); condition_expr->accept_vis (*this); + auto cond_fragment = expander.take_expanded_fragment (*this); + if (cond_fragment.should_expand ()) + condition_expr = cond_fragment.take_expression_fragment (); if (condition_expr->is_marked_for_strip ()) rust_error_at (condition_expr->get_locus (), "cannot strip expression in this position - outer " diff --git a/gcc/testsuite/rust/compile/macro42.rs b/gcc/testsuite/rust/compile/macro42.rs new file mode 100644 index 0000000..29fa651 --- /dev/null +++ b/gcc/testsuite/rust/compile/macro42.rs @@ -0,0 +1,31 @@ +// { dg-additional-options "-w -frust-cfg=A" } +macro_rules! cfg { + () => {{}}; +} + +fn main() -> i32 { + let mut res = 0; + if cfg!(A) { + res = 1; + } + + if cfg!(A) { + res = 2; + } else { + res = 3; + } + + if cfg!(A) { + res = 4; + } else if cfg!(A) { + res = 5; + } + + let res = if cfg!(A) { + 6 + } else { + 7 + }; + + return res; +} |