@@ -477,8 +477,9 @@ TEST(SubElementTest, Nested) {
477
477
{strAttr, trueAttr, falseAttr, boolArrayAttr, dictAttr}));
478
478
}
479
479
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) {
482
483
MLIRContext context;
483
484
context.loadDialect <test::TestDialect>();
484
485
@@ -489,15 +490,35 @@ TEST(CopyCountAttr, CopyCount) {
489
490
test::CopyCount::counter = 0 ;
490
491
test::TestCopyCountAttr::get (&context, std::move (copyCount));
491
492
#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 );
495
498
#else
496
499
EXPECT_EQ (counter1, 0 );
497
500
EXPECT_EQ (test::CopyCount::counter, 0 );
498
501
#endif
499
502
}
500
503
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
+
501
522
// Test stripped printing using test dialect attribute.
502
523
TEST (CopyCountAttr, PrintStripped) {
503
524
MLIRContext context;
0 commit comments