-
Notifications
You must be signed in to change notification settings - Fork 187
Open
Description
gccrs/gcc/rust/typecheck/rust-tyty.h
Lines 529 to 541 in 95dcbb2
// Representation options, specified via attributes e.g. #[repr(packed)] struct ReprOptions { // bool is_c; // bool is_transparent; //... // For align and pack: 0 = unspecified. Nonzero = byte alignment. // It is an error for both to be nonzero, this should be caught when // parsing the #[repr] attribute. unsigned char align = 0; unsigned char pack = 0; };
I think it might be worth having some kind of error node state here. For example, during the type-checking of this structure, you could represent an error state by a flag or something so that when you are compiling the type we know if it's ok or not so we can error or ignore the options. This will only really matter down the line when we get rid of the saw_errors guards between each compiler pass.
Originally posted by @philberty in #1188 (comment)
For ReprFlags
:
- We can create an enum., like:
enum ReprFlags : unsigned int {
IS_C,
IS_SIMD,
IS_TRANSPARENT,
IS_LINEAR,
RANDOMIZE_LAYOUT,
IS_UNOPTIMISABLE // Not sure to add this
};
Adding error node:
- We can add a error node in
struct ReprOptions
, like:
bool is_error
Raise Error while parsing the options:
- By adding a check here:
gccrs/gcc/rust/typecheck/rust-hir-type-check-base.cc
Lines 312 to 347 in 0fe8a6b
size_t oparen = inline_option.find ('(', 0); | |
bool is_pack = false, is_align = false; | |
unsigned char value = 1; | |
if (oparen == std::string::npos) | |
{ | |
is_pack = inline_option.compare ("packed") == 0; | |
is_align = inline_option.compare ("align") == 0; | |
} | |
else | |
{ | |
std::string rep = inline_option.substr (0, oparen); | |
is_pack = rep.compare ("packed") == 0; | |
is_align = rep.compare ("align") == 0; | |
size_t cparen = inline_option.find (')', oparen); | |
if (cparen == std::string::npos) | |
{ | |
rust_error_at (locus, "malformed attribute"); | |
} | |
std::string value_str = inline_option.substr (oparen, cparen); | |
value = strtoul (value_str.c_str () + 1, NULL, 10); | |
} | |
if (is_pack) | |
repr.pack = value; | |
else if (is_align) | |
repr.align = value; | |
// Multiple repr options must be specified with e.g. #[repr(C, | |
// packed(2))]. | |
break; | |
} | |
} |
Implementation of this in rustc:
Valid rustc reprs are here:
.help = valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
In rustc:
- The Struct
ReprOptions
is defined as:
https://github.com/rust-lang/rust/blob/fcf3006e0133365ecd26894689c086387edcbecb/compiler/rustc_abi/src/lib.rs#L71-L87 - The
Reprflags
are implemented as :
https://github.com/rust-lang/rust/blob/fcf3006e0133365ecd26894689c086387edcbecb/compiler/rustc_abi/src/lib.rs#L36-L50
Metadata
Metadata
Assignees
Labels
No labels