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
diff --git a/clang/unittests/Lex/HeaderMapTest.cpp b/clang/unittests/Lex/HeaderMapTest.cpp
index e892170..ad0579a 100644
--- a/clang/unittests/Lex/HeaderMapTest.cpp
+++ b/clang/unittests/Lex/HeaderMapTest.cpp
@@ -143,6 +143,15 @@
ASSERT_FALSE(HeaderMapImpl::checkHeader(*File.getBuffer(), NeedsSwap));
}
+TEST(HeaderMapTest, checkHeader0Buckets) {
+ // Create with 1 bucket to avoid 0-sized arrays.
+ MapFile<1, 1> File;
+ File.init();
+ File.Header.NumBuckets = 0;
+ bool NeedsSwap;
+ ASSERT_FALSE(HeaderMapImpl::checkHeader(*File.getBuffer(), NeedsSwap));
+}
+
TEST(HeaderMapTest, checkHeaderNotEnoughBuckets) {
MapFile<1, 1> File;
File.init();