<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - defvar and foreach not accepted in all record bodies"
   href="https://bugs.llvm.org/show_bug.cgi?id=52180">52180</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>defvar and foreach not accepted in all record bodies
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>tools
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>TableGen
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>joseph.nash@amd.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The text of <a href="https://llvm.org/docs/TableGen/ProgRef.html">https://llvm.org/docs/TableGen/ProgRef.html</a> suggests the defvar and
foreach constructs should be valid in all record bodies. Running the example
below shows that isn't true. If you ignore the text, and only look at the
grammar on the TableGen manual, there is still a mismatch. defvar should be
valid in a class definition. foreach text also says it is valid in a record
body, but that isn't present in the grammar. 
It would be great if both these constructs were always available, but at least
the intended and actual behavior should be documented.

Related:
<a href="https://reviews.llvm.org/D85838/new/#inline-1064437">https://reviews.llvm.org/D85838/new/#inline-1064437</a>
Perhaps in the doc upgrade some info was lost?


reproducer.td

// global scope
// foreach and defvar ok
defvar x = "str";
foreach i = 1...5 in {
}

// record def
// foreach broken
// defvar ok
def test {
  // error: Unknown token when expecting a type
  /*foreach i = 1..5 in {*/
  /*}*/
}
def test2 {
  defvar k = "str";
}

// class definition
// foreach and defvar broken
class T1<int K> {
  // error: Unknown token when expecting a type
  /*foreach i = 1...5 in {*/
  /*}*/
  // error: Variable not defined: 'K'
  /*defvar Q = K;*/
}
def myT1 : T1<1>;


// multiclass definition
// defvar ok at entry and within multidefs
// foreach ok at entry and broken within multidefs
multiclass T3<int K> {
  foreach i = 1...5 in {
  }
  defvar Q = K;

  def name1 {
    // error: Unknown token when expecting a type
    /*foreach i = 1...5 in {*/
    /*}*/
    defvar L = K;
  }
}
defm myT3 : T3<1>;</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>