Skip to content

Commit 61a2a11

Browse files
[AST] Handle consumed parameters correctly in ClangTypeConverter.
See also: #28527.
1 parent eabe7bc commit 61a2a11

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/AST/ClangTypeConverter.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,25 @@ const clang::Type *ClangTypeConverter::getFunctionType(
122122
if (resultClangTy.isNull())
123123
return nullptr;
124124

125-
SmallVector<clang::QualType, 8> paramsClangTy;
125+
SmallVector<clang::FunctionProtoType::ExtParameterInfo, 4> extParamInfos;
126+
SmallVector<clang::QualType, 4> paramsClangTy;
127+
bool someParamIsConsumed = false;
126128
for (auto p : params) {
127129
auto pc = convert(p.getPlainType());
128130
if (pc.isNull())
129131
return nullptr;
132+
clang::FunctionProtoType::ExtParameterInfo extParamInfo;
133+
if (p.getParameterFlags().isOwned()) {
134+
someParamIsConsumed = true;
135+
extParamInfo = extParamInfo.withIsConsumed(true);
136+
}
137+
extParamInfos.push_back(extParamInfo);
130138
paramsClangTy.push_back(pc);
131139
}
132140

133141
clang::FunctionProtoType::ExtProtoInfo info(clang::CallingConv::CC_C);
142+
if (someParamIsConsumed)
143+
info.ExtParameterInfos = extParamInfos.begin();
134144
auto fn = ClangASTContext.getFunctionType(resultClangTy, paramsClangTy, info);
135145
if (fn.isNull())
136146
return nullptr;

0 commit comments

Comments
 (0)