[llvm] r223911 - DataLayout: Provide nicer diagnostics for malformed strings

David Majnemer david.majnemer at gmail.com
Tue Dec 9 18:36:41 PST 2014


Author: majnemer
Date: Tue Dec  9 20:36:41 2014
New Revision: 223911

URL: http://llvm.org/viewvc/llvm-project?rev=223911&view=rev
Log:
DataLayout: Provide nicer diagnostics for malformed strings

Added:
    llvm/trunk/test/Assembler/invalid-datalayout10.ll
    llvm/trunk/test/Assembler/invalid-datalayout11.ll
    llvm/trunk/test/Assembler/invalid-datalayout12.ll
    llvm/trunk/test/Assembler/invalid-datalayout13.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=223911&r1=223910&r2=223911&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DataLayout.cpp (original)
+++ llvm/trunk/lib/IR/DataLayout.cpp Tue Dec  9 20:36:41 2014
@@ -199,6 +199,8 @@ static std::pair<StringRef, StringRef> s
   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(StringRe
             "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(StringRe
       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");

Added: llvm/trunk/test/Assembler/invalid-datalayout10.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-datalayout10.ll?rev=223911&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/invalid-datalayout10.ll (added)
+++ llvm/trunk/test/Assembler/invalid-datalayout10.ll Tue Dec  9 20:36:41 2014
@@ -0,0 +1,3 @@
+; RUN: not llvm-as < %s 2>&1 | FileCheck %s
+target datalayout = "m"
+; CHECK: Expected mangling specifier in datalayout string

Added: llvm/trunk/test/Assembler/invalid-datalayout11.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-datalayout11.ll?rev=223911&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/invalid-datalayout11.ll (added)
+++ llvm/trunk/test/Assembler/invalid-datalayout11.ll Tue Dec  9 20:36:41 2014
@@ -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

Added: llvm/trunk/test/Assembler/invalid-datalayout12.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-datalayout12.ll?rev=223911&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/invalid-datalayout12.ll (added)
+++ llvm/trunk/test/Assembler/invalid-datalayout12.ll Tue Dec  9 20:36:41 2014
@@ -0,0 +1,3 @@
+; RUN: not llvm-as < %s 2>&1 | FileCheck %s
+target datalayout = "f"
+; CHECK: Missing alignment specification in datalayout string

Added: llvm/trunk/test/Assembler/invalid-datalayout13.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-datalayout13.ll?rev=223911&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/invalid-datalayout13.ll (added)
+++ llvm/trunk/test/Assembler/invalid-datalayout13.ll Tue Dec  9 20:36:41 2014
@@ -0,0 +1,3 @@
+; RUN: not llvm-as < %s 2>&1 | FileCheck %s
+target datalayout = ":32"
+; CHECK: Expected token before separator in datalayout string





More information about the llvm-commits mailing list