public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Implement macro expansion in `IfExpr`, `IfExprConseqElse`, `IfExprConseqIf`, `IfExprConseqIfLet`.
@ 2022-06-08 12:37 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:37 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:d780b204d84433fa3bd88853985e073b02b8f3a2
commit d780b204d84433fa3bd88853985e073b02b8f3a2
Author: antego <antego@users.noreply.github.com>
Date: Sun Apr 24 10:14:29 2022 +1000
Implement macro expansion in `IfExpr`, `IfExprConseqElse`, `IfExprConseqIf`, `IfExprConseqIfLet`.
Addresses #1141
Diff:
---
gcc/rust/expand/rust-attribute-visitor.cc | 12 ++++++++++++
gcc/testsuite/rust/compile/macro42.rs | 31 +++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+)
diff --git a/gcc/rust/expand/rust-attribute-visitor.cc b/gcc/rust/expand/rust-attribute-visitor.cc
index e420d0932a5..842fbdf680a 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 00000000000..29fa651fcd2
--- /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;
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-06-08 12:37 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 12:37 [gcc/devel/rust/master] Implement macro expansion in `IfExpr`, `IfExprConseqElse`, `IfExprConseqIf`, `IfExprConseqIfLet` Thomas Schwinge
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).