@@ -8439,22 +8439,26 @@ ClangImporter::Implementation::importSwiftAttrAttributes(Decl *MappedDecl) {
8439
8439
}
8440
8440
8441
8441
namespace {
8442
- class PointerParamInfo {
8442
+ class PointerParamInfoPrinter {
8443
8443
public:
8444
- virtual void print (clang::ASTContext &ctx, llvm::raw_ostream &out) const = 0;
8445
- virtual ~PointerParamInfo () = default ;
8446
- };
8444
+ clang::ASTContext &ctx;
8445
+ llvm::raw_ostream &out;
8446
+ bool firstParam = true ;
8447
+ PointerParamInfoPrinter (clang::ASTContext &ctx, llvm::raw_ostream &out)
8448
+ : ctx(ctx), out(out) {
8449
+ out << " @PointerBounds(" ;
8450
+ }
8451
+ ~PointerParamInfoPrinter () { out << " )" ; }
8447
8452
8448
- class CountedByParam : public PointerParamInfo {
8449
- public:
8450
- size_t pointerIndex;
8451
- clang::Expr *countExpr;
8452
- bool isSizedBy;
8453
- CountedByParam (size_t idx, clang::Expr *E, bool sizedBy)
8454
- : pointerIndex(idx), countExpr(E), isSizedBy(sizedBy) {}
8455
-
8456
- virtual void print (clang::ASTContext &ctx,
8457
- llvm::raw_ostream &out) const override {
8453
+ void printCountedBy (const clang::CountAttributedType *CAT,
8454
+ size_t pointerIndex) {
8455
+ if (!firstParam) {
8456
+ out << " , " ;
8457
+ } else {
8458
+ firstParam = false ;
8459
+ }
8460
+ clang::Expr *countExpr = CAT->getCountExpr ();
8461
+ bool isSizedBy = CAT->isCountInBytes ();
8458
8462
out << " ." ;
8459
8463
if (isSizedBy)
8460
8464
out << " sizedBy" ;
@@ -8470,7 +8474,6 @@ class CountedByParam : public PointerParamInfo {
8470
8474
out, {}, {ctx.getLangOpts ()}); // TODO: map clang::Expr to Swift Expr
8471
8475
out << " \" )" ;
8472
8476
}
8473
- virtual ~CountedByParam () {}
8474
8477
};
8475
8478
} // namespace
8476
8479
@@ -8480,31 +8483,21 @@ void ClangImporter::Implementation::importBoundsAttributes(
8480
8483
dyn_cast_or_null<clang::FunctionDecl>(MappedDecl->getClangDecl ());
8481
8484
if (!ClangDecl)
8482
8485
return ;
8483
-
8484
- SmallVector<PointerParamInfo *, 4 > BoundsInfo;
8485
- size_t parameterIndex = 1 ;
8486
- for (auto param : ClangDecl->parameters ()) {
8487
- if (auto CAT = param->getType ()->getAs <clang::CountAttributedType>()) {
8488
- BoundsInfo.push_back (new CountedByParam (
8489
- parameterIndex, CAT->getCountExpr (), CAT->isCountInBytes ()));
8490
- }
8491
- parameterIndex++;
8492
- }
8493
- if (BoundsInfo.empty ())
8486
+ if (!funcsWithPointerBounds.count (ClangDecl))
8494
8487
return ;
8495
8488
8496
8489
llvm::SmallString<128 > MacroString;
8497
8490
{
8498
8491
llvm::raw_svector_ostream out (MacroString);
8499
8492
8500
- out << " @PointerBounds( " ;
8501
- for ( size_t i = 0 ; i < BoundsInfo. size (); i++) {
8502
- BoundsInfo[i]-> print ( getClangASTContext (), out);
8503
- if (i + 1 < BoundsInfo. size ()) {
8504
- out << " , " ;
8493
+ size_t parameterIndex = 1 ;
8494
+ PointerParamInfoPrinter printer ( getClangASTContext (), out);
8495
+ for ( auto param : ClangDecl-> parameters ()) {
8496
+ if (auto CAT = param-> getType ()-> getAs <clang::CountAttributedType> ()) {
8497
+ printer. printCountedBy (CAT, parameterIndex) ;
8505
8498
}
8499
+ parameterIndex++;
8506
8500
}
8507
- out << " )" ;
8508
8501
}
8509
8502
8510
8503
// Dig out a buffer with the attribute text.
0 commit comments