Skip to content

Fix handling of coherence related lang_items #1970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
231 changes: 208 additions & 23 deletions gcc/rust/util/rust-lang-item.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ class RustLangItem
RANGE_INCLUSIVE,
RANGE_TO_INCLUSIVE,

// https://github.com/rust-lang/rust/blob/master/library/core/src/ptr/const_ptr.rs
CONST_PTR,
MUT_PTR,
CONST_SLICE_PTR,

// https://github.com/rust-lang/rust/blob/master/library/core/src/marker.rs
PHANTOM_DATA,

Expand All @@ -85,6 +80,40 @@ class RustLangItem
CLONE,
SIZED,

// https://github.com/Rust-GCC/gccrs/issues/1896
// https://github.com/rust-lang/rust/commit/afbecc0f68c4dcfc4878ba5bcb1ac942544a1bdc
// https://github.com/Rust-GCC/gccrs/issues/1494
// https://github.com/rust-lang/rust/blob/master/library/core/src/ptr/const_ptr.rs
SLICE_ALLOC,
SLICE_U8_ALLOC,
STR_ALLOC,
ARRAY,
BOOL,
CHAR,
F32,
F64,
I8,
I16,
I32,
I64,
I128,
ISIZE,
U8,
U16,
U32,
U64,
U128,
USIZE,
CONST_PTR,
CONST_SLICE_PTR,
MUT_PTR,
MUT_SLICE_PTR,
SLICE_U8,
SLICE,
STR,
F32_RUNTIME,
F64_RUNTIME,

// delimiter
UNKNOWN,
};
Expand Down Expand Up @@ -219,18 +248,6 @@ class RustLangItem
{
return ItemType::RANGE_TO_INCLUSIVE;
}
else if (item.compare ("const_ptr") == 0)
{
return ItemType::CONST_PTR;
}
else if (item.compare ("mut_ptr") == 0)
{
return ItemType::MUT_PTR;
}
else if (item.compare ("const_slice_ptr") == 0)
{
return ItemType::CONST_SLICE_PTR;
}
else if (item.compare ("phantom_data") == 0)
{
return ItemType::PHANTOM_DATA;
Expand All @@ -255,6 +272,122 @@ class RustLangItem
{
return ItemType::SIZED;
}
else if (item.compare ("slice_alloc") == 0)
{
return ItemType::SLICE_ALLOC;
}
else if (item.compare ("slice_u8_alloc") == 0)
{
return ItemType::SLICE_U8_ALLOC;
}
else if (item.compare ("str_alloc") == 0)
{
return ItemType::STR_ALLOC;
}
else if (item.compare ("array") == 0)
{
return ItemType::ARRAY;
}
else if (item.compare ("bool") == 0)
{
return ItemType::BOOL;
}
else if (item.compare ("char") == 0)
{
return ItemType::CHAR;
}
else if (item.compare ("f32") == 0)
{
return ItemType::F32;
}
else if (item.compare ("f64") == 0)
{
return ItemType::F64;
}
else if (item.compare ("i8") == 0)
{
return ItemType::I8;
}
else if (item.compare ("i16") == 0)
{
return ItemType::I16;
}
else if (item.compare ("i32") == 0)
{
return ItemType::I32;
}
else if (item.compare ("i64") == 0)
{
return ItemType::I64;
}
else if (item.compare ("i128") == 0)
{
return ItemType::I128;
}
else if (item.compare ("isize") == 0)
{
return ItemType::ISIZE;
}
else if (item.compare ("u8") == 0)
{
return ItemType::U8;
}
else if (item.compare ("u16") == 0)
{
return ItemType::U16;
}
else if (item.compare ("u32") == 0)
{
return ItemType::U32;
}
else if (item.compare ("u64") == 0)
{
return ItemType::U64;
}
else if (item.compare ("u128") == 0)
{
return ItemType::U128;
}
else if (item.compare ("usize") == 0)
{
return ItemType::USIZE;
}
else if (item.compare ("const_ptr") == 0)
{
return ItemType::CONST_PTR;
}
else if (item.compare ("const_slice_ptr") == 0)
{
return ItemType::CONST_SLICE_PTR;
}
else if (item.compare ("mut_ptr") == 0)
{
return ItemType::MUT_PTR;
}
else if (item.compare ("mut_slice_ptr") == 0)
{
return ItemType::MUT_SLICE_PTR;
}
else if (item.compare ("slice_u8") == 0)
{
return ItemType::SLICE_U8;
}
else if (item.compare ("slice") == 0)
{
return ItemType::SLICE;
}
else if (item.compare ("str") == 0)
{
return ItemType::STR;
}
else if (item.compare ("f32_runtime") == 0)
{
return ItemType::F32_RUNTIME;
}
else if (item.compare ("f64_runtime") == 0)
{
return ItemType::F64_RUNTIME;
}

return ItemType::UNKNOWN;
}
Expand Down Expand Up @@ -327,12 +460,6 @@ class RustLangItem
return "RangeInclusive";
case RANGE_TO_INCLUSIVE:
return "RangeToInclusive";
case CONST_PTR:
return "const_ptr";
case MUT_PTR:
return "mut_ptr";
case CONST_SLICE_PTR:
return "const_slice_ptr";
case PHANTOM_DATA:
return "phantom_data";
case FN_ONCE:
Expand All @@ -345,6 +472,64 @@ class RustLangItem
return "clone";
case SIZED:
return "sized";
case SLICE_ALLOC:
return "slice_alloc";
case SLICE_U8_ALLOC:
return "slice_u8_alloc";
case STR_ALLOC:
return "str_alloc";
case ARRAY:
return "array";
case BOOL:
return "bool";
case CHAR:
return "char";
case F32:
return "f32";
case F64:
return "f64";
case I8:
return "i8";
case I16:
return "i16";
case I32:
return "i32";
case I64:
return "i64";
case I128:
return "i128";
case ISIZE:
return "isize";
case U8:
return "u8";
case U16:
return "u16";
case U32:
return "u32";
case U64:
return "u64";
case U128:
return "u128";
case USIZE:
return "usize";
case CONST_PTR:
return "const_ptr";
case CONST_SLICE_PTR:
return "const_slice_ptr";
case MUT_PTR:
return "mut_ptr";
case MUT_SLICE_PTR:
return "mut_slice_ptr";
case SLICE_U8:
return "slice_u8";
case SLICE:
return "slice";
case STR:
return "str";
case F32_RUNTIME:
return "f32_runtime";
case F64_RUNTIME:
return "f64_runtime";

case UNKNOWN:
return "<UNKNOWN>";
Expand Down
2 changes: 2 additions & 0 deletions gcc/testsuite/rust/compile/lang-impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#[lang = "i8"]
impl i32 {}