Skip to content

Commit 490c73c

Browse files
authored
Merge pull request #64368 from hyp/eng/irgen-type-loc-nomore
[interop] do not traverse type locs when IRGening clang decls from Swift
2 parents af1e0f7 + 8d7799a commit 490c73c

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

lib/IRGen/GenClangDecl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ class ClangDeclFinder
112112
return true;
113113
}
114114

115+
// Do not traverse type locs, as they might contain expressions that reference
116+
// code that should not be instantiated and/or emitted.
117+
bool TraverseTypeLoc(clang::TypeLoc TL) { return true; }
118+
115119
bool shouldVisitTemplateInstantiations() const { return true; }
116120
bool shouldVisitImplicitCode() const { return true; }
117121
};

test/Interop/Cxx/templates/Inputs/unevaluated-context.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,27 @@ inline void initVector() {
3535
vv.push_back(0);
3636
}
3737

38+
template <class T>
39+
class UseDeclVal {
40+
public:
41+
UseDeclVal() {}
42+
43+
auto declTypeRet() const noexcept -> decltype(declval<T>().method()) {
44+
return T().method();
45+
}
46+
47+
inline int callMethod() const {
48+
int x = declTypeRet();
49+
return x;
50+
}
51+
};
52+
53+
struct StructWithMethod {
54+
inline int method() {
55+
return 42;
56+
}
57+
};
58+
59+
using UseDeclValStruct = UseDeclVal<StructWithMethod>;
60+
3861
#endif // TEST_INTEROP_CXX_TEMPLATES_INPUTS_UNEVALUATED_CONTEXT_H

test/Interop/Cxx/templates/unevaluated-context.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var UnevaluatedTestSuite = TestSuite("UnevaluatedContext")
99

1010
UnevaluatedTestSuite.test("declval") {
1111
initVector()
12+
let _ = UseDeclValStruct().callMethod()
1213
}
1314

1415
runAllTests()

0 commit comments

Comments
 (0)