Skip to content

Commit 268afa8

Browse files
committed
Fix handling of coherence related lang_items
gcc/rust/ChangeLog: * hir/rust-ast-lower-base.cc (ASTLoweringBase::handle_lang_item_attribute): Check for COHERENCE_CORE. * util/rust-lang-item.h (RustLangItem::ItemType::COHERENCE_CORE): Add. (RustLangItem::Parse): Parse COHERENCE_CORE. (RustLangItem::ToString): Handle COHERENCE_CORE. gcc/testsuite/ChangeLog: * rust/compile/lang-impl.rs: New test.
1 parent 914b938 commit 268afa8

File tree

3 files changed

+36
-19
lines changed

3 files changed

+36
-19
lines changed

gcc/rust/hir/rust-ast-lower-base.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -785,8 +785,12 @@ ASTLoweringBase::handle_lang_item_attribute (const ItemWrapper &item,
785785
rust_error_at (attr.get_locus (), "unknown lang item");
786786
return;
787787
}
788-
mappings->insert_lang_item (lang_item_type,
789-
item.get_mappings ().get_defid ());
788+
else if (lang_item_type != Analysis::RustLangItem::ItemType::COHERENCE_CORE)
789+
{
790+
// TODO: bypass coherence checks
791+
mappings->insert_lang_item (lang_item_type,
792+
item.get_mappings ().get_defid ());
793+
}
790794
}
791795

792796
bool

gcc/rust/util/rust-lang-item.h

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,6 @@ class RustLangItem
6868
RANGE_INCLUSIVE,
6969
RANGE_TO_INCLUSIVE,
7070

71-
// https://github.com/rust-lang/rust/blob/master/library/core/src/ptr/const_ptr.rs
72-
CONST_PTR,
73-
MUT_PTR,
74-
CONST_SLICE_PTR,
75-
7671
// https://github.com/rust-lang/rust/blob/master/library/core/src/marker.rs
7772
PHANTOM_DATA,
7873

@@ -85,6 +80,11 @@ class RustLangItem
8580
CLONE,
8681
SIZED,
8782

83+
// https://github.com/Rust-GCC/gccrs/issues/1896
84+
// https://github.com/rust-lang/rust/commit/afbecc0f68c4dcfc4878ba5bcb1ac942544a1bdc
85+
// https://github.com/Rust-GCC/gccrs/issues/1494
86+
COHERENCE_CORE,
87+
8888
// delimiter
8989
UNKNOWN,
9090
};
@@ -219,18 +219,6 @@ class RustLangItem
219219
{
220220
return ItemType::RANGE_TO_INCLUSIVE;
221221
}
222-
else if (item.compare ("const_ptr") == 0)
223-
{
224-
return ItemType::CONST_PTR;
225-
}
226-
else if (item.compare ("mut_ptr") == 0)
227-
{
228-
return ItemType::MUT_PTR;
229-
}
230-
else if (item.compare ("const_slice_ptr") == 0)
231-
{
232-
return ItemType::CONST_SLICE_PTR;
233-
}
234222
else if (item.compare ("phantom_data") == 0)
235223
{
236224
return ItemType::PHANTOM_DATA;
@@ -255,6 +243,27 @@ class RustLangItem
255243
{
256244
return ItemType::SIZED;
257245
}
246+
else if (item.compare ("slice_alloc") == 0
247+
|| item.compare ("slice_u8_alloc") == 0
248+
|| item.compare ("str_alloc") == 0 || item.compare ("array") == 0
249+
|| item.compare ("bool") == 0 || item.compare ("char") == 0
250+
|| item.compare ("f32") == 0 || item.compare ("f64") == 0
251+
|| item.compare ("i8") == 0 || item.compare ("i16") == 0
252+
|| item.compare ("i32") == 0 || item.compare ("i64") == 0
253+
|| item.compare ("i128") == 0 || item.compare ("isize") == 0
254+
|| item.compare ("u8") == 0 || item.compare ("u16") == 0
255+
|| item.compare ("u32") == 0 || item.compare ("u64") == 0
256+
|| item.compare ("u128") == 0 || item.compare ("usize") == 0
257+
|| item.compare ("const_ptr") == 0
258+
|| item.compare ("const_slice_ptr") == 0
259+
|| item.compare ("mut_ptr") == 0
260+
|| item.compare ("mut_slice_ptr") == 0
261+
|| item.compare ("slice_u8") == 0 || item.compare ("slice") == 0
262+
|| item.compare ("str") == 0 || item.compare ("f32_runtime") == 0
263+
|| item.compare ("f64_runtime") == 0)
264+
{
265+
return ItemType::COHERENCE_CORE;
266+
}
258267

259268
return ItemType::UNKNOWN;
260269
}
@@ -346,6 +355,8 @@ class RustLangItem
346355
case SIZED:
347356
return "sized";
348357

358+
case COHERENCE_CORE:
359+
return "<COHERENCE_CORE>";
349360
case UNKNOWN:
350361
return "<UNKNOWN>";
351362
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#[lang = "i8"]
2+
impl i32 {}

0 commit comments

Comments
 (0)