Commit 44712d15 by Derek Schuff

Fix subzero build for mac

The subzero mac build fails with errors like the following: /Users/dschuff/code/nacl/native_client/toolchain_build/src/subzero/src/IceGlobalContext.cpp:116: error: ISO C++ forbids variable-size array 'NameBase' Replace the variable-length array with llvm::SmallVector which will still allow stack allocation most of the time. R=stichnot@chromium.org BUG=build subzero on the bots Review URL: https://codereview.chromium.org/335343005
parent 70d6883a
...@@ -113,22 +113,22 @@ IceString GlobalContext::mangleName(const IceString &Name) const { ...@@ -113,22 +113,22 @@ IceString GlobalContext::mangleName(const IceString &Name) const {
return Name; return Name;
unsigned PrefixLength = getTestPrefix().length(); unsigned PrefixLength = getTestPrefix().length();
char NameBase[1 + Name.length()]; llvm::SmallVector<char, 32> NameBase(1 + Name.length());
const size_t BufLen = 30 + Name.length() + PrefixLength; const size_t BufLen = 30 + Name.length() + PrefixLength;
char NewName[BufLen]; llvm::SmallVector<char, 32> NewName(BufLen);
uint32_t BaseLength = 0; // using uint32_t due to sscanf format string uint32_t BaseLength = 0; // using uint32_t due to sscanf format string
int ItemsParsed = sscanf(Name.c_str(), "_ZN%s", NameBase); int ItemsParsed = sscanf(Name.c_str(), "_ZN%s", NameBase.data());
if (ItemsParsed == 1) { if (ItemsParsed == 1) {
// Transform _ZN3foo3barExyz ==> _ZN6Prefix3foo3barExyz // Transform _ZN3foo3barExyz ==> _ZN6Prefix3foo3barExyz
// (splice in "6Prefix") ^^^^^^^ // (splice in "6Prefix") ^^^^^^^
snprintf(NewName, BufLen, "_ZN%u%s%s", PrefixLength, snprintf(NewName.data(), BufLen, "_ZN%u%s%s", PrefixLength,
getTestPrefix().c_str(), NameBase); getTestPrefix().c_str(), NameBase.data());
// We ignore the snprintf return value (here and below). If we // We ignore the snprintf return value (here and below). If we
// somehow miscalculated the output buffer length, the output will // somehow miscalculated the output buffer length, the output will
// be truncated, but it will be truncated consistently for all // be truncated, but it will be truncated consistently for all
// mangleName() calls on the same input string. // mangleName() calls on the same input string.
return NewName; return NewName.data();
} }
// Artificially limit BaseLength to 9 digits (less than 1 billion) // Artificially limit BaseLength to 9 digits (less than 1 billion)
...@@ -136,8 +136,8 @@ IceString GlobalContext::mangleName(const IceString &Name) const { ...@@ -136,8 +136,8 @@ IceString GlobalContext::mangleName(const IceString &Name) const {
// there are more than 9 digits (which we test by looking at the // there are more than 9 digits (which we test by looking at the
// beginning of NameBase), then we consider this a failure to parse // beginning of NameBase), then we consider this a failure to parse
// a namespace mangling, and fall back to the simple prefixing. // a namespace mangling, and fall back to the simple prefixing.
ItemsParsed = sscanf(Name.c_str(), "_Z%9u%s", &BaseLength, NameBase); ItemsParsed = sscanf(Name.c_str(), "_Z%9u%s", &BaseLength, NameBase.data());
if (ItemsParsed == 2 && BaseLength <= strlen(NameBase) && if (ItemsParsed == 2 && BaseLength <= strlen(NameBase.data()) &&
!isdigit(NameBase[0])) { !isdigit(NameBase[0])) {
// Transform _Z3barxyz ==> _ZN6Prefix3barExyz // Transform _Z3barxyz ==> _ZN6Prefix3barExyz
// ^^^^^^^^ ^ // ^^^^^^^^ ^
...@@ -148,8 +148,8 @@ IceString GlobalContext::mangleName(const IceString &Name) const { ...@@ -148,8 +148,8 @@ IceString GlobalContext::mangleName(const IceString &Name) const {
// Transform _Z3barIabcExyz ==> _ZN6Prefix3barIabcEExyz // Transform _Z3barIabcExyz ==> _ZN6Prefix3barIabcEExyz
// ^^^^^^^^ ^ // ^^^^^^^^ ^
// (splice in "N6Prefix", and insert "E" after "3barIabcE") // (splice in "N6Prefix", and insert "E" after "3barIabcE")
char OrigName[Name.length()]; llvm::SmallVector<char, 32> OrigName(Name.length());
char OrigSuffix[Name.length()]; llvm::SmallVector<char, 32> OrigSuffix(Name.length());
uint32_t ActualBaseLength = BaseLength; uint32_t ActualBaseLength = BaseLength;
if (NameBase[ActualBaseLength] == 'I') { if (NameBase[ActualBaseLength] == 'I') {
++ActualBaseLength; ++ActualBaseLength;
...@@ -157,12 +157,13 @@ IceString GlobalContext::mangleName(const IceString &Name) const { ...@@ -157,12 +157,13 @@ IceString GlobalContext::mangleName(const IceString &Name) const {
NameBase[ActualBaseLength] != '\0') NameBase[ActualBaseLength] != '\0')
++ActualBaseLength; ++ActualBaseLength;
} }
strncpy(OrigName, NameBase, ActualBaseLength); strncpy(OrigName.data(), NameBase.data(), ActualBaseLength);
OrigName[ActualBaseLength] = '\0'; OrigName[ActualBaseLength] = '\0';
strcpy(OrigSuffix, NameBase + ActualBaseLength); strcpy(OrigSuffix.data(), NameBase.data() + ActualBaseLength);
snprintf(NewName, BufLen, "_ZN%u%s%u%sE%s", PrefixLength, snprintf(NewName.data(), BufLen, "_ZN%u%s%u%sE%s", PrefixLength,
getTestPrefix().c_str(), BaseLength, OrigName, OrigSuffix); getTestPrefix().c_str(), BaseLength, OrigName.data(),
return NewName; OrigSuffix.data());
return NewName.data();
} }
// Transform bar ==> Prefixbar // Transform bar ==> Prefixbar
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment