[clang] 0a002f6 - [Sema] Try 2: Sanity-check alignment requested via `__attribute__((assume_aligned(imm)))`
Roman Lebedev via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 24 05:57:11 PST 2020
Author: Roman Lebedev
Date: 2020-01-24T16:56:39+03:00
New Revision: 0a002f679be4a9d363e6f21b707493c18158930b
URL: https://github.com/llvm/llvm-project/commit/0a002f679be4a9d363e6f21b707493c18158930b
DIFF: https://github.com/llvm/llvm-project/commit/0a002f679be4a9d363e6f21b707493c18158930b.diff
LOG: [Sema] Try 2: Sanity-check alignment requested via `__attribute__((assume_aligned(imm)))`
Summary:
For `__builtin_assume_aligned()`, we do validate that the alignment
is not greater than `536870912` (D68824), but we don't do that for
`__attribute__((assume_aligned(N)))` attribute.
I suspect we should.
This was initially committed in a4cfb15d15a8a353fe316f2a9fe1c8c6a6740ef1
but reverted in 210f0882c9e5d6f504b8f29e8a5eae884f812e5c due to
suspicious bot failures.
Reviewers: erichkeane, aaron.ballman, hfinkel, rsmith, jdoerfert
Reviewed By: erichkeane
Subscribers: cfe-commits, llvm-commits
Tags: #llvm, #clang
Differential Revision: https://reviews.llvm.org/D72994
Added:
Modified:
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/Sema/builtin-assume-aligned.c
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 514fca59ca09..8ad981f89b6e 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -1625,6 +1625,12 @@ void Sema::AddAssumeAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E,
<< E->getSourceRange();
return;
}
+
+ // Alignment calculations can wrap around if it's greater than 2**29.
+ unsigned MaximumAlignment = 536870912;
+ if (I > MaximumAlignment)
+ Diag(CI.getLoc(), diag::warn_assume_aligned_too_great)
+ << CI.getRange() << MaximumAlignment;
}
if (OE) {
diff --git a/clang/test/Sema/builtin-assume-aligned.c b/clang/test/Sema/builtin-assume-aligned.c
index 565dc6609442..b862f865c2ca 100644
--- a/clang/test/Sema/builtin-assume-aligned.c
+++ b/clang/test/Sema/builtin-assume-aligned.c
@@ -46,6 +46,7 @@ int test8(int *a, int j) {
void test_void_assume_aligned(void) __attribute__((assume_aligned(32))); // expected-warning {{'assume_aligned' attribute only applies to return values that are pointers}}
int test_int_assume_aligned(void) __attribute__((assume_aligned(16))); // expected-warning {{'assume_aligned' attribute only applies to return values that are pointers}}
void *test_ptr_assume_aligned(void) __attribute__((assume_aligned(64))); // no-warning
+void *test_ptr_assume_aligned(void) __attribute__((assume_aligned(1073741824))); // expected-warning {{requested alignment must be 536870912 bytes or smaller; maximum alignment assumed}}
int j __attribute__((assume_aligned(8))); // expected-warning {{'assume_aligned' attribute only applies to Objective-C methods and functions}}
void *test_no_fn_proto() __attribute__((assume_aligned(32))); // no-warning
More information about the cfe-commits
mailing list