From bf13927f3b62e4e3951670775a28fd2fa154d911 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Wed, 10 Dec 2014 01:38:28 +0000 Subject: [PATCH] DataLayout: Be more verbose when diagnosing problems in pointer specs git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223903 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/DataLayout.cpp | 13 ++++++++++--- test/Assembler/invalid-datalayout6.ll | 3 +++ test/Assembler/invalid-datalayout7.ll | 3 +++ test/Assembler/invalid-datalayout8.ll | 3 +++ test/Assembler/invalid-datalayout9.ll | 3 +++ 5 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 test/Assembler/invalid-datalayout6.ll create mode 100644 test/Assembler/invalid-datalayout7.ll create mode 100644 test/Assembler/invalid-datalayout8.ll create mode 100644 test/Assembler/invalid-datalayout9.ll diff --git a/lib/IR/DataLayout.cpp b/lib/IR/DataLayout.cpp index 394986e092d..4e0c066b1c8 100644 --- a/lib/IR/DataLayout.cpp +++ b/lib/IR/DataLayout.cpp @@ -197,8 +197,8 @@ void DataLayout::reset(StringRef Desc) { static std::pair split(StringRef Str, char Separator) { assert(!Str.empty() && "parse error, string can't be empty here"); std::pair Split = Str.split(Separator); - assert((!Split.second.empty() || Split.first == Str) && - "a trailing separator is not allowed"); + if (Split.second.empty() && Split.first != Str) + report_fatal_error("Trailing separator in datalayout string"); return Split; } @@ -213,7 +213,8 @@ static unsigned getInt(StringRef R) { /// Convert bits into bytes. Assert if not a byte width multiple. static unsigned inBytes(unsigned Bits) { - assert(Bits % 8 == 0 && "number of bits must be a byte width multiple"); + if (Bits % 8) + report_fatal_error("number of bits must be a byte width multiple"); return Bits / 8; } @@ -251,10 +252,16 @@ void DataLayout::parseSpecifier(StringRef Desc) { report_fatal_error("Invalid address space, must be a 24bit integer"); // Size. + if (Rest.empty()) + report_fatal_error( + "Missing size specification for pointer in datalayout string"); Split = split(Rest, ':'); unsigned PointerMemSize = inBytes(getInt(Tok)); // ABI alignment. + if (Rest.empty()) + report_fatal_error( + "Missing alignment specification for pointer in datalayout string"); Split = split(Rest, ':'); unsigned PointerABIAlign = inBytes(getInt(Tok)); diff --git a/test/Assembler/invalid-datalayout6.ll b/test/Assembler/invalid-datalayout6.ll new file mode 100644 index 00000000000..425099f7cad --- /dev/null +++ b/test/Assembler/invalid-datalayout6.ll @@ -0,0 +1,3 @@ +; RUN: not llvm-as < %s 2>&1 | FileCheck %s +target datalayout = "a:" +; CHECK: Trailing separator in datalayout string diff --git a/test/Assembler/invalid-datalayout7.ll b/test/Assembler/invalid-datalayout7.ll new file mode 100644 index 00000000000..097227ae6ae --- /dev/null +++ b/test/Assembler/invalid-datalayout7.ll @@ -0,0 +1,3 @@ +; RUN: not llvm-as < %s 2>&1 | FileCheck %s +target datalayout = "p:52" +; CHECK: number of bits must be a byte width multiple diff --git a/test/Assembler/invalid-datalayout8.ll b/test/Assembler/invalid-datalayout8.ll new file mode 100644 index 00000000000..28832ffb17d --- /dev/null +++ b/test/Assembler/invalid-datalayout8.ll @@ -0,0 +1,3 @@ +; RUN: not llvm-as < %s 2>&1 | FileCheck %s +target datalayout = "e-p" +; CHECK: Missing size specification for pointer in datalayout string diff --git a/test/Assembler/invalid-datalayout9.ll b/test/Assembler/invalid-datalayout9.ll new file mode 100644 index 00000000000..dfeac65cf60 --- /dev/null +++ b/test/Assembler/invalid-datalayout9.ll @@ -0,0 +1,3 @@ +; RUN: not llvm-as < %s 2>&1 | FileCheck %s +target datalayout = "e-p:64" +; CHECK: Missing alignment specification for pointer in datalayout string