DataLayout: Provide nicer diagnostics for malformed strings

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223911 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Majnemer 2014-12-10 02:36:41 +00:00
parent 09df76443e
commit fda17198fd
5 changed files with 23 additions and 2 deletions

View File

@ -199,6 +199,8 @@ static std::pair<StringRef, StringRef> split(StringRef Str, char Separator) {
std::pair<StringRef, StringRef> Split = Str.split(Separator);
if (Split.second.empty() && Split.first != Str)
report_fatal_error("Trailing separator in datalayout string");
if (!Split.second.empty() && Split.first.empty())
report_fatal_error("Expected token before separator in datalayout string");
return Split;
}
@ -297,6 +299,9 @@ void DataLayout::parseSpecifier(StringRef Desc) {
"Sized aggregate specification in datalayout string");
// ABI alignment.
if (Rest.empty())
report_fatal_error(
"Missing alignment specification in datalayout string");
Split = split(Rest, ':');
unsigned ABIAlign = inBytes(getInt(Tok));
@ -328,8 +333,12 @@ void DataLayout::parseSpecifier(StringRef Desc) {
break;
}
case 'm':
assert(Tok.empty());
assert(Rest.size() == 1);
if (!Tok.empty())
report_fatal_error("Unexpected trailing characters after mangling specifier in datalayout string");
if (Rest.empty())
report_fatal_error("Expected mangling specifier in datalayout string");
if (Rest.size() > 1)
report_fatal_error("Unknown mangling specifier in datalayout string");
switch(Rest[0]) {
default:
report_fatal_error("Unknown mangling in datalayout string");

View File

@ -0,0 +1,3 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "m"
; CHECK: Expected mangling specifier in datalayout string

View File

@ -0,0 +1,3 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "m."
; CHECK: Unexpected trailing characters after mangling specifier in datalayout string

View File

@ -0,0 +1,3 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "f"
; CHECK: Missing alignment specification in datalayout string

View File

@ -0,0 +1,3 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = ":32"
; CHECK: Expected token before separator in datalayout string