[llvm] r223898 - DataLayout: Move asserts over to report_fatal_error
David Majnemer
david.majnemer at gmail.com
Tue Dec 9 17:17:08 PST 2014
Author: majnemer
Date: Tue Dec 9 19:17:08 2014
New Revision: 223898
URL: http://llvm.org/viewvc/llvm-project?rev=223898&view=rev
Log:
DataLayout: Move asserts over to report_fatal_error
As indicated by the tests, it is possible to feed the AsmParser an
invalid datalayout string. We should verify the result of parsing this
string regardless of whether or not we have assertions enabled.
Added:
llvm/trunk/test/Assembler/invalid-datalayout1.ll
llvm/trunk/test/Assembler/invalid-datalayout2.ll
llvm/trunk/test/Assembler/invalid-datalayout3.ll
llvm/trunk/test/Assembler/invalid-datalayout4.ll
llvm/trunk/test/Assembler/invalid-datalayout5.bc
llvm/trunk/test/Assembler/invalid-datalayout5.ll
Modified:
llvm/trunk/lib/IR/DataLayout.cpp
Modified: llvm/trunk/lib/IR/DataLayout.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DataLayout.cpp?rev=223898&r1=223897&r2=223898&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DataLayout.cpp (original)
+++ llvm/trunk/lib/IR/DataLayout.cpp Tue Dec 9 19:17:08 2014
@@ -247,8 +247,8 @@ void DataLayout::parseSpecifier(StringRe
case 'p': {
// Address space.
unsigned AddrSpace = Tok.empty() ? 0 : getInt(Tok);
- assert(AddrSpace < 1 << 24 &&
- "Invalid address space, must be a 24bit integer");
+ if (!isUInt<24>(AddrSpace))
+ report_fatal_error("Invalid address space, must be a 24bit integer");
// Size.
Split = split(Rest, ':');
@@ -285,8 +285,9 @@ void DataLayout::parseSpecifier(StringRe
// Bit size.
unsigned Size = Tok.empty() ? 0 : getInt(Tok);
- assert((AlignType != AGGREGATE_ALIGN || Size == 0) &&
- "These specifications don't have a size");
+ if (AlignType == AGGREGATE_ALIGN && Size != 0)
+ report_fatal_error(
+ "Sized aggregate specification in datalayout string");
// ABI alignment.
Split = split(Rest, ':');
@@ -306,7 +307,9 @@ void DataLayout::parseSpecifier(StringRe
case 'n': // Native integer types.
for (;;) {
unsigned Width = getInt(Tok);
- assert(Width != 0 && "width must be non-zero");
+ if (Width == 0)
+ report_fatal_error(
+ "Zero width native integer type in datalayout string");
LegalIntWidths.push_back(Width);
if (Rest.empty())
break;
@@ -322,7 +325,7 @@ void DataLayout::parseSpecifier(StringRe
assert(Rest.size() == 1);
switch(Rest[0]) {
default:
- llvm_unreachable("Unknown mangling in datalayout string");
+ report_fatal_error("Unknown mangling in datalayout string");
case 'e':
ManglingMode = MM_ELF;
break;
@@ -338,7 +341,7 @@ void DataLayout::parseSpecifier(StringRe
}
break;
default:
- llvm_unreachable("Unknown specifier in datalayout string");
+ report_fatal_error("Unknown specifier in datalayout string");
break;
}
}
Added: llvm/trunk/test/Assembler/invalid-datalayout1.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-datalayout1.ll?rev=223898&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/invalid-datalayout1.ll (added)
+++ llvm/trunk/test/Assembler/invalid-datalayout1.ll Tue Dec 9 19:17:08 2014
@@ -0,0 +1,3 @@
+; RUN: not llvm-as < %s 2>&1 | FileCheck %s
+target datalayout = "^"
+; CHECK: Unknown specifier in datalayout string
Added: llvm/trunk/test/Assembler/invalid-datalayout2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-datalayout2.ll?rev=223898&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/invalid-datalayout2.ll (added)
+++ llvm/trunk/test/Assembler/invalid-datalayout2.ll Tue Dec 9 19:17:08 2014
@@ -0,0 +1,3 @@
+; RUN: not llvm-as < %s 2>&1 | FileCheck %s
+target datalayout = "m:v"
+; CHECK: Unknown mangling in datalayout string
Added: llvm/trunk/test/Assembler/invalid-datalayout3.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-datalayout3.ll?rev=223898&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/invalid-datalayout3.ll (added)
+++ llvm/trunk/test/Assembler/invalid-datalayout3.ll Tue Dec 9 19:17:08 2014
@@ -0,0 +1,3 @@
+; RUN: not llvm-as < %s 2>&1 | FileCheck %s
+target datalayout = "n0"
+; CHECK: Zero width native integer type in datalayout string
Added: llvm/trunk/test/Assembler/invalid-datalayout4.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-datalayout4.ll?rev=223898&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/invalid-datalayout4.ll (added)
+++ llvm/trunk/test/Assembler/invalid-datalayout4.ll Tue Dec 9 19:17:08 2014
@@ -0,0 +1,3 @@
+; RUN: not llvm-as < %s 2>&1 | FileCheck %s
+target datalayout = "p16777216:64:64:64"
+; CHECK: Invalid address space, must be a 24bit integer
Added: llvm/trunk/test/Assembler/invalid-datalayout5.bc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-datalayout5.bc?rev=223898&view=auto
==============================================================================
Binary files llvm/trunk/test/Assembler/invalid-datalayout5.bc (added) and llvm/trunk/test/Assembler/invalid-datalayout5.bc Tue Dec 9 19:17:08 2014 differ
Added: llvm/trunk/test/Assembler/invalid-datalayout5.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-datalayout5.ll?rev=223898&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/invalid-datalayout5.ll (added)
+++ llvm/trunk/test/Assembler/invalid-datalayout5.ll Tue Dec 9 19:17:08 2014
@@ -0,0 +1,3 @@
+; RUN: not llvm-as < %s 2>&1 | FileCheck %s
+target datalayout = "a1:64"
+; CHECK: Sized aggregate specification in datalayout string
More information about the llvm-commits
mailing list