You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Clang] Allow non-constant sizes for __builtin_assume_dereferenceable. (llvm#156929)
Update Clang's __builtin_assume_dereferenceable to support non-constant
lengths. The corresponding assume bundle has been updated to support
non-constant sizes in cad62df.
The current docs for the builtin don't mention the constant requirement
for the size argument, so don't need to be updated:
https://clang.llvm.org/docs/LanguageExtensions.html#builtin-assume-dereferenceable
A number of patches landed recently to make the optimizer make better
use of the dereferenceable assumptions, and once
llvm#156730 lands, it can be used
to vectorize some early-exit loops, for example std::find with
std::vector::iterator: https://godbolt.org/z/qo58PKG37
```
#include <algorithm>
#include <cstddef>
#include <vector>
auto find(std::vector<short>::iterator first, short s, unsigned size) {
auto Addr = __builtin_assume_aligned(std::to_address(first), 2);
__builtin_assume_dereferenceable(std::to_address(first), size * sizeof(short));
return std::find(first, first + size, s);
}
```
PR: llvm#156929
(cherry picked from commit c8d065b)
Copy file name to clipboardExpand all lines: clang/docs/ReleaseNotes.rst
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -389,6 +389,8 @@ Non-comprehensive list of changes in this release
389
389
this build without optimizations (i.e. use `-O0` or use the `optnone` function
390
390
attribute) or use the `fno-sanitize-merge=` flag in optimized builds.
391
391
392
+
- ``__builtin_assume_dereferenceable`` now accepts non-constant size operands.
393
+
392
394
New Compiler Flags
393
395
------------------
394
396
- New option ``-fno-sanitize-debug-trap-reasons`` added to disable emitting trap reasons into the debug info when compiling with trapping UBSan (e.g. ``-fsanitize-trap=undefined``).
0 commit comments