aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Lex/HeaderMap.cpp
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2016-02-22 22:24:22 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2016-02-22 22:24:22 +0000
commit3a7def09fece8d6a403f5002dd4811704fa2b3c4 (patch)
treecc766a73bec0223cb7be43ad37b6c9c3a02d332c /clang/lib/Lex/HeaderMap.cpp
parent964b70d559fad083744ea2791def82c564087388 (diff)
downloadllvm-3a7def09fece8d6a403f5002dd4811704fa2b3c4.zip
llvm-3a7def09fece8d6a403f5002dd4811704fa2b3c4.tar.gz
llvm-3a7def09fece8d6a403f5002dd4811704fa2b3c4.tar.bz2
Lex: Check for 0 buckets on header map construction
Switch to using `isPowerOf2_32()` to check whether the buckets are a power of two, and as a side benefit reject loading a header map with no buckets. This is a follow-up to r261448. llvm-svn: 261585
Diffstat (limited to 'clang/lib/Lex/HeaderMap.cpp')
-rw-r--r--clang/lib/Lex/HeaderMap.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/clang/lib/Lex/HeaderMap.cpp b/clang/lib/Lex/HeaderMap.cpp
index 67b6631..be0d477 100644
--- a/clang/lib/Lex/HeaderMap.cpp
+++ b/clang/lib/Lex/HeaderMap.cpp
@@ -86,10 +86,10 @@ bool HeaderMapImpl::checkHeader(const llvm::MemoryBuffer &File,
// Check the number of buckets. It should be a power of two, and there
// should be enough space in the file for all of them.
- auto NumBuckets = NeedsByteSwap
- ? llvm::sys::getSwappedBytes(Header->NumBuckets)
- : Header->NumBuckets;
- if (NumBuckets & (NumBuckets - 1))
+ uint32_t NumBuckets = NeedsByteSwap
+ ? llvm::sys::getSwappedBytes(Header->NumBuckets)
+ : Header->NumBuckets;
+ if (!llvm::isPowerOf2_32(NumBuckets))
return false;
if (File.getBufferSize() <
sizeof(HMapHeader) + sizeof(HMapBucket) * NumBuckets)
@@ -208,7 +208,7 @@ StringRef HeaderMapImpl::lookupFilename(StringRef Filename,
unsigned NumBuckets = getEndianAdjustedWord(Hdr.NumBuckets);
// Don't probe infinitely. This should be checked before constructing.
- assert(!(NumBuckets & (NumBuckets - 1)) && "Expected power of 2");
+ assert(llvm::isPowerOf2_32(NumBuckets) && "Expected power of 2");
// Linearly probe the hash table.
for (unsigned Bucket = HashHMapKey(Filename);; ++Bucket) {