1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

DataLayout: Provide nicer diagnostics for malformed strings

llvm-svn: 223911
This commit is contained in:
David Majnemer 2014-12-10 02:36:41 +00:00
parent 6f52870a48
commit df607e95a0
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); std::pair<StringRef, StringRef> Split = Str.split(Separator);
if (Split.second.empty() && Split.first != Str) if (Split.second.empty() && Split.first != Str)
report_fatal_error("Trailing separator in datalayout string"); 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; return Split;
} }
@ -297,6 +299,9 @@ void DataLayout::parseSpecifier(StringRef Desc) {
"Sized aggregate specification in datalayout string"); "Sized aggregate specification in datalayout string");
// ABI alignment. // ABI alignment.
if (Rest.empty())
report_fatal_error(
"Missing alignment specification in datalayout string");
Split = split(Rest, ':'); Split = split(Rest, ':');
unsigned ABIAlign = inBytes(getInt(Tok)); unsigned ABIAlign = inBytes(getInt(Tok));
@ -328,8 +333,12 @@ void DataLayout::parseSpecifier(StringRef Desc) {
break; break;
} }
case 'm': case 'm':
assert(Tok.empty()); if (!Tok.empty())
assert(Rest.size() == 1); 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]) { switch(Rest[0]) {
default: default:
report_fatal_error("Unknown mangling in datalayout string"); 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