Fix ARM build. (#3165)

This fixes an issue with `constexpr` in ARM builds. The table needs to
be a _`static`_ `constexpr` in order to be used w/o capture in the
lambda. This was reported with an alternative fix in #3164 -- this fix
avoids adding captures to the lambda by fixing the `constexpr`
declaration.

The name is tweaked and parentheses added to try to keep `clang-format`
producing a nice formatting for this weird construct. Without these, I
was getting distractingly bad results.

The code path wasn't built outside of ARM, and so mostly showed up on
ARM macOS builds -- in general, we don't currently have non-x86 GitHub
CI to catch this kind of issue. Sorry for folks who bumped into it!

I'm planning a subsequent PR that will refactor code so that we have
more common code in the fallback and reduce our exposure to
single-platform build issues like this.
This commit is contained in:
Chandler Carruth
2023-08-29 16:02:52 +00:00
committed by GitHub
parent f63834c71d
commit 82860c4573
+5 -7
View File
@@ -68,7 +68,7 @@ static auto ScanForIdentifierPrefix(llvm::StringRef text) -> llvm::StringRef {
// A table of booleans that we can use to classify bytes as being valid
// identifier (or keyword) characters. This is used in the generic,
// non-vectorized fallback code to scan for length of an identifier.
constexpr std::array<bool, 256> IsIdentifierByteTable = []() constexpr {
static constexpr std::array<bool, 256> IsIdByteTable = ([]() constexpr {
std::array<bool, 256> table = {};
for (char c = '0'; c <= '9'; ++c) {
table[c] = true;
@@ -81,7 +81,7 @@ static auto ScanForIdentifierPrefix(llvm::StringRef text) -> llvm::StringRef {
}
table['_'] = true;
return table;
}();
})();
#if __x86_64__
// This code uses a scheme derived from the techniques in Geoff Langdale and
@@ -196,17 +196,15 @@ static auto ScanForIdentifierPrefix(llvm::StringRef text) -> llvm::StringRef {
// Fallback to scalar loop. We only end up here when we don't have >=16
// bytes to scan or we find a UTF-8 unicode character.
// TODO: This assumes all Unicode characters are non-identifiers.
while (i < size &&
IsIdentifierByteTable[static_cast<unsigned char>(text[i])]) {
while (i < size && IsIdByteTable[static_cast<unsigned char>(text[i])]) {
++i;
}
return text.substr(0, i);
#else
// TODO: Optimize this with SIMD for other architectures.
return text.take_while([](char c) {
return IsIdentifierByteTable[static_cast<unsigned char>(c)];
});
return text.take_while(
[](char c) { return IsIdByteTable[static_cast<unsigned char>(c)]; });
#endif
}