Skip to content

Commit 0974fca

Browse files
committed
[cxx-interop] Do not emit IR for C++20 requires expr
This fixes a compiler crash when emitting IR for a for-in loop over a C++ `std::vector` in C++20 mode. rdar://108810356
1 parent 9a57840 commit 0974fca

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

lib/IRGen/GenClangDecl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ class ClangDeclFinder
119119
return true;
120120
}
121121

122+
bool TraverseRequiresExpr(clang::RequiresExpr *RE) { return true; }
123+
122124
// Do not traverse type locs, as they might contain expressions that reference
123125
// code that should not be instantiated and/or emitted.
124126
bool TraverseTypeLoc(clang::TypeLoc TL) { return true; }
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
inline void calledFromConceptBody(int x) {}
2+
inline void calledFromMethodBody(int x) {}
3+
4+
struct MyStruct {
5+
template <typename T>
6+
void foo(T x)
7+
requires requires(const T x) { calledFromConceptBody(x); }
8+
{
9+
calledFromMethodBody(x);
10+
}
11+
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module MethodRequires {
2+
header "method-requires.h"
3+
export *
4+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %target-swiftxx-frontend -emit-ir -Xcc -std=c++20 -I %S/Inputs %s | %FileCheck %s
2+
3+
import MethodRequires
4+
5+
var s = MyStruct()
6+
s.foo(123)
7+
// CHECK-NOT: calledFromConceptBody
8+
// CHECK: calledFromMethodBody

test/Interop/Cxx/stdlib/use-std-vector.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-experimental-cxx-interop)
2-
// FIXME: also test this in C++20 mode once rdar://108810356 is fixed.
2+
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-experimental-cxx-interop -Xcc -std=c++20)
33
//
44
// REQUIRES: executable_test
55
//

0 commit comments

Comments
 (0)