aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2022-03-14 11:33:53 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2022-03-16 09:38:09 +0100
commitb6b567171c1f5e947dd80b3c9958b1d9520d4888 (patch)
tree681beb045d95736bb2d4cdb357a8f58b5f05889e /gcc
parent41f402f0b19c7e4f19f8d4d65d15223d2752f302 (diff)
downloadgcc-b6b567171c1f5e947dd80b3c9958b1d9520d4888.zip
gcc-b6b567171c1f5e947dd80b3c9958b1d9520d4888.tar.gz
gcc-b6b567171c1f5e947dd80b3c9958b1d9520d4888.tar.bz2
attribute expansion: Fix spurious stripping of tail expression
This commit fixes the issue reported in #391, but highlights another one, which will be reported.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/ast/rust-ast.h7
-rw-r--r--gcc/rust/hir/rust-ast-lower-expr.h4
-rw-r--r--gcc/testsuite/rust/compile/xfail/slice1.rs6
3 files changed, 12 insertions, 5 deletions
diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h
index d07501e..c254712 100644
--- a/gcc/rust/ast/rust-ast.h
+++ b/gcc/rust/ast/rust-ast.h
@@ -249,7 +249,8 @@ public:
BYTE_STRING,
INT,
FLOAT,
- BOOL
+ BOOL,
+ ERROR
};
private:
@@ -274,11 +275,11 @@ public:
static Literal create_error ()
{
- return Literal ("", CHAR, PrimitiveCoreType::CORETYPE_UNKNOWN);
+ return Literal ("", ERROR, PrimitiveCoreType::CORETYPE_UNKNOWN);
}
// Returns whether literal is in an invalid state.
- bool is_error () const { return value_as_string == ""; }
+ bool is_error () const { return type == ERROR; }
};
/* Forward decl - definition moved to rust-expr.h as it requires LiteralExpr to
diff --git a/gcc/rust/hir/rust-ast-lower-expr.h b/gcc/rust/hir/rust-ast-lower-expr.h
index e316868..4bfcbc8 100644
--- a/gcc/rust/hir/rust-ast-lower-expr.h
+++ b/gcc/rust/hir/rust-ast-lower-expr.h
@@ -359,6 +359,10 @@ public:
case AST::Literal::LitType::BOOL:
type = HIR::Literal::LitType::BOOL;
break;
+ // Error literals should have been stripped during expansion
+ case AST::Literal::LitType::ERROR:
+ gcc_unreachable ();
+ break;
}
auto crate_num = mappings->get_current_crate ();
Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
diff --git a/gcc/testsuite/rust/compile/xfail/slice1.rs b/gcc/testsuite/rust/compile/xfail/slice1.rs
index 48abcbe..3087d4d 100644
--- a/gcc/testsuite/rust/compile/xfail/slice1.rs
+++ b/gcc/testsuite/rust/compile/xfail/slice1.rs
@@ -1,3 +1,5 @@
-fn foo (e: &str) -> &str {
- &"" // { dg-bogus "cannot strip expression in this position - outer attributes not allowed" "#391" { xfail *-*-* } }
+// { dg-additional-options "-w" }
+
+fn foo(e: &str) -> &str { // { dg-bogus "expected" "#391" { xfail *-*-* } }
+ &"" // { dg-bogus "expected" "#391" { xfail *-*-* } }
}