[PATCH] D95874: [TableGen] Temporary hack to add type checking for multiclass template arguments

Paul C. Anagnostopoulos via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 2 07:56:57 PST 2021


Paul-C-Anagnostopoulos created this revision.
Paul-C-Anagnostopoulos added reviewers: lattner, RKSimon, craig.topper, arsenm, t.p.northover, asb, sunfish.
Herald added subscribers: luismarques, pengfei, s.egerton, PkmX, simoncook, hiraditya, kristof.beyls, tpr, dschuff.
Paul-C-Anagnostopoulos requested review of this revision.
Herald added subscribers: llvm-commits, aheejin, wdng.
Herald added a project: LLVM.

Apply this patch to a throw-away branch to help you find and fix multiclass template arguments that are of the wrong type. Such arguments have been discovered in the AMDGPU, ARM, MSP430, RISCV, WebAssembly, and X86 targets. The problem may exist in others, also.

See this conversation: https://lists.llvm.org/pipermail/llvm-dev/2021-February/148261.html


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95874

Files:
  llvm/lib/TableGen/TGParser.cpp


Index: llvm/lib/TableGen/TGParser.cpp
===================================================================
--- llvm/lib/TableGen/TGParser.cpp
+++ llvm/lib/TableGen/TGParser.cpp
@@ -3509,7 +3509,20 @@
     SubstStack Substs;
     for (unsigned i = 0, e = TArgs.size(); i != e; ++i) {
       if (i < TemplateVals.size()) {
+        // This if block is a hack so we can track down multiclass template
+        // argument values of the wrong type.
+        if (TypedInit *ArgValue = dyn_cast<TypedInit>(TemplateVals[i])) {
+          auto *ArgType = MC->Rec.getValue(TArgs[i])->getType();
+          if (!ArgValue->getCastTo(ArgType))
+            return Error(SubClassLoc,
+                         "Value specified for template argument '" +
+                             TArgs[i]->getAsString() + "' (#" + Twine(i) +
+                             ") is of type " + ArgValue->getType()->getAsString() +
+                             "; expected type " + ArgType->getAsString() + ": " +
+                             ArgValue->getAsString());
+        }
         Substs.emplace_back(TArgs[i], TemplateVals[i]);
+
       } else {
         Init *Default = MC->Rec.getValue(TArgs[i])->getValue();
         if (!Default->isComplete()) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95874.320788.patch
Type: text/x-patch
Size: 1230 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210202/d4233a23/attachment.bin>


More information about the llvm-commits mailing list