@@ -462,8 +462,9 @@ TEST(SubElementTest, Nested) {
462
462
{strAttr, trueAttr, falseAttr, boolArrayAttr, dictAttr}));
463
463
}
464
464
465
- // Test how many times we call copy-ctor when building an attribute.
466
- TEST (CopyCountAttr, CopyCount) {
465
+ // Test how many times we call copy-ctor when building an attribute with the
466
+ // 'get' method.
467
+ TEST (CopyCountAttr, CopyCountGet) {
467
468
MLIRContext context;
468
469
context.loadDialect <test::TestDialect>();
469
470
@@ -483,6 +484,23 @@ TEST(CopyCountAttr, CopyCount) {
483
484
#endif
484
485
}
485
486
487
+ // Test how many times we call copy-ctor when building an attribute with the
488
+ // 'getChecked' method.
489
+ TEST (CopyCountAttr, CopyCountGetChecked) {
490
+ MLIRContext context;
491
+ context.loadDialect <test::TestDialect>();
492
+ test::CopyCount::counter = 0 ;
493
+ test::CopyCount copyCount (" hello" );
494
+ auto loc = UnknownLoc::get (&context);
495
+ test::TestCopyCountAttr::getChecked (loc, &context, std::move (copyCount));
496
+ int counter1 = test::CopyCount::counter;
497
+ test::CopyCount::counter = 0 ;
498
+ test::TestCopyCountAttr::getChecked (loc, &context, std::move (copyCount));
499
+ // One verification requires a copy.
500
+ EXPECT_EQ (counter1, 1 );
501
+ EXPECT_EQ (test::CopyCount::counter, 1 );
502
+ }
503
+
486
504
// Test stripped printing using test dialect attribute.
487
505
TEST (CopyCountAttr, PrintStripped) {
488
506
MLIRContext context;
0 commit comments