Skip to content

[mlir] Fix build after ec50f5828f25 #101021

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 12, 2024
Merged

Conversation

ryanpholt
Copy link
Contributor

This commit fixes what appears to be invalid C++ -- a lambda capturing a variable before it is declared. The code compiles with GCC and Clang but not MSVC.

This commit fixes what appears to be invalid C++ -- a lambda capturing a
variable before it is declared. The code compiles with GCC and Clang but
not MSVC.
@ryanpholt ryanpholt requested a review from zyx-billy July 29, 2024 14:37
@llvmbot llvmbot added the mlir label Jul 29, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 29, 2024

@llvm/pr-subscribers-mlir

Author: Ryan Holt (ryan-holt-1)

Changes

This commit fixes what appears to be invalid C++ -- a lambda capturing a variable before it is declared. The code compiles with GCC and Clang but not MSVC.


Full diff: https://github.com/llvm/llvm-project/pull/101021.diff

1 Files Affected:

  • (modified) mlir/unittests/Support/CyclicReplacerCacheTest.cpp (+5-4)
diff --git a/mlir/unittests/Support/CyclicReplacerCacheTest.cpp b/mlir/unittests/Support/CyclicReplacerCacheTest.cpp
index ca2eb6ce4171f..64a8ab72b69b7 100644
--- a/mlir/unittests/Support/CyclicReplacerCacheTest.cpp
+++ b/mlir/unittests/Support/CyclicReplacerCacheTest.cpp
@@ -26,14 +26,15 @@ TEST(CachedCyclicReplacerTest, testNoRecursion) {
 
 TEST(CachedCyclicReplacerTest, testInPlaceRecursionPruneAnywhere) {
   // Replacer cycles through ints 0 -> 1 -> 2 -> 0 -> ...
-  CachedCyclicReplacer<int, int> replacer(
-      /*replacer=*/[&](int n) { return replacer((n + 1) % 3); },
+  std::optional<CachedCyclicReplacer<int, int>> replacer;
+  replacer.emplace(
+      /*replacer=*/[&](int n) { return (*replacer)((n + 1) % 3); },
       /*cycleBreaker=*/[&](int n) { return -1; });
 
   // Starting at 0.
-  EXPECT_EQ(replacer(0), -1);
+  EXPECT_EQ((*replacer)(0), -1);
   // Starting at 2.
-  EXPECT_EQ(replacer(2), -1);
+  EXPECT_EQ((*replacer)(2), -1);
 }
 
 //===----------------------------------------------------------------------===//

@ryanpholt
Copy link
Contributor Author

You can see the issue on Compiler Explorer here: https://godbolt.org/z/Ms4W3Es6z

@Meinersbur
Copy link
Member

I think I found a simpler workaround: #102627

@ryanpholt ryanpholt requested a review from Meinersbur August 9, 2024 17:19
Copy link
Member

@Meinersbur Meinersbur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ryanpholt ryanpholt merged commit 80ff391 into llvm:main Aug 12, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants