[flang-commits] [flang] d4a1db4 - [flang][msvc] Workaround 'forgotten' symbols in FoldOperation. NFC.

Michael Kruse via flang-commits flang-commits at lists.llvm.org
Wed Sep 30 19:28:42 PDT 2020


Author: Michael Kruse
Date: 2020-09-30T21:28:34-05:00
New Revision: d4a1db4f3fd7ce701454127465dd0ddbdb7face2

URL: https://github.com/llvm/llvm-project/commit/d4a1db4f3fd7ce701454127465dd0ddbdb7face2
DIFF: https://github.com/llvm/llvm-project/commit/d4a1db4f3fd7ce701454127465dd0ddbdb7face2.diff

LOG: [flang][msvc] Workaround 'forgotten' symbols in FoldOperation. NFC.

This resolves an issue where the Microsoft compiler 'forgets' symbols when using constexpr in a lambda in a templated function. The symbols are:

1. The implicit lambda captures `context` and `convert`. Fix by making them explicit captures. The error message was:
```
fold-implementation.h(1220): error C2065: 'convert': undeclared identifier
```

2. The function template argument FROMCAT. Fix by storing it in a temporary constexpr variable inside the function. The error message was:
```
fold-implementation.h(1216): error C2065: 'FROMCAT': undeclared identifier
```

This patch is part of the series to make flang compilable with MS Visual Studio <http://lists.llvm.org/pipermail/flang-dev/2020-July/000448.html>.

Reviewed By: klausler

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

Added: 
    

Modified: 
    flang/lib/Evaluate/fold-implementation.h

Removed: 
    


################################################################################
diff  --git a/flang/lib/Evaluate/fold-implementation.h b/flang/lib/Evaluate/fold-implementation.h
index bb5463e697fe..8178b277d13b 100644
--- a/flang/lib/Evaluate/fold-implementation.h
+++ b/flang/lib/Evaluate/fold-implementation.h
@@ -1155,8 +1155,11 @@ Expr<TO> FoldOperation(
     return *array;
   }
   return std::visit(
-      [&](auto &kindExpr) -> Expr<TO> {
+      [&context, &convert](auto &kindExpr) -> Expr<TO> {
         using Operand = ResultType<decltype(kindExpr)>;
+        // This variable is a workaround for msvc which emits an error when
+        // using the FROMCAT template parameter below.
+        TypeCategory constexpr FromCat{FROMCAT};
         char buffer[64];
         if (auto value{GetScalarConstantValue<Operand>(kindExpr)}) {
           if constexpr (TO::category == TypeCategory::Integer) {
@@ -1213,7 +1216,7 @@ Expr<TO> FoldOperation(
             return Expr<TO>{value->IsTrue()};
           }
         } else if constexpr (std::is_same_v<Operand, TO> &&
-            FROMCAT != TypeCategory::Character) {
+            FromCat != TypeCategory::Character) {
           return std::move(kindExpr); // remove needless conversion
         }
         return Expr<TO>{std::move(convert)};


        


More information about the flang-commits mailing list