@@ -1164,23 +1164,22 @@ void swift::conformToCxxSpanIfNeeded(ClangImporter::Implementation &impl,
1164
1164
if (!elementType || !sizeType)
1165
1165
return ;
1166
1166
1167
- auto constPointerTypeDecl =
1168
- lookupNestedClangTypeDecl (clangDecl, " const_pointer" );
1167
+ auto pointerTypeDecl = lookupNestedClangTypeDecl (clangDecl, " pointer" );
1169
1168
auto countTypeDecl = lookupNestedClangTypeDecl (clangDecl, " size_type" );
1170
1169
1171
- if (!constPointerTypeDecl || !countTypeDecl)
1170
+ if (!pointerTypeDecl || !countTypeDecl)
1172
1171
return ;
1173
1172
1174
- // create fake variable for constPointer (constructor arg 1)
1175
- auto constPointerType = clangCtx.getTypeDeclType (constPointerTypeDecl );
1176
- auto fakeConstPointerVarDecl = clang::VarDecl::Create (
1173
+ // create fake variable for pointer (constructor arg 1)
1174
+ clang::QualType pointerType = clangCtx.getTypeDeclType (pointerTypeDecl );
1175
+ auto fakePointerVarDecl = clang::VarDecl::Create (
1177
1176
clangCtx, /* DC*/ clangCtx.getTranslationUnitDecl (),
1178
1177
clang::SourceLocation (), clang::SourceLocation (), /* Id*/ nullptr ,
1179
- constPointerType , clangCtx.getTrivialTypeSourceInfo (constPointerType ),
1178
+ pointerType , clangCtx.getTrivialTypeSourceInfo (pointerType ),
1180
1179
clang::StorageClass::SC_None);
1181
1180
1182
- auto fakeConstPointer = new (clangCtx) clang::DeclRefExpr (
1183
- clangCtx, fakeConstPointerVarDecl , false , constPointerType ,
1181
+ auto fakePointer = new (clangCtx) clang::DeclRefExpr (
1182
+ clangCtx, fakePointerVarDecl , false , pointerType ,
1184
1183
clang::ExprValueKind::VK_LValue, clang::SourceLocation ());
1185
1184
1186
1185
// create fake variable for count (constructor arg 2)
@@ -1197,8 +1196,7 @@ void swift::conformToCxxSpanIfNeeded(ClangImporter::Implementation &impl,
1197
1196
1198
1197
// Use clangSema.BuildCxxTypeConstructExpr to create a CXXTypeConstructExpr,
1199
1198
// passing constPointer and count
1200
- SmallVector<clang::Expr *, 2 > constructExprArgs = {fakeConstPointer,
1201
- fakeCount};
1199
+ SmallVector<clang::Expr *, 2 > constructExprArgs = {fakePointer, fakeCount};
1202
1200
1203
1201
auto clangDeclTyInfo = clangCtx.getTrivialTypeSourceInfo (
1204
1202
clang::QualType (clangDecl->getTypeForDecl (), 0 ));
@@ -1226,5 +1224,10 @@ void swift::conformToCxxSpanIfNeeded(ClangImporter::Implementation &impl,
1226
1224
elementType->getUnderlyingType ());
1227
1225
impl.addSynthesizedTypealias (decl, ctx.getIdentifier (" Size" ),
1228
1226
sizeType->getUnderlyingType ());
1229
- impl.addSynthesizedProtocolAttrs (decl, {KnownProtocolKind::CxxSpan});
1227
+
1228
+ if (pointerType->getPointeeType ().isConstQualified ()) {
1229
+ impl.addSynthesizedProtocolAttrs (decl, {KnownProtocolKind::CxxSpan});
1230
+ } else {
1231
+ impl.addSynthesizedProtocolAttrs (decl, {KnownProtocolKind::CxxMutableSpan});
1232
+ }
1230
1233
}
0 commit comments