[PATCH] D72994: [Sema] Sanitize alignment requested via `__attribute__((assume_aligned(imm)))`
Roman Lebedev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Jan 19 02:33:43 PST 2020
lebedev.ri created this revision.
lebedev.ri added reviewers: erichkeane, aaron.ballman, hfinkel, rsmith, jdoerfert.
lebedev.ri added a project: LLVM.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
lebedev.ri added a parent revision: D72993: [NFC][Codegen] Use MaybeAlign + APInt::getLimitedValue() when creating Alignment attr.
For `__builtin_assume_aligned()`, we do validate that the alignment
is not greater than `536870912` (D68824 <https://reviews.llvm.org/D68824>), but we don't do that for
`__attribute__((assume_aligned(N)))` attribute.
I suspect we should.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D72994
Files:
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/Sema/builtin-assume-aligned.c
Index: clang/test/Sema/builtin-assume-aligned.c
===================================================================
--- clang/test/Sema/builtin-assume-aligned.c
+++ clang/test/Sema/builtin-assume-aligned.c
@@ -46,6 +46,7 @@
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
Index: clang/lib/Sema/SemaDeclAttr.cpp
===================================================================
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -1625,6 +1625,12 @@
<< 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) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72994.238978.patch
Type: text/x-patch
Size: 1607 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200119/ac7139e6/attachment-0001.bin>
More information about the cfe-commits
mailing list