From 99ad2a3b6752de11e17460055f02c0a52132eae1 Mon Sep 17 00:00:00 2001 From: Pete Cooper Date: Thu, 7 Aug 2014 05:46:57 +0000 Subject: [PATCH] TableGen: Change { } to only accept bits entries when n == 1. Prior to this change, it was legal to do something like bits<2> opc = { 0, 1 }; bits<2> opc2 = { 1, 0 }; bits<2> a = { opc, opc2 }; This involved silently dropping bits from opc and opc2 which is very hard to debug. Now the above test would be an error. Having tested with an assert, none of LLVM/clang was relying on this behaviour. Thanks to Adam Nemet for the above test. llvm-svn: 215083 --- llvm/lib/TableGen/Record.cpp | 5 ++++- llvm/test/TableGen/BitsInit.td | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 llvm/test/TableGen/BitsInit.td diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp index cf8ef9b..8267a36 100644 --- a/llvm/lib/TableGen/Record.cpp +++ b/llvm/lib/TableGen/Record.cpp @@ -114,8 +114,11 @@ Init *BitRecTy::convertValue(IntInit *II) { Init *BitRecTy::convertValue(TypedInit *VI) { RecTy *Ty = VI->getType(); - if (isa(Ty) || isa(Ty) || isa(Ty)) + if (isa(Ty)) return VI; // Accept variable if it is already of bit type! + if (auto *BitsTy = dyn_cast(Ty)) + // Accept only bits<1> expression. + return BitsTy->getNumBits() == 1 ? VI : nullptr; return nullptr; } diff --git a/llvm/test/TableGen/BitsInit.td b/llvm/test/TableGen/BitsInit.td new file mode 100644 index 0000000..28fd319 --- /dev/null +++ b/llvm/test/TableGen/BitsInit.td @@ -0,0 +1,22 @@ + +// RUN: not llvm-tblgen %s 2>&1 > %t +// RUN: FileCheck %s < %t + +def a { + bits<2> opc = { 0, 1 }; + bits<2> opc2 = { 1, 0 }; + bits<1> opc3 = { 1 }; + bits<2> a = { opc, opc2 }; // error! + bits<2> b = { opc{0}, opc2{0} }; + bits<2> c = { opc{1}, opc2{1} }; + bits<2> c = { opc3{0}, opc3 }; +} + +// CHECK: def a { +// CHECK: bits<2> opc = { 0, 1 }; +// CHECK: bits<2> opc2 = { 1, 0 }; +// CHECK: bits<1> opc3 = { 1 }; +// CHECK: bits<2> a = { ?, ? }; +// CHECK: bits<2> b = { 1, 0 }; +// CHECK: bits<2> c = { 1, 1 }; +// CHECK: } -- 2.7.4