@@ -477,8 +477,9 @@ TEST(SubElementTest, Nested) {
477477 {strAttr, trueAttr, falseAttr, boolArrayAttr, dictAttr}));
478478}
479479
480- // Test how many times we call copy-ctor when building an attribute.
481- TEST (CopyCountAttr, CopyCount) {
480+ // Test how many times we call copy-ctor when building an attribute with the
481+ // 'get' method.
482+ TEST (CopyCountAttr, CopyCountGet) {
482483 MLIRContext context;
483484 context.loadDialect <test::TestDialect>();
484485
@@ -489,15 +490,35 @@ TEST(CopyCountAttr, CopyCount) {
489490 test::CopyCount::counter = 0 ;
490491 test::TestCopyCountAttr::get (&context, std::move (copyCount));
491492#ifndef NDEBUG
492- // One verification enabled only in assert-mode requires a copy.
493- EXPECT_EQ (counter1, 1 );
494- EXPECT_EQ (test::CopyCount::counter, 1 );
493+ // One verification enabled only in assert-mode requires two copies: one for
494+ // calling 'verifyInvariants' and one for calling 'verify' inside
495+ // 'verifyInvariants'.
496+ EXPECT_EQ (counter1, 2 );
497+ EXPECT_EQ (test::CopyCount::counter, 2 );
495498#else
496499 EXPECT_EQ (counter1, 0 );
497500 EXPECT_EQ (test::CopyCount::counter, 0 );
498501#endif
499502}
500503
504+ // Test how many times we call copy-ctor when building an attribute with the
505+ // 'getChecked' method.
506+ TEST (CopyCountAttr, CopyCountGetChecked) {
507+ MLIRContext context;
508+ context.loadDialect <test::TestDialect>();
509+ test::CopyCount::counter = 0 ;
510+ test::CopyCount copyCount (" hello" );
511+ auto loc = UnknownLoc::get (&context);
512+ test::TestCopyCountAttr::getChecked (loc, &context, std::move (copyCount));
513+ int counter1 = test::CopyCount::counter;
514+ test::CopyCount::counter = 0 ;
515+ test::TestCopyCountAttr::getChecked (loc, &context, std::move (copyCount));
516+ // The verifiers require two copies: one for calling 'verifyInvariants' and
517+ // one for calling 'verify' inside 'verifyInvariants'.
518+ EXPECT_EQ (counter1, 2 );
519+ EXPECT_EQ (test::CopyCount::counter, 2 );
520+ }
521+
501522// Test stripped printing using test dialect attribute.
502523TEST (CopyCountAttr, PrintStripped) {
503524 MLIRContext context;
0 commit comments