diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-07-17 19:52:16 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-17 19:52:16 +0000 |
commit | e4cdb24c468b8a848980f7138767fbe093471c5b (patch) | |
tree | 0fb6789a85aa49e4044679b8a6b10d26e953dc25 /gcc | |
parent | fd2bd659e44e5b7fea92bc34a4864f057f387490 (diff) | |
parent | 9c7a580aa13707a18c53bc772c3d9301dd9bfb2c (diff) | |
download | gcc-e4cdb24c468b8a848980f7138767fbe093471c5b.zip gcc-e4cdb24c468b8a848980f7138767fbe093471c5b.tar.gz gcc-e4cdb24c468b8a848980f7138767fbe093471c5b.tar.bz2 |
Merge #1391
1391: Fix ICE on duplicate compilation of ExternBlock items r=philberty a=philberty
When we declare an extern block after where it is used the query
compilation system in the backend code-gen pass will resolve this and
compile as required. But when the iteration of the crate as part of the
pipeline we end up compiling this function again. The check we used to stop
this was copy paste from the other function items but in this case the
check for function_completed is not valid as this is a prototype for an
extern item so we dont add this to the translation unit as an fndecl which
meant we hit the ICE where we compile and add it again.
Fixes #1323
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/backend/rust-compile-extern.h | 20 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/issue-1323-1.rs | 18 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/issue-1323-2.rs | 16 |
3 files changed, 46 insertions, 8 deletions
diff --git a/gcc/rust/backend/rust-compile-extern.h b/gcc/rust/backend/rust-compile-extern.h index ddad350..4355e4a 100644 --- a/gcc/rust/backend/rust-compile-extern.h +++ b/gcc/rust/backend/rust-compile-extern.h @@ -46,6 +46,14 @@ public: void visit (HIR::ExternalStaticItem &item) override { + // check if its already been compiled + Bvariable *lookup = ctx->get_backend ()->error_variable (); + if (ctx->lookup_var_decl (item.get_mappings ().get_hirid (), &lookup)) + { + reference = ctx->get_backend ()->var_expression (lookup, ref_locus); + return; + } + TyTy::BaseType *resolved_type = nullptr; bool ok = ctx->get_tyctx ()->lookup_type (item.get_mappings ().get_hirid (), &resolved_type); @@ -102,15 +110,11 @@ public: if (ctx->lookup_function_decl (fntype->get_ty_ref (), &lookup, fntype->get_id (), fntype)) { - // has this been added to the list then it must be finished - if (ctx->function_completed (lookup)) - { - tree dummy = NULL_TREE; - if (!ctx->lookup_function_decl (fntype->get_ty_ref (), &dummy)) - ctx->insert_function_decl (fntype, lookup); + reference + = address_expression (lookup, build_pointer_type (TREE_TYPE (lookup)), + ref_locus); - return; - } + return; } if (fntype->has_subsititions_defined ()) diff --git a/gcc/testsuite/rust/compile/issue-1323-1.rs b/gcc/testsuite/rust/compile/issue-1323-1.rs new file mode 100644 index 0000000..a617425 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-1323-1.rs @@ -0,0 +1,18 @@ +fn main() { + let mut x = [1, 2, 3]; + let y: i32 = x[0]; + print_int(y); +} + +extern "C" { + fn printf(s: *const i8, ...); +} + +fn print_int(value: i32) { + let s = "%d\n\0"; + let s_p = s as *const str; + let c_p = s_p as *const i8; + unsafe { + printf(c_p, value as isize); + } +} diff --git a/gcc/testsuite/rust/compile/issue-1323-2.rs b/gcc/testsuite/rust/compile/issue-1323-2.rs new file mode 100644 index 0000000..45168b2 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-1323-2.rs @@ -0,0 +1,16 @@ +fn print_int(value: i32) { + let s = "%d\n\0"; + let s_p = s as *const str; + let c_p = s_p as *const i8; + unsafe { + printf(c_p, value as isize); + } +} + +fn main() { + print_int(5); +} + +extern "C" { + fn printf(s: *const i8, ...); +} |