mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-09 11:25:55 +00:00
Add error handling in getInt.
Accordingly, update a testcase with a broken datalayout string. Also, we never parse negative numbers, because '-' is used as a separator. Therefore, use unsigned as result type. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@168785 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -152,13 +152,6 @@ DataLayout::InvalidPointerElem = PointerAlignElem::get(~0U, 0U, 0U, 0U);
|
|||||||
// DataLayout Class Implementation
|
// DataLayout Class Implementation
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
/// getInt - Get an integer ignoring errors.
|
|
||||||
static int getInt(StringRef R) {
|
|
||||||
int Result = 0;
|
|
||||||
R.getAsInteger(10, Result);
|
|
||||||
return Result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DataLayout::init(StringRef Desc) {
|
void DataLayout::init(StringRef Desc) {
|
||||||
initializeDataLayoutPass(*PassRegistry::getPassRegistry());
|
initializeDataLayoutPass(*PassRegistry::getPassRegistry());
|
||||||
|
|
||||||
@@ -186,6 +179,16 @@ void DataLayout::init(StringRef Desc) {
|
|||||||
(void)errMsg;
|
(void)errMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get an unsinged integer, including error checks.
|
||||||
|
static unsigned getInt(StringRef R) {
|
||||||
|
if (R.empty())
|
||||||
|
return 0;
|
||||||
|
unsigned Result;
|
||||||
|
bool error = R.getAsInteger(10, Result);
|
||||||
|
assert(!error && "not a number, or does not fit in an unsigned int");
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
std::string DataLayout::parseSpecifier(StringRef Desc) {
|
std::string DataLayout::parseSpecifier(StringRef Desc) {
|
||||||
|
|
||||||
while (!Desc.empty()) {
|
while (!Desc.empty()) {
|
||||||
@@ -207,31 +210,31 @@ std::string DataLayout::parseSpecifier(StringRef Desc) {
|
|||||||
LittleEndian = true;
|
LittleEndian = true;
|
||||||
break;
|
break;
|
||||||
case 'p': {
|
case 'p': {
|
||||||
int AddrSpace = 0;
|
unsigned AddrSpace = 0;
|
||||||
if (Specifier.size() > 1) {
|
if (Specifier.size() > 1) {
|
||||||
AddrSpace = getInt(Specifier.substr(1));
|
AddrSpace = getInt(Specifier.substr(1));
|
||||||
if (AddrSpace < 0 || AddrSpace > (1 << 24))
|
if (AddrSpace > (1 << 24))
|
||||||
return "Invalid address space, must be a positive 24bit integer";
|
return "Invalid address space, must be a 24bit integer";
|
||||||
}
|
}
|
||||||
Split = Token.split(':');
|
Split = Token.split(':');
|
||||||
int PointerMemSizeBits = getInt(Split.first);
|
unsigned PointerMemSizeBits = getInt(Split.first);
|
||||||
if (PointerMemSizeBits < 0 || PointerMemSizeBits % 8 != 0)
|
if (PointerMemSizeBits % 8 != 0)
|
||||||
return "invalid pointer size, must be a positive 8-bit multiple";
|
return "invalid pointer size, must be an 8-bit multiple";
|
||||||
|
|
||||||
// Pointer ABI alignment.
|
// Pointer ABI alignment.
|
||||||
Split = Split.second.split(':');
|
Split = Split.second.split(':');
|
||||||
int PointerABIAlignBits = getInt(Split.first);
|
unsigned PointerABIAlignBits = getInt(Split.first);
|
||||||
if (PointerABIAlignBits < 0 || PointerABIAlignBits % 8 != 0) {
|
if (PointerABIAlignBits % 8 != 0) {
|
||||||
return "invalid pointer ABI alignment, "
|
return "invalid pointer ABI alignment, "
|
||||||
"must be a positive 8-bit multiple";
|
"must be an 8-bit multiple";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pointer preferred alignment.
|
// Pointer preferred alignment.
|
||||||
Split = Split.second.split(':');
|
Split = Split.second.split(':');
|
||||||
int PointerPrefAlignBits = getInt(Split.first);
|
unsigned PointerPrefAlignBits = getInt(Split.first);
|
||||||
if (PointerPrefAlignBits < 0 || PointerPrefAlignBits % 8 != 0) {
|
if (PointerPrefAlignBits % 8 != 0) {
|
||||||
return "invalid pointer preferred alignment, "
|
return "invalid pointer preferred alignment, "
|
||||||
"must be a positive 8-bit multiple";
|
"must be an 8-bit multiple";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PointerPrefAlignBits == 0)
|
if (PointerPrefAlignBits == 0)
|
||||||
@@ -255,26 +258,22 @@ std::string DataLayout::parseSpecifier(StringRef Desc) {
|
|||||||
case 'a': AlignType = AGGREGATE_ALIGN; break;
|
case 'a': AlignType = AGGREGATE_ALIGN; break;
|
||||||
case 's': AlignType = STACK_ALIGN; break;
|
case 's': AlignType = STACK_ALIGN; break;
|
||||||
}
|
}
|
||||||
int Size = getInt(Specifier.substr(1));
|
unsigned Size = getInt(Specifier.substr(1));
|
||||||
if (Size < 0) {
|
|
||||||
return std::string("invalid ") + field + "-size field, "
|
|
||||||
"must be positive";
|
|
||||||
}
|
|
||||||
|
|
||||||
Split = Token.split(':');
|
Split = Token.split(':');
|
||||||
int ABIAlignBits = getInt(Split.first);
|
unsigned ABIAlignBits = getInt(Split.first);
|
||||||
if (ABIAlignBits < 0 || ABIAlignBits % 8 != 0) {
|
if (ABIAlignBits % 8 != 0) {
|
||||||
return std::string("invalid ") + field +"-abi-alignment field, "
|
return std::string("invalid ") + field +"-abi-alignment field, "
|
||||||
"must be a positive 8-bit multiple";
|
"must be an 8-bit multiple";
|
||||||
}
|
}
|
||||||
unsigned ABIAlign = ABIAlignBits / 8;
|
unsigned ABIAlign = ABIAlignBits / 8;
|
||||||
|
|
||||||
Split = Split.second.split(':');
|
Split = Split.second.split(':');
|
||||||
|
|
||||||
int PrefAlignBits = getInt(Split.first);
|
unsigned PrefAlignBits = getInt(Split.first);
|
||||||
if (PrefAlignBits < 0 || PrefAlignBits % 8 != 0) {
|
if (PrefAlignBits % 8 != 0) {
|
||||||
return std::string("invalid ") + field +"-preferred-alignment field, "
|
return std::string("invalid ") + field +"-preferred-alignment field, "
|
||||||
"must be a positive 8-bit multiple";
|
"must be an 8-bit multiple";
|
||||||
}
|
}
|
||||||
unsigned PrefAlign = PrefAlignBits / 8;
|
unsigned PrefAlign = PrefAlignBits / 8;
|
||||||
if (PrefAlign == 0)
|
if (PrefAlign == 0)
|
||||||
@@ -286,23 +285,22 @@ std::string DataLayout::parseSpecifier(StringRef Desc) {
|
|||||||
case 'n': // Native integer types.
|
case 'n': // Native integer types.
|
||||||
Specifier = Specifier.substr(1);
|
Specifier = Specifier.substr(1);
|
||||||
do {
|
do {
|
||||||
int Width = getInt(Specifier);
|
unsigned Width = getInt(Specifier);
|
||||||
if (Width <= 0) {
|
if (Width == 0) {
|
||||||
return std::string("invalid native integer size \'") +
|
return std::string("invalid native integer size \'") +
|
||||||
Specifier.str() + "\', must be a positive integer.";
|
Specifier.str() + "\', must be a non-zero integer.";
|
||||||
}
|
}
|
||||||
if (Width != 0)
|
LegalIntWidths.push_back(Width);
|
||||||
LegalIntWidths.push_back(Width);
|
|
||||||
Split = Token.split(':');
|
Split = Token.split(':');
|
||||||
Specifier = Split.first;
|
Specifier = Split.first;
|
||||||
Token = Split.second;
|
Token = Split.second;
|
||||||
} while (!Specifier.empty() || !Token.empty());
|
} while (!Specifier.empty() || !Token.empty());
|
||||||
break;
|
break;
|
||||||
case 'S': { // Stack natural alignment.
|
case 'S': { // Stack natural alignment.
|
||||||
int StackNaturalAlignBits = getInt(Specifier.substr(1));
|
unsigned StackNaturalAlignBits = getInt(Specifier.substr(1));
|
||||||
if (StackNaturalAlignBits < 0 || StackNaturalAlignBits % 8 != 0) {
|
if (StackNaturalAlignBits % 8 != 0) {
|
||||||
return "invalid natural stack alignment (S-field), "
|
return "invalid natural stack alignment (S-field), "
|
||||||
"must be a positive 8-bit multiple";
|
"must be an 8-bit multiple";
|
||||||
}
|
}
|
||||||
StackNaturalAlign = StackNaturalAlignBits / 8;
|
StackNaturalAlign = StackNaturalAlignBits / 8;
|
||||||
break;
|
break;
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
; RUN: opt -no-aa -gvn -S %s
|
; RUN: opt -no-aa -gvn -S %s
|
||||||
|
|
||||||
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v1
|
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
|
||||||
28:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
|
|
||||||
target triple = "x86_64-unknown-freebsd8.0"
|
target triple = "x86_64-unknown-freebsd8.0"
|
||||||
|
|
||||||
; PR5744
|
; PR5744
|
||||||
|
Reference in New Issue
Block a user