Skip to content

Commit

Permalink
[TableGen] Don't quote variable name when printing !foreach.
Browse files Browse the repository at this point in the history
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

llvm-svn: 331351
  • Loading branch information
statham-arm committed May 2, 2018
1 parent e222d92 commit 6a02604
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 5 additions & 3 deletions llvm/lib/TableGen/Record.cpp
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions llvm/test/TableGen/foreach-leak.td
@@ -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 {
Expand Down

0 comments on commit 6a02604

Please sign in to comment.