public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Following up on #1141. Implementing macro expansion or ComparisonExpr, LazyBooleanExpr, AssignmentEx
@ 2022-06-08 12:36 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:36 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:e26b95f64a0f450199b3a5f58db68dfd0fb585b5

commit e26b95f64a0f450199b3a5f58db68dfd0fb585b5
Author: antego <antego@users.noreply.github.com>
Date:   Wed Apr 13 20:00:54 2022 +1000

    Following up on #1141. Implementing macro expansion or ComparisonExpr, LazyBooleanExpr, AssignmentExpr.

Diff:
---
 gcc/rust/expand/rust-attribute-visitor.cc      | 39 ++++++++++++++++++++++----
 gcc/testsuite/rust/execute/torture/macros29.rs | 21 ++++++++++++++
 gcc/testsuite/rust/execute/torture/macros30.rs | 22 +++++++++++++++
 gcc/testsuite/rust/execute/torture/macros31.rs | 27 ++++++++++++++++++
 4 files changed, 103 insertions(+), 6 deletions(-)

diff --git a/gcc/rust/expand/rust-attribute-visitor.cc b/gcc/rust/expand/rust-attribute-visitor.cc
index 859ae7e9708..e420d0932a5 100644
--- a/gcc/rust/expand/rust-attribute-visitor.cc
+++ b/gcc/rust/expand/rust-attribute-visitor.cc
@@ -643,10 +643,19 @@ AttrVisitor::visit (AST::ComparisonExpr &expr)
 
   /* should have no possibility for outer attrs as would be parsed
    * with outer expr */
-  expr.get_left_expr ()->accept_vis (*this);
+  auto &l_expr = expr.get_left_expr ();
+  l_expr->accept_vis (*this);
+  auto l_fragment = expander.take_expanded_fragment (*this);
+  if (l_fragment.should_expand ())
+    l_expr = l_fragment.take_expression_fragment ();
+
   /* should syntactically not have outer attributes, though this may
    * not have worked in practice */
-  expr.get_right_expr ()->accept_vis (*this);
+  auto &r_expr = expr.get_right_expr ();
+  r_expr->accept_vis (*this);
+  auto r_fragment = expander.take_expanded_fragment (*this);
+  if (r_fragment.should_expand ())
+    r_expr = r_fragment.take_expression_fragment ();
 
   // ensure that they are not marked for strip
   if (expr.get_left_expr ()->is_marked_for_strip ())
@@ -667,10 +676,19 @@ AttrVisitor::visit (AST::LazyBooleanExpr &expr)
 
   /* should have no possibility for outer attrs as would be parsed
    * with outer expr */
-  expr.get_left_expr ()->accept_vis (*this);
+  auto &l_expr = expr.get_left_expr ();
+  l_expr->accept_vis (*this);
+  auto l_fragment = expander.take_expanded_fragment (*this);
+  if (l_fragment.should_expand ())
+    l_expr = l_fragment.take_expression_fragment ();
+
   /* should syntactically not have outer attributes, though this may
    * not have worked in practice */
-  expr.get_right_expr ()->accept_vis (*this);
+  auto &r_expr = expr.get_right_expr ();
+  r_expr->accept_vis (*this);
+  auto r_fragment = expander.take_expanded_fragment (*this);
+  if (r_fragment.should_expand ())
+    r_expr = r_fragment.take_expression_fragment ();
 
   // ensure that they are not marked for strip
   if (expr.get_left_expr ()->is_marked_for_strip ())
@@ -718,10 +736,19 @@ AttrVisitor::visit (AST::AssignmentExpr &expr)
 
   /* should have no possibility for outer attrs as would be parsed
    * with outer expr */
-  expr.get_left_expr ()->accept_vis (*this);
+  auto &l_expr = expr.get_left_expr ();
+  l_expr->accept_vis (*this);
+  auto l_fragment = expander.take_expanded_fragment (*this);
+  if (l_fragment.should_expand ())
+    l_expr = l_fragment.take_expression_fragment ();
+
   /* should syntactically not have outer attributes, though this may
    * not have worked in practice */
-  expr.get_right_expr ()->accept_vis (*this);
+  auto &r_expr = expr.get_right_expr ();
+  r_expr->accept_vis (*this);
+  auto r_fragment = expander.take_expanded_fragment (*this);
+  if (r_fragment.should_expand ())
+    r_expr = r_fragment.take_expression_fragment ();
 
   // ensure that they are not marked for strip
   if (expr.get_left_expr ()->is_marked_for_strip ())
diff --git a/gcc/testsuite/rust/execute/torture/macros29.rs b/gcc/testsuite/rust/execute/torture/macros29.rs
new file mode 100644
index 00000000000..7bce29b5995
--- /dev/null
+++ b/gcc/testsuite/rust/execute/torture/macros29.rs
@@ -0,0 +1,21 @@
+// { dg-output "1\n" }
+macro_rules! concat {
+  () => {{}};
+}
+
+extern "C" {
+  fn printf(fmt: *const i8, ...);
+}
+
+fn print(s: u32) {
+  printf("%u\n\0" as *const str as *const i8, s);
+}
+
+fn main () -> i32 {
+  let res = concat!("test2") == "test3";
+  if !res {
+    print(1);
+  }
+
+  0
+}
diff --git a/gcc/testsuite/rust/execute/torture/macros30.rs b/gcc/testsuite/rust/execute/torture/macros30.rs
new file mode 100644
index 00000000000..09247e6dd7e
--- /dev/null
+++ b/gcc/testsuite/rust/execute/torture/macros30.rs
@@ -0,0 +1,22 @@
+// { dg-output "1\n" }
+macro_rules! concat {
+  () => {{}};
+}
+
+extern "C" {
+  fn printf(fmt: *const i8, ...);
+}
+
+fn print(s: u32) {
+  printf("%u\n\0" as *const str as *const i8, s);
+}
+
+fn main () -> i32 {
+  let mut x = concat!("x");
+  x = concat!("y");
+  if x == "y" {
+    print(1);
+  }
+
+  0
+}
diff --git a/gcc/testsuite/rust/execute/torture/macros31.rs b/gcc/testsuite/rust/execute/torture/macros31.rs
new file mode 100644
index 00000000000..1a67c473770
--- /dev/null
+++ b/gcc/testsuite/rust/execute/torture/macros31.rs
@@ -0,0 +1,27 @@
+// { dg-additional-options "-w -frust-cfg=A" }
+// { dg-output "A\nB\n" }
+macro_rules! cfg {
+    () => {{}};
+}
+
+extern "C" {
+    fn printf(fmt: *const i8, ...);
+}
+
+fn print(s: &str) {
+    printf("%s\n" as *const str as *const i8, s as *const str as *const i8);
+}
+
+
+fn main() -> i32 {
+    let cfg = cfg!(A) || cfg!(B);
+    if cfg {
+        print("A");
+    }
+    let cfg = cfg!(A) && cfg!(B);
+    if !cfg {
+        print("B");
+    }
+
+    0
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-08 12:36 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:36 [gcc/devel/rust/master] Following up on #1141. Implementing macro expansion or ComparisonExpr, LazyBooleanExpr, AssignmentEx 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).