comparison clang/test/CodeGenObjC/strong-in-c-struct.m @ 173:0572611fdcc8 llvm10 llvm12

reorgnization done
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 11:55:54 +0900
parents 1d019706d866
children 2e18cbf3894f
comparison
equal deleted inserted replaced
172:9fbae9c8bf63 173:0572611fdcc8
86 StrongSmall getStrongSmall(void); 86 StrongSmall getStrongSmall(void);
87 StrongOuter getStrongOuter(void); 87 StrongOuter getStrongOuter(void);
88 StrongOuter2 getStrongOuter2(void); 88 StrongOuter2 getStrongOuter2(void);
89 void calleeStrongSmall(StrongSmall); 89 void calleeStrongSmall(StrongSmall);
90 void func(Strong *); 90 void func(Strong *);
91
92 @interface C
93 - (StrongSmall)getStrongSmall;
94 + (StrongSmall)getStrongSmallClass;
95 @end
96
97 id g0;
91 98
92 // CHECK: %[[STRUCT_STRONGOUTER:.*]] = type { %[[STRUCT_STRONG:.*]], i8*, double } 99 // CHECK: %[[STRUCT_STRONGOUTER:.*]] = type { %[[STRUCT_STRONG:.*]], i8*, double }
93 // CHECK: %[[STRUCT_STRONG]] = type { %[[STRUCT_TRIVIAL:.*]], i8* } 100 // CHECK: %[[STRUCT_STRONG]] = type { %[[STRUCT_TRIVIAL:.*]], i8* }
94 // CHECK: %[[STRUCT_TRIVIAL]] = type { [4 x i32] } 101 // CHECK: %[[STRUCT_TRIVIAL]] = type { [4 x i32] }
95 // CHECK: %[[STRUCT_BLOCK_BYREF_T:.*]] = type { i8*, %[[STRUCT_BLOCK_BYREF_T]]*, i32, i32, i8*, i8*, i8*, %[[STRUCT_STRONGOUTER]] } 102 // CHECK: %[[STRUCT_BLOCK_BYREF_T:.*]] = type { i8*, %[[STRUCT_BLOCK_BYREF_T]]*, i32, i32, i8*, i8*, i8*, %[[STRUCT_STRONGOUTER]] }
474 481
475 void test_destructor_ignored_result(void) { 482 void test_destructor_ignored_result(void) {
476 getStrongSmall(); 483 getStrongSmall();
477 } 484 }
478 485
486 // CHECK: define void @test_destructor_ignored_result2(%{{.*}}* %[[C:.*]])
487 // CHECK: %[[TMP:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8
488 // CHECK: %[[CALL:.*]] = call [2 x i64]{{.*}}@objc_msgSend
489 // CHECK: %[[V5:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[TMP]] to [2 x i64]*
490 // CHECK: store [2 x i64] %[[CALL]], [2 x i64]* %[[V5]], align 8
491 // CHECK: %[[V6:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[TMP]] to i8**
492 // CHECK: call void @__destructor_8_s8(i8** %[[V6]])
493
494 void test_destructor_ignored_result2(C *c) {
495 [c getStrongSmall];
496 }
497
479 // CHECK: define void @test_copy_constructor_StrongBlock( 498 // CHECK: define void @test_copy_constructor_StrongBlock(
480 // CHECK: call void @__copy_constructor_8_8_sb0( 499 // CHECK: call void @__copy_constructor_8_8_sb0(
481 // CHECK: call void @__destructor_8_sb0( 500 // CHECK: call void @__destructor_8_sb0(
482 // CHECK: ret void 501 // CHECK: ret void
483 502
518 *d = *s; 537 *d = *s;
519 } 538 }
520 539
521 // CHECK: define void @test_copy_constructor_StrongVolatile0( 540 // CHECK: define void @test_copy_constructor_StrongVolatile0(
522 // CHECK: call void @__copy_constructor_8_8_t0w4_sv8( 541 // CHECK: call void @__copy_constructor_8_8_t0w4_sv8(
542 // CHECK-NOT: call
523 // CHECK: call void @__destructor_8_sv8( 543 // CHECK: call void @__destructor_8_sv8(
544 // CHECK-NOT: call
524 545
525 // CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_t0w4_sv8( 546 // CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_t0w4_sv8(
526 // CHECK: %[[V8:.*]] = load volatile i8*, i8** %{{.*}}, align 8 547 // CHECK: %[[V8:.*]] = load volatile i8*, i8** %{{.*}}, align 8
527 // CHECK: %[[V9:.*]] = call i8* @llvm.objc.retain(i8* %[[V8]]) 548 // CHECK: %[[V9:.*]] = call i8* @llvm.objc.retain(i8* %[[V8]])
528 // CHECK: store volatile i8* %[[V9]], i8** %{{.*}}, align 8 549 // CHECK: store volatile i8* %[[V9]], i8** %{{.*}}, align 8
707 728
708 void test_copy_constructor_VolatileArray(VolatileArray *a) { 729 void test_copy_constructor_VolatileArray(VolatileArray *a) {
709 VolatileArray t = *a; 730 VolatileArray t = *a;
710 } 731 }
711 732
733 // CHECK: define void @test_compound_literal0(
734 // CHECK: %[[P:.*]] = alloca %[[STRUCT_STRONGSMALL]]*, align 8
735 // CHECK: %[[_COMPOUNDLITERAL:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8
736 // CHECK: %[[CLEANUP_COND:.*]] = alloca i1, align 1
737 // CHECK: %[[_COMPOUNDLITERAL1:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8
738 // CHECK: %[[CLEANUP_COND4:.*]] = alloca i1, align 1
739
740 // CHECK: %[[I:.*]] = getelementptr inbounds %[[STRUCT_STRONGSMALL]], %[[STRUCT_STRONGSMALL]]* %[[_COMPOUNDLITERAL]], i32 0, i32 0
741 // CHECK: store i32 1, i32* %[[I]], align 8
742 // CHECK: %[[F1:.*]] = getelementptr inbounds %[[STRUCT_STRONGSMALL]], %[[STRUCT_STRONGSMALL]]* %[[_COMPOUNDLITERAL]], i32 0, i32 1
743 // CHECK: store i8* null, i8** %[[F1]], align 8
744 // CHECK: store i1 true, i1* %[[CLEANUP_COND]], align 1
745
746 // CHECK: %[[I2:.*]] = getelementptr inbounds %[[STRUCT_STRONGSMALL]], %[[STRUCT_STRONGSMALL]]* %[[_COMPOUNDLITERAL1]], i32 0, i32 0
747 // CHECK: store i32 2, i32* %[[I2]], align 8
748 // CHECK: %[[F13:.*]] = getelementptr inbounds %[[STRUCT_STRONGSMALL]], %[[STRUCT_STRONGSMALL]]* %[[_COMPOUNDLITERAL1]], i32 0, i32 1
749 // CHECK: store i8* null, i8** %[[F13]], align 8
750 // CHECK: store i1 true, i1* %[[CLEANUP_COND4]], align 1
751
752 // CHECK: %[[COND:.*]] = phi %[[STRUCT_STRONGSMALL]]* [ %[[_COMPOUNDLITERAL]], %{{.*}} ], [ %[[_COMPOUNDLITERAL1]], %{{.*}} ]
753 // CHECK: store %[[STRUCT_STRONGSMALL]]* %[[COND]], %[[STRUCT_STRONGSMALL]]** %[[P]], align 8
754 // CHECK: call void @func(
755
756 // CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[_COMPOUNDLITERAL1]] to i8**
757 // CHECK: call void @__destructor_8_s8(i8** %[[V1]])
758
759 // CHECK: %[[V2:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[_COMPOUNDLITERAL]] to i8**
760 // CHECK: call void @__destructor_8_s8(i8** %[[V2]])
761
762 void test_compound_literal0(int c) {
763 StrongSmall *p = c ? &(StrongSmall){ 1, 0 } : &(StrongSmall){ 2, 0 };
764 func(0);
765 }
766
767 // Check that there is only one destructor call, which destructs 't'.
768
769 // CHECK: define void @test_compound_literal1(
770 // CHECK: %[[T:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8
771
772 // CHECK: %[[I:.*]] = getelementptr inbounds %[[STRUCT_STRONGSMALL]], %[[STRUCT_STRONGSMALL]]* %[[T]], i32 0, i32 0
773 // CHECK: store i32 1, i32* %[[I]], align 8
774 // CHECK: %[[F1:.*]] = getelementptr inbounds %[[STRUCT_STRONGSMALL]], %[[STRUCT_STRONGSMALL]]* %[[T]], i32 0, i32 1
775 // CHECK: store i8* null, i8** %[[F1]], align 8
776
777 // CHECK: %[[I1:.*]] = getelementptr inbounds %[[STRUCT_STRONGSMALL]], %[[STRUCT_STRONGSMALL]]* %[[T]], i32 0, i32 0
778 // CHECK: store i32 2, i32* %[[I1]], align 8
779 // CHECK: %[[F12:.*]] = getelementptr inbounds %[[STRUCT_STRONGSMALL]], %[[STRUCT_STRONGSMALL]]* %[[T]], i32 0, i32 1
780 // CHECK: store i8* null, i8** %[[F12]], align 8
781
782 // CHECK: call void @func(
783 // CHECK-NOT: call void
784 // CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[T]] to i8**
785 // CHECK: call void @__destructor_8_s8(i8** %[[V1]])
786 // CHECK-NOT: call void
787
788 void test_compound_literal1(int c) {
789 StrongSmall t = c ? (StrongSmall){ 1, 0 } : (StrongSmall){ 2, 0 };
790 func(0);
791 }
792
793 // CHECK: define void @test_compound_literal2(
794 // CHECK: %[[P_ADDR:.*]] = alloca %[[STRUCT_STRONGSMALL]]*, align 8
795 // CHECK: %[[_COMPOUNDLITERAL:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8
796 // CHECK: %[[CLEANUP_COND:.*]] = alloca i1, align 1
797 // CHECK: %[[_COMPOUNDLITERAL1:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8
798 // CHECK: %[[CLEANUP_COND4:.*]] = alloca i1, align 1
799 // CHECK: %[[V0:.*]] = load %[[STRUCT_STRONGSMALL]]*, %[[STRUCT_STRONGSMALL]]** %[[P_ADDR]], align 8
800
801 // CHECK: %[[I:.*]] = getelementptr inbounds %[[STRUCT_STRONGSMALL]], %[[STRUCT_STRONGSMALL]]* %[[_COMPOUNDLITERAL]], i32 0, i32 0
802 // CHECK: store i32 1, i32* %[[I]], align 8
803 // CHECK: %[[F1:.*]] = getelementptr inbounds %[[STRUCT_STRONGSMALL]], %[[STRUCT_STRONGSMALL]]* %[[_COMPOUNDLITERAL]], i32 0, i32 1
804 // CHECK: store i8* null, i8** %[[F1]], align 8
805 // CHECK: store i1 true, i1* %[[CLEANUP_COND]], align 1
806 // CHECK: %[[V2:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[V0]] to i8**
807 // CHECK: %[[V3:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[_COMPOUNDLITERAL]] to i8**
808 // CHECK: call void @__copy_assignment_8_8_t0w4_s8(i8** %[[V2]], i8** %[[V3]])
809
810 // CHECK: %[[I2:.*]] = getelementptr inbounds %[[STRUCT_STRONGSMALL]], %[[STRUCT_STRONGSMALL]]* %[[_COMPOUNDLITERAL1]], i32 0, i32 0
811 // CHECK: store i32 2, i32* %[[I2]], align 8
812 // CHECK: %[[F13:.*]] = getelementptr inbounds %[[STRUCT_STRONGSMALL]], %[[STRUCT_STRONGSMALL]]* %[[_COMPOUNDLITERAL1]], i32 0, i32 1
813 // CHECK: store i8* null, i8** %[[F13]], align 8
814 // CHECK: store i1 true, i1* %[[CLEANUP_COND4]], align 1
815 // CHECK: %[[V4:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[V0]] to i8**
816 // CHECK: %[[V5:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[_COMPOUNDLITERAL1]] to i8**
817 // CHECK: call void @__copy_assignment_8_8_t0w4_s8(i8** %[[V4]], i8** %[[V5]])
818
819 // CHECK: call void @func(
820
821 // CHECK: %[[V6:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[_COMPOUNDLITERAL1]] to i8**
822 // CHECK: call void @__destructor_8_s8(i8** %[[V6]])
823
824 // CHECK: %[[V7:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[_COMPOUNDLITERAL]] to i8**
825 // CHECK: call void @__destructor_8_s8(i8** %[[V7]])
826
827 void test_compound_literal2(int c, StrongSmall *p) {
828 *p = c ? (StrongSmall){ 1, 0 } : (StrongSmall){ 2, 0 };
829 func(0);
830 }
831
832 // CHECK: define void @test_member_access(
833 // CHECK: %[[TMP:.*]] = alloca %[[STRUCT_STRONGSMALL]],
834 // CHECK: %[[V3:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[TMP]] to i8**
835 // CHECK: call void @__destructor_8_s8(i8** %[[V3]])
836 // CHECK: call void @func(
837
838 void test_member_access(void) {
839 g0 = getStrongSmall().f1;
840 func(0);
841 }
842
843 // CHECK: define void @test_member_access2(%{{.*}}* %[[C:.*]])
844 // CHECK: %[[COERCE:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8
845 // CHECK: %[[V8:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[COERCE]] to i8**
846 // CHECK: call void @__destructor_8_s8(i8** %[[V8]])
847 // CHECK: call void @func(
848
849 void test_member_access2(C *c) {
850 g0 = [c getStrongSmall].f1;
851 func(0);
852 }
853
854 // CHECK: define void @test_member_access3(
855 // CHECK: %[[COERCE:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8
856 // CHECK: %[[V8:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[COERCE]] to i8**
857 // CHECK: call void @__destructor_8_s8(i8** %[[V8]])
858 // CHECK: call void @func(
859
860 void test_member_access3(void) {
861 g0 = [C getStrongSmallClass].f1;
862 func(0);
863 }
864
865 // CHECK: define void @test_member_access4()
866 // CHECK: %[[COERCE:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8
867 // CHECK: %[[V5:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[COERCE]] to i8**
868 // CHECK: call void @__destructor_8_s8(i8** %[[V5]])
869 // CHECK: call void @func(
870
871 void test_member_access4(void) {
872 g0 = ^{ StrongSmall s; return s; }().f1;
873 func(0);
874 }
875
876 // CHECK: define void @test_volatile_variable_reference(
877 // CHECK: %[[AGG_TMP_ENSURED:.*]] = alloca %[[STRUCT_STRONGSMALL]],
878 // CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[AGG_TMP_ENSURED]] to i8**
879 // CHECK: %[[V2:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %{{.*}} to i8**
880 // CHECK: call void @__copy_constructor_8_8_tv0w32_sv8(i8** %[[V1]], i8** %[[V2]])
881 // CHECK: %[[V3:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[AGG_TMP_ENSURED]] to i8**
882 // CHECK: call void @__destructor_8_s8(i8** %[[V3]])
883 // CHECK: call void @func(
884
885 void test_volatile_variable_reference(volatile StrongSmall *a) {
886 (void)*a;
887 func(0);
888 }
889
890 struct ZeroBitfield {
891 int : 0;
892 id strong;
893 };
894
895
896 // CHECK: define linkonce_odr hidden void @__default_constructor_8_sv0
897 // CHECK: define linkonce_odr hidden void @__copy_assignment_8_8_sv0
898 void test_zero_bitfield() {
899 struct ZeroBitfield volatile a, b;
900 a = b;
901 }
902
712 #endif /* USESTRUCT */ 903 #endif /* USESTRUCT */