[MLIR][NFC] Inline lambda to workaround gcc 9.1,9.2 bug
authorKiran Chandramohan <kiran.chandramohan@arm.com>
Tue, 16 Jun 2020 14:26:25 +0000 (15:26 +0100)
committerKiran Chandramohan <kiran.chandramohan@arm.com>
Tue, 16 Jun 2020 14:31:06 +0000 (15:31 +0100)
gcc 9.1/9.2 has a bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90538)
which leads to an incorrect error when expanding parameter packs multiple
times in a lambda. Inlining this lambda to work around this issue.

Reviewed By: rriddle, CarolineConcatto

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

mlir/lib/IR/AsmPrinter.cpp

index 111ab4d..0636ab5 100644 (file)
@@ -1547,24 +1547,30 @@ void ModulePrinter::printDenseIntOrFPElementsAttr(DenseIntOrFPElementsAttr attr,
   }
 
   if (ComplexType complexTy = elementType.dyn_cast<ComplexType>()) {
-    auto printComplexValue = [&](auto complexValues, auto printFn,
-                                 raw_ostream &os, auto &&... params) {
+    Type complexElementType = complexTy.getElementType();
+    // Note: The if and else below had a common lambda function which invoked
+    // printDenseElementsAttrImpl. This lambda was hitting a bug in gcc 9.1,9.2
+    // and hence was replaced.
+    if (complexElementType.isa<IntegerType>()) {
+      bool isSigned = !complexElementType.isUnsignedInteger();
       printDenseElementsAttrImpl(attr.isSplat(), type, os, [&](unsigned index) {
-        auto complexValue = *(complexValues.begin() + index);
+        auto complexValue = *(attr.getComplexIntValues().begin() + index);
         os << "(";
-        printFn(complexValue.real(), os, params...);
+        printDenseIntElement(complexValue.real(), os, isSigned);
         os << ",";
-        printFn(complexValue.imag(), os, params...);
+        printDenseIntElement(complexValue.imag(), os, isSigned);
         os << ")";
       });
-    };
-
-    Type complexElementType = complexTy.getElementType();
-    if (complexElementType.isa<IntegerType>())
-      printComplexValue(attr.getComplexIntValues(), printDenseIntElement, os,
-                        /*isSigned=*/!complexElementType.isUnsignedInteger());
-    else
-      printComplexValue(attr.getComplexFloatValues(), printFloatValue, os);
+    } else {
+      printDenseElementsAttrImpl(attr.isSplat(), type, os, [&](unsigned index) {
+        auto complexValue = *(attr.getComplexFloatValues().begin() + index);
+        os << "(";
+        printFloatValue(complexValue.real(), os);
+        os << ",";
+        printFloatValue(complexValue.imag(), os);
+        os << ")";
+      });
+    }
   } else if (elementType.isIntOrIndex()) {
     bool isSigned = !elementType.isUnsignedInteger();
     auto intValues = attr.getIntValues();