Teach DataLayout that zero-byte pointer sizes don't make sense.
authorOwen Anderson <resistor@mac.com>
Mon, 2 Mar 2015 06:00:02 +0000 (06:00 +0000)
committerOwen Anderson <resistor@mac.com>
Mon, 2 Mar 2015 06:00:02 +0000 (06:00 +0000)
Previously this would result in assertion failures or simply crashes
at various points in the optimizer when trying to create types of zero
bit width.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@230936 91177308-0d34-0410-b5e6-96231b3b80d8

lib/IR/DataLayout.cpp
test/Assembler/invalid-datalayout19.ll [new file with mode: 0644]

index 9c1dee0cfb7ea6cf0b8e93a406d7d5f3c0804f0a..c414e80f4104dfc96d994d21bdeb2e6d5d71d32f 100644 (file)
@@ -259,6 +259,8 @@ void DataLayout::parseSpecifier(StringRef Desc) {
             "Missing size specification for pointer in datalayout string");
       Split = split(Rest, ':');
       unsigned PointerMemSize = inBytes(getInt(Tok));
+      if (!PointerMemSize)
+        report_fatal_error("Invalid pointer size of 0 bytes");
 
       // ABI alignment.
       if (Rest.empty())
diff --git a/test/Assembler/invalid-datalayout19.ll b/test/Assembler/invalid-datalayout19.ll
new file mode 100644 (file)
index 0000000..fc0fc46
--- /dev/null
@@ -0,0 +1,6 @@
+; RUN: not llvm-as < %s 2>&1 | FileCheck %s
+
+target datalayout = "p:0:32:32"
+
+; CHECK: Invalid pointer size of 0 bytes
+