OSDN Git Service

[TableGen] Don't quote variable name when printing !foreach.
authorSimon Tatham <simon.tatham@arm.com>
Wed, 2 May 2018 13:17:26 +0000 (13:17 +0000)
committerSimon Tatham <simon.tatham@arm.com>
Wed, 2 May 2018 13:17:26 +0000 (13:17 +0000)
An input !foreach expression such as !foreach(a, lst, !add(a, 1))
would be re-emitted by llvm-tblgen -print-records with the first
argument in quotes, giving !foreach("a", lst, !add(a, 1)), which isn't
valid TableGen input syntax.

Reviewers: nhaehnle

Reviewed By: nhaehnle

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D46352

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

lib/TableGen/Record.cpp
test/TableGen/foreach-leak.td

index e81a6f2..4f1ca04 100644 (file)
@@ -1196,14 +1196,16 @@ Init *TernOpInit::resolveReferences(Resolver &R) const {
 
 std::string TernOpInit::getAsString() const {
   std::string Result;
+  bool UnquotedLHS = false;
   switch (getOpcode()) {
   case SUBST: Result = "!subst"; break;
-  case FOREACH: Result = "!foreach"; break;
+  case FOREACH: Result = "!foreach"; UnquotedLHS = true; break;
   case IF: Result = "!if"; break;
   case DAG: Result = "!dag"; break;
   }
-  return Result + "(" + LHS->getAsString() + ", " + MHS->getAsString() + ", " +
-         RHS->getAsString() + ")";
+  return (Result + "(" +
+          (UnquotedLHS ? LHS->getAsUnquotedString() : LHS->getAsString()) +
+          ", " + MHS->getAsString() + ", " + RHS->getAsString() + ")");
 }
 
 static void ProfileFoldOpInit(FoldingSetNodeID &ID, Init *A, Init *B,
index 68867e1..cc8ca89 100644 (file)
@@ -1,6 +1,9 @@
 // RUN: llvm-tblgen %s | FileCheck %s
 // XFAIL: vg_leak
 
+// CHECK: --- Classes ---
+// CHECK: list<int> ret = !foreach(a,
+
 // CHECK: --- Defs ---
 
 // CHECK: def C0 {