<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/107872>107872</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            clang-format incorrectly formats TableGen
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang-format
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          tim-hoffman
      </td>
    </tr>
</table>

<pre>
    #### Input file
```
#ifndef DEMO_OPS
#define DEMO_OPS

include "mlir/Interfaces/InferTypeOpInterface.td"
include "mlir/Interfaces/SideEffectInterfaces.td"
include "mlir/IR/OpAsmInterface.td"
include "mlir/IR/OpBase.td"
include "mlir/IR/RegionKindInterface.td"
include "mlir/IR/SymbolInterfaces.td"

include "Dialect/DEMO/IR/Dialect.td"
include "Dialect/DEMO/IR/Attrs.td"
include "Dialect/DEMO/IR/Types.td"

class DEMO_Op<string mnemonic, list<Trait> traits = []>
    : Op<DEMODialect, mnemonic, traits>;

//===----------------------------------------------------------------------===//
// Basic constructs
//===----------------------------------------------------------------------===//

def DEMO_StructDefOp : DEMO_Op<"struct", [
 HasParent<"mlir::ModuleOp">,
  Symbol,
  SymbolTable,
 IsolatedFromAbove,
  GraphRegionNoTerminator,
]> {
  let summary = "";
  let description = [{}];

  let arguments = (ins
 SymbolNameAttr:$sym_name,
 OptionalAttr<FlatSymbolRefArrayAttr>:$const_params
  );

  let regions = (region SizedRegion<1> : $body);

  let assemblyFormat = [{
    $sym_name (`<` $const_params^ `>`)? $body attr-dict
 }];

  let hasRegionVerifier = 1;
}

def DEMO_FieldOp : DEMO_Op<"field", [HasParent<"StructDefOp">, Symbol]> {
  let summary = "";
  let description = [{}];

  let arguments = (ins
 SymbolNameAttr:$sym_name,
 OptionalAttr<TypedArrayAttrBase<DEMO_TypeModiferAttr, "type modifiers">>:$modifiers,
      TypeAttrOf<AnyDEMOType>:$type
 );

  let assemblyFormat = [{
    $sym_name `:` ($modifiers^)? $type attr-dict
 }];
}

//===----------------------------------------------------------------------===//
// Field element operators
//===----------------------------------------------------------------------===//

class DEMO_BinaryFeltOp<string mnemonic, list<Trait> traits = []>
    : DEMO_Op<mnemonic,
              !listconcat(traits, [SameOperandsAndResultType, Pure, NoMemoryEffect])> {

  let arguments = (ins DEMO_FeltType:$lhs, DEMO_FeltType:$rhs);
  let results = (outs DEMO_FeltType:$result);
  let assemblyFormat = "$lhs `,` $rhs attr-dict";
}

#endif // DEMO_OPS
```

#### `.clang-format` file:
```
---
# Formatter for .td files
Language: TableGen
BasedOnStyle: LLVM
IndentWidth: 2
---
# Formatter for .h, .cpp, etc.
Language: Cpp
BasedOnStyle: LLVM
IndentWidth: 2
```

#### Command:
`clang-format -i include/Dialect/DEMO/IR/Ops.td`

#### Result after formatting:
```
#ifndef DEMO_OPS
#define DEMO_OPS

include "mlir/Interfaces/InferTypeOpInterface.td"
include "mlir/Interfaces/SideEffectInterfaces.td"
include "mlir/IR/OpAsmInterface.td"
include "mlir/IR/OpBase.td"
include "mlir/IR/RegionKindInterface.td"
include "mlir/IR/SymbolInterfaces.td"

include "Dialect/DEMO/IR/Dialect.td"
include "Dialect/DEMO/IR/Attrs.td"
include "Dialect/DEMO/IR/Types.td"

class DEMO_Op<string mnemonic, list<Trait> traits = []>
    : Op<DEMODialect, mnemonic, traits>;

//===----------------------------------------------------------------------===//
// Basic constructs
//===----------------------------------------------------------------------===//

def DEMO_StructDefOp : DEMO_Op<"struct", [
 HasParent<"mlir::ModuleOp">,
  Symbol,
  SymbolTable,
 IsolatedFromAbove,
  GraphRegionNoTerminator,
]> {
  let summary = "";
  let description = [{}];

  let arguments = (ins
 SymbolNameAttr:$sym_name,
 OptionalAttr<FlatSymbolRefArrayAttr>:$const_params
  );

  let regions = (region SizedRegion<1> : $body);

  let assemblyFormat = [{
    $sym_name (`<` $const_params^ `>`)? $body attr-dict
 }];

  let hasRegionVerifier = 1;
}

def DEMO_FieldOp : DEMO_Op<"field", [HasParent<"StructDefOp">, Symbol]> {
  let summary = "";
  let description = [{}];

  let arguments = (ins
 SymbolNameAttr:$sym_name,
 OptionalAttr<TypedArrayAttrBase<DEMO_TypeModiferAttr, "type modifiers">>:$modifiers,
      TypeAttrOf<AnyDEMOType>:$type
 );

  let assemblyFormat = [{
    $sym_name `:` ($modifiers^)? $type attr-dict
 }];
}

//===----------------------------------------------------------------------===//
// Field element operators
//===---------------------------------------------------------------- -- -- -- ==
      = //

      class DEMO_BinaryFeltOp<string mnemonic, list<Trait> traits = []>
      : DEMO_Op<mnemonic, !listconcat(traits, [
                  SameOperandsAndResultType, Pure, NoMemoryEffect
                ])> {

    let arguments = (ins DEMO_FeltType : $lhs, DEMO_FeltType : $rhs);
    let results = (outs DEMO_FeltType : $result);
    let assemblyFormat = "$lhs `,` $rhs attr-dict";
  }

#endif // DEMO_OPS
```

#### Problem:
The comment block with "Field element operators" is reflowed improperly and the class declaration after it is formatted incorrectly.

#### Other attempts that did NOT resolve the issue:
1. Adding "ReflowComments: false" in the TableGen section of the `.clang-format` file
2. Adding "// clang-format off" and "// clang-format on" around the block comment. Resulted in:
```
// clang-format off
//===----------------------------------------------------------------------===//
// Field element operators
//===-------------------------------------------- -- -- -- -- -- -- -- -- -- -- -- -- -- ==
      = //
      // clang-format on

      class DEMO_BinaryFeltOp<string mnemonic, list<Trait> traits = []>
      : DEMO_Op<mnemonic, !listconcat(traits, [
                  SameOperandsAndResultType, Pure, NoMemoryEffect
 ])> {

    let arguments = (ins DEMO_FeltType : $lhs, DEMO_FeltType : $rhs);
    let results = (outs DEMO_FeltType : $result);
    let assemblyFormat = "$lhs `,` $rhs attr-dict";
 }

#endif // DEMO_OPS

```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWV1z4rwV_jXiRhMGZAhwwQXhY5vpJmSSzPYyI6xjUKsPjyRnh_76jiTbGGKSdCfdtu-LxwOLpPOhc55zpCdLreVbBTBFwxs0XHRo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