aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile-expr.cc
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-05-26 08:55:57 +0000
committerGitHub <noreply@github.com>2022-05-26 08:55:57 +0000
commita4455d8f522cad015f3540f118f8c6ce2775fccb (patch)
tree523681227dc0a48b4f7176ca9dcedd37a46f1f51 /gcc/rust/backend/rust-compile-expr.cc
parent5c84a5ca514398f858020c378c5a26f0593eaee3 (diff)
parent4cfd6942c07021db05beae40e1128901e37109e6 (diff)
downloadgcc-a4455d8f522cad015f3540f118f8c6ce2775fccb.zip
gcc-a4455d8f522cad015f3540f118f8c6ce2775fccb.tar.gz
gcc-a4455d8f522cad015f3540f118f8c6ce2775fccb.tar.bz2
Merge #1280
1280: Str's have the same layout as [T] r=philberty a=philberty Raw strings have a very specific type layout which maps over to Slices. It also has very specific type checking rules so for example: let a:&str = "TEST 1"; let b:&str = &"TEST 2"; Are both the same type this is likely to be for all DST's but lets do one rule at a time. Fixes #1023 #1271 Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc/rust/backend/rust-compile-expr.cc')
-rw-r--r--gcc/rust/backend/rust-compile-expr.cc19
1 files changed, 17 insertions, 2 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc
index b176ed2..4168bb8 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -1014,13 +1014,28 @@ tree
CompileExpr::compile_string_literal (const HIR::LiteralExpr &expr,
const TyTy::BaseType *tyty)
{
+ tree fat_pointer = TyTyResolveCompile::compile (ctx, tyty);
+
rust_assert (expr.get_lit_type () == HIR::Literal::STRING);
const auto literal_value = expr.get_literal ();
auto base = ctx->get_backend ()->string_constant_expression (
literal_value.as_string ());
- return address_expression (base, build_pointer_type (TREE_TYPE (base)),
- expr.get_locus ());
+ tree data = address_expression (base, build_pointer_type (TREE_TYPE (base)),
+ expr.get_locus ());
+
+ TyTy::BaseType *usize = nullptr;
+ bool ok = ctx->get_tyctx ()->lookup_builtin ("usize", &usize);
+ rust_assert (ok);
+ tree type = TyTyResolveCompile::compile (ctx, usize);
+
+ mpz_t ival;
+ mpz_init_set_ui (ival, literal_value.as_string ().size ());
+ tree size = double_int_to_tree (type, mpz_get_double_int (type, ival, true));
+
+ return ctx->get_backend ()->constructor_expression (fat_pointer, false,
+ {data, size}, -1,
+ expr.get_locus ());
}
tree