projects
/
oota-llvm.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
BumpPtrAllocator: use uintptr_t when aligning addresses to avoid undefined behaviour
[oota-llvm.git]
/
include
/
llvm
/
Support
/
MathExtras.h
diff --git
a/include/llvm/Support/MathExtras.h
b/include/llvm/Support/MathExtras.h
index 0abba62a2c234850e68c8b8d7541f24f229839e8..adfca78fbeae46ee6fca2c153497d8aa72aadbe5 100644
(file)
--- a/
include/llvm/Support/MathExtras.h
+++ b/
include/llvm/Support/MathExtras.h
@@
-550,16
+550,15
@@
inline uint64_t MinAlign(uint64_t A, uint64_t B) {
return (A | B) & (1 + ~(A | B));
}
return (A | B) & (1 + ~(A | B));
}
-/// \brief Aligns \c
Pt
r to \c Alignment bytes, rounding up.
+/// \brief Aligns \c
Add
r to \c Alignment bytes, rounding up.
///
/// Alignment should be a power of two. This method rounds up, so
///
/// Alignment should be a power of two. This method rounds up, so
-///
AlignPtr(7, 4) == 8 and AlignPt
r(8, 4) == 8.
-inline
char *alignPtr(char *Pt
r, size_t Alignment) {
+///
alignAddr(7, 4) == 8 and alignAdd
r(8, 4) == 8.
+inline
uintptr_t alignAddr(void *Add
r, size_t Alignment) {
assert(Alignment && isPowerOf2_64((uint64_t)Alignment) &&
"Alignment is not a power of two!");
assert(Alignment && isPowerOf2_64((uint64_t)Alignment) &&
"Alignment is not a power of two!");
- return (char *)(((uintptr_t)Ptr + Alignment - 1) &
- ~(uintptr_t)(Alignment - 1));
+ return (((uintptr_t)Addr + Alignment - 1) & ~(uintptr_t)(Alignment - 1));
}
/// NextPowerOf2 - Returns the next power of two (in 64-bits)
}
/// NextPowerOf2 - Returns the next power of two (in 64-bits)