Skip to content

[interop] do not traverse type locs when IRGening clang decls from Swift #64368

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
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/IRGen/GenClangDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ class ClangDeclFinder
return true;
}

// Do not traverse type locs, as they might contain expressions that reference
// code that should not be instantiated and/or emitted.
bool TraverseTypeLoc(clang::TypeLoc TL) { return true; }

bool shouldVisitTemplateInstantiations() const { return true; }
bool shouldVisitImplicitCode() const { return true; }
};
Expand Down
23 changes: 23 additions & 0 deletions test/Interop/Cxx/templates/Inputs/unevaluated-context.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,27 @@ inline void initVector() {
vv.push_back(0);
}

template <class T>
class UseDeclVal {
public:
UseDeclVal() {}

auto declTypeRet() const noexcept -> decltype(declval<T>().method()) {
return T().method();
}

inline int callMethod() const {
int x = declTypeRet();
return x;
}
};

struct StructWithMethod {
inline int method() {
return 42;
}
};

using UseDeclValStruct = UseDeclVal<StructWithMethod>;

#endif // TEST_INTEROP_CXX_TEMPLATES_INPUTS_UNEVALUATED_CONTEXT_H
1 change: 1 addition & 0 deletions test/Interop/Cxx/templates/unevaluated-context.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var UnevaluatedTestSuite = TestSuite("UnevaluatedContext")

UnevaluatedTestSuite.test("declval") {
initVector()
let _ = UseDeclValStruct().callMethod()
}

runAllTests()