[gccrs,COMMIT,3/3] gccrs: Add new checks for `#[repr(align)]` attribute
Checks
| Context |
Check |
Description |
| linaro-tcwg-bot/tcwg_simplebootstrap_build--master-arm-bootstrap |
fail
|
Patch failed to apply
|
| linaro-tcwg-bot/tcwg_gcc_build--master-arm |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 |
success
|
Build passed
|
Commit Message
From: Yap Zhi Heng <yapzhhg@gmail.com>
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::parse_repr_options): New
check for `#[repr(align)]` to enforce having a parameter that is a power of 2.
gcc/testsuite/ChangeLog:
* rust/compile/invalid_repr_hint.rs: Update existing and add new `align` test cases.
Signed-Off-By: Yap Zhi Heng <yapzhhg@gmail.com>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.
Commit on github: https://github.com/Rust-GCC/gccrs/commit/864defecb6c0faf055005b48a24914651ef5c727
The commit has NOT been mentioned in any issue.
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/4650
gcc/rust/typecheck/rust-hir-type-check-base.cc | 13 +++++++++++++
gcc/testsuite/rust/compile/invalid_repr_hint.rs | 5 ++++-
2 files changed, 17 insertions(+), 1 deletion(-)
@@ -522,6 +522,15 @@ TypeCheckBase::parse_repr_options (const AST::AttrVec &attrs, location_t locus)
if (oparen == std::string::npos)
{
+ if (inline_option.compare ("align") == 0)
+ {
+ rust_error_at (attr.get_locus (), ErrorCode::E0589,
+ "invalid %<repr(align)%> attribute: %<align%> "
+ "needs an argument");
+ delete meta_items;
+ break;
+ }
+
is_pack = inline_option.compare ("packed") == 0;
is_c = inline_option.compare ("C") == 0;
is_integer = (inline_option.compare ("isize") == 0
@@ -571,6 +580,10 @@ TypeCheckBase::parse_repr_options (const AST::AttrVec &attrs, location_t locus)
}
else if (is_align)
{
+ if (value == 0 || (value & (value - 1)) != 0)
+ rust_error_at (
+ attr.get_locus (), ErrorCode::E0589,
+ "invalid %<repr(align)%> attribute: not a power of two");
repr.repr_kind = TyTy::ADTType::ReprKind::ALIGN;
repr.align = value;
}
@@ -6,7 +6,10 @@ struct Foo {
x: i32,
}
-#[repr(align)] // { dg-error "unrecognized representation hint" }
+#[repr(align)] // { dg-error "invalid .repr.align.. attribute: .align. needs an argument" }
struct Bar {
x: i32,
}
+
+#[repr(align(3))] // { dg-error "invalid .repr.align.. attribute: not a power of two" }
+struct Baz {}