comparison gcc/coverage.c @ 63:b7f97abdc517 gcc-4.6-20100522

update gcc from gcc-4.5.0 to gcc-4.6
author ryoma <e075725@ie.u-ryukyu.ac.jp>
date Mon, 24 May 2010 12:47:05 +0900
parents 77e2b8dfacca
children f6334be47118
comparison
equal deleted inserted replaced
56:3c8a44c06a95 63:b7f97abdc517
44 #include "langhooks.h" 44 #include "langhooks.h"
45 #include "hashtab.h" 45 #include "hashtab.h"
46 #include "tree-iterator.h" 46 #include "tree-iterator.h"
47 #include "cgraph.h" 47 #include "cgraph.h"
48 #include "tree-pass.h" 48 #include "tree-pass.h"
49 #include "diagnostic.h"
50 #include "intl.h"
49 51
50 #include "gcov-io.c" 52 #include "gcov-io.c"
51 53
52 struct function_list 54 struct function_list
53 { 55 {
355 checksum = compute_checksum (); 357 checksum = compute_checksum ();
356 if (entry->checksum != checksum 358 if (entry->checksum != checksum
357 || entry->summary.num != expected) 359 || entry->summary.num != expected)
358 { 360 {
359 static int warned = 0; 361 static int warned = 0;
362 bool warning_printed = false;
360 tree id = DECL_ASSEMBLER_NAME (current_function_decl); 363 tree id = DECL_ASSEMBLER_NAME (current_function_decl);
361 364
362 if (warn_coverage_mismatch) 365 warning_printed =
363 warning (OPT_Wcoverage_mismatch, "coverage mismatch for function " 366 warning_at (input_location, OPT_Wcoverage_mismatch,
364 "%qE while reading counter %qs", id, ctr_names[counter]); 367 "coverage mismatch for function "
365 else 368 "%qE while reading counter %qs", id, ctr_names[counter]);
366 error ("coverage mismatch for function %qE while reading counter %qs", 369 if (warning_printed)
367 id, ctr_names[counter]);
368
369 if (!inhibit_warnings)
370 { 370 {
371 if (entry->checksum != checksum) 371 if (entry->checksum != checksum)
372 inform (input_location, "checksum is %x instead of %x", entry->checksum, checksum); 372 inform (input_location, "checksum is %x instead of %x",
373 entry->checksum, checksum);
373 else 374 else
374 inform (input_location, "number of counters is %d instead of %d", 375 inform (input_location, "number of counters is %d instead of %d",
375 entry->summary.num, expected); 376 entry->summary.num, expected);
376 } 377
377 378 if (!(errorcount || sorrycount)
378 if (warn_coverage_mismatch 379 && !warned++)
379 && !inhibit_warnings 380 {
380 && !warned++) 381 inform (input_location, "coverage mismatch ignored");
381 { 382 inform (input_location, flag_guess_branch_prob
382 inform (input_location, "coverage mismatch ignored due to -Wcoverage-mismatch"); 383 ? G_("execution counts estimated")
383 inform (input_location, flag_guess_branch_prob 384 : G_("execution counts assumed to be zero"));
384 ? "execution counts estimated" 385 if (!flag_guess_branch_prob)
385 : "execution counts assumed to be zero"); 386 inform (input_location,
386 if (!flag_guess_branch_prob) 387 "this can result in poorly optimized code");
387 inform (input_location, "this can result in poorly optimized code"); 388 }
388 } 389 }
389 390
390 return NULL; 391 return NULL;
391 } 392 }
392 393
669 RECORD_TYPE. */ 670 RECORD_TYPE. */
670 671
671 static tree 672 static tree
672 build_fn_info_value (const struct function_list *function, tree type) 673 build_fn_info_value (const struct function_list *function, tree type)
673 { 674 {
674 tree value = NULL_TREE;
675 tree fields = TYPE_FIELDS (type); 675 tree fields = TYPE_FIELDS (type);
676 unsigned ix; 676 unsigned ix;
677 tree array_value = NULL_TREE; 677 VEC(constructor_elt,gc) *v1 = NULL;
678 VEC(constructor_elt,gc) *v2 = NULL;
678 679
679 /* ident */ 680 /* ident */
680 value = tree_cons (fields, build_int_cstu (get_gcov_unsigned_t (), 681 CONSTRUCTOR_APPEND_ELT (v1, fields,
681 function->ident), value); 682 build_int_cstu (get_gcov_unsigned_t (),
683 function->ident));
682 fields = TREE_CHAIN (fields); 684 fields = TREE_CHAIN (fields);
683 685
684 /* checksum */ 686 /* checksum */
685 value = tree_cons (fields, build_int_cstu (get_gcov_unsigned_t (), 687 CONSTRUCTOR_APPEND_ELT (v1, fields,
686 function->checksum), value); 688 build_int_cstu (get_gcov_unsigned_t (),
689 function->checksum));
687 fields = TREE_CHAIN (fields); 690 fields = TREE_CHAIN (fields);
688 691
689 /* counters */ 692 /* counters */
690 for (ix = 0; ix != GCOV_COUNTERS; ix++) 693 for (ix = 0; ix != GCOV_COUNTERS; ix++)
691 if (prg_ctr_mask & (1 << ix)) 694 if (prg_ctr_mask & (1 << ix))
692 { 695 CONSTRUCTOR_APPEND_ELT (v2, NULL,
693 tree counters = build_int_cstu (get_gcov_unsigned_t (), 696 build_int_cstu (get_gcov_unsigned_t (),
694 function->n_ctrs[ix]); 697 function->n_ctrs[ix]));
695 698
696 array_value = tree_cons (NULL_TREE, counters, array_value); 699 CONSTRUCTOR_APPEND_ELT (v1, fields,
697 } 700 build_constructor (TREE_TYPE (fields), v2));
698 701
699 /* FIXME: use build_constructor directly. */ 702 return build_constructor (type, v1);
700 array_value = build_constructor_from_list (TREE_TYPE (fields),
701 nreverse (array_value));
702 value = tree_cons (fields, array_value, value);
703
704 /* FIXME: use build_constructor directly. */
705 value = build_constructor_from_list (type, nreverse (value));
706
707 return value;
708 } 703 }
709 704
710 /* Creates the gcov_ctr_info RECORD_TYPE. */ 705 /* Creates the gcov_ctr_info RECORD_TYPE. */
711 706
712 static tree 707 static tree
750 RECORD_TYPE. */ 745 RECORD_TYPE. */
751 746
752 static tree 747 static tree
753 build_ctr_info_value (unsigned int counter, tree type) 748 build_ctr_info_value (unsigned int counter, tree type)
754 { 749 {
755 tree value = NULL_TREE;
756 tree fields = TYPE_FIELDS (type); 750 tree fields = TYPE_FIELDS (type);
757 tree fn; 751 tree fn;
752 VEC(constructor_elt,gc) *v = NULL;
758 753
759 /* counters */ 754 /* counters */
760 value = tree_cons (fields, 755 CONSTRUCTOR_APPEND_ELT (v, fields,
761 build_int_cstu (get_gcov_unsigned_t (), 756 build_int_cstu (get_gcov_unsigned_t (),
762 prg_n_ctrs[counter]), 757 prg_n_ctrs[counter]));
763 value);
764 fields = TREE_CHAIN (fields); 758 fields = TREE_CHAIN (fields);
765 759
766 if (prg_n_ctrs[counter]) 760 if (prg_n_ctrs[counter])
767 { 761 {
768 tree array_type; 762 tree array_type;
776 TREE_TYPE (tree_ctr_tables[counter]) = array_type; 770 TREE_TYPE (tree_ctr_tables[counter]) = array_type;
777 DECL_SIZE (tree_ctr_tables[counter]) = TYPE_SIZE (array_type); 771 DECL_SIZE (tree_ctr_tables[counter]) = TYPE_SIZE (array_type);
778 DECL_SIZE_UNIT (tree_ctr_tables[counter]) = TYPE_SIZE_UNIT (array_type); 772 DECL_SIZE_UNIT (tree_ctr_tables[counter]) = TYPE_SIZE_UNIT (array_type);
779 varpool_finalize_decl (tree_ctr_tables[counter]); 773 varpool_finalize_decl (tree_ctr_tables[counter]);
780 774
781 value = tree_cons (fields, 775 CONSTRUCTOR_APPEND_ELT (v, fields,
782 build1 (ADDR_EXPR, TREE_TYPE (fields), 776 build1 (ADDR_EXPR, TREE_TYPE (fields),
783 tree_ctr_tables[counter]), 777 tree_ctr_tables[counter]));
784 value);
785 } 778 }
786 else 779 else
787 value = tree_cons (fields, null_pointer_node, value); 780 CONSTRUCTOR_APPEND_ELT (v, fields, null_pointer_node);
788 fields = TREE_CHAIN (fields); 781 fields = TREE_CHAIN (fields);
789 782
790 fn = build_decl (BUILTINS_LOCATION, 783 fn = build_decl (BUILTINS_LOCATION,
791 FUNCTION_DECL, 784 FUNCTION_DECL,
792 get_identifier (ctr_merge_functions[counter]), 785 get_identifier (ctr_merge_functions[counter]),
794 DECL_EXTERNAL (fn) = 1; 787 DECL_EXTERNAL (fn) = 1;
795 TREE_PUBLIC (fn) = 1; 788 TREE_PUBLIC (fn) = 1;
796 DECL_ARTIFICIAL (fn) = 1; 789 DECL_ARTIFICIAL (fn) = 1;
797 TREE_NOTHROW (fn) = 1; 790 TREE_NOTHROW (fn) = 1;
798 DECL_ASSEMBLER_NAME (fn); /* Initialize assembler name so we can stream out. */ 791 DECL_ASSEMBLER_NAME (fn); /* Initialize assembler name so we can stream out. */
799 value = tree_cons (fields, 792 CONSTRUCTOR_APPEND_ELT (v, fields, build1 (ADDR_EXPR, TREE_TYPE (fields), fn));
800 build1 (ADDR_EXPR, TREE_TYPE (fields), fn), 793
801 value); 794 return build_constructor (type, v);
802
803 /* FIXME: use build_constructor directly. */
804 value = build_constructor_from_list (type, nreverse (value));
805
806 return value;
807 } 795 }
808 796
809 /* Creates the gcov_info RECORD_TYPE and initializer for it. Returns a 797 /* Creates the gcov_info RECORD_TYPE and initializer for it. Returns a
810 CONSTRUCTOR. */ 798 CONSTRUCTOR. */
811 799
816 tree type, const_type; 804 tree type, const_type;
817 tree fn_info_type, fn_info_value = NULL_TREE; 805 tree fn_info_type, fn_info_value = NULL_TREE;
818 tree fn_info_ptr_type; 806 tree fn_info_ptr_type;
819 tree ctr_info_type, ctr_info_ary_type, ctr_info_value = NULL_TREE; 807 tree ctr_info_type, ctr_info_ary_type, ctr_info_value = NULL_TREE;
820 tree field, fields = NULL_TREE; 808 tree field, fields = NULL_TREE;
821 tree value = NULL_TREE;
822 tree filename_string; 809 tree filename_string;
823 int da_file_name_len; 810 int da_file_name_len;
824 unsigned n_fns; 811 unsigned n_fns;
825 const struct function_list *fn; 812 const struct function_list *fn;
826 tree string_type; 813 tree string_type;
814 VEC(constructor_elt,gc) *v1 = NULL;
815 VEC(constructor_elt,gc) *v2 = NULL;
827 816
828 /* Count the number of active counters. */ 817 /* Count the number of active counters. */
829 for (n_ctr_types = 0, ix = 0; ix != GCOV_COUNTERS; ix++) 818 for (n_ctr_types = 0, ix = 0; ix != GCOV_COUNTERS; ix++)
830 if (prg_ctr_mask & (1 << ix)) 819 if (prg_ctr_mask & (1 << ix))
831 n_ctr_types++; 820 n_ctr_types++;
836 /* Version ident */ 825 /* Version ident */
837 field = build_decl (BUILTINS_LOCATION, 826 field = build_decl (BUILTINS_LOCATION,
838 FIELD_DECL, NULL_TREE, get_gcov_unsigned_t ()); 827 FIELD_DECL, NULL_TREE, get_gcov_unsigned_t ());
839 TREE_CHAIN (field) = fields; 828 TREE_CHAIN (field) = fields;
840 fields = field; 829 fields = field;
841 value = tree_cons (field, build_int_cstu (TREE_TYPE (field), GCOV_VERSION), 830 CONSTRUCTOR_APPEND_ELT (v1, field,
842 value); 831 build_int_cstu (TREE_TYPE (field), GCOV_VERSION));
843 832
844 /* next -- NULL */ 833 /* next -- NULL */
845 field = build_decl (BUILTINS_LOCATION, 834 field = build_decl (BUILTINS_LOCATION,
846 FIELD_DECL, NULL_TREE, build_pointer_type (const_type)); 835 FIELD_DECL, NULL_TREE, build_pointer_type (const_type));
847 TREE_CHAIN (field) = fields; 836 TREE_CHAIN (field) = fields;
848 fields = field; 837 fields = field;
849 value = tree_cons (field, null_pointer_node, value); 838 CONSTRUCTOR_APPEND_ELT (v1, field, null_pointer_node);
850 839
851 /* stamp */ 840 /* stamp */
852 field = build_decl (BUILTINS_LOCATION, 841 field = build_decl (BUILTINS_LOCATION,
853 FIELD_DECL, NULL_TREE, get_gcov_unsigned_t ()); 842 FIELD_DECL, NULL_TREE, get_gcov_unsigned_t ());
854 TREE_CHAIN (field) = fields; 843 TREE_CHAIN (field) = fields;
855 fields = field; 844 fields = field;
856 value = tree_cons (field, build_int_cstu (TREE_TYPE (field), local_tick), 845 CONSTRUCTOR_APPEND_ELT (v1, field,
857 value); 846 build_int_cstu (TREE_TYPE (field), local_tick));
858 847
859 /* Filename */ 848 /* Filename */
860 string_type = build_pointer_type (build_qualified_type (char_type_node, 849 string_type = build_pointer_type (build_qualified_type (char_type_node,
861 TYPE_QUAL_CONST)); 850 TYPE_QUAL_CONST));
862 field = build_decl (BUILTINS_LOCATION, 851 field = build_decl (BUILTINS_LOCATION,
866 da_file_name_len = strlen (da_file_name); 855 da_file_name_len = strlen (da_file_name);
867 filename_string = build_string (da_file_name_len + 1, da_file_name); 856 filename_string = build_string (da_file_name_len + 1, da_file_name);
868 TREE_TYPE (filename_string) = build_array_type 857 TREE_TYPE (filename_string) = build_array_type
869 (char_type_node, build_index_type 858 (char_type_node, build_index_type
870 (build_int_cst (NULL_TREE, da_file_name_len))); 859 (build_int_cst (NULL_TREE, da_file_name_len)));
871 value = tree_cons (field, build1 (ADDR_EXPR, string_type, filename_string), 860 CONSTRUCTOR_APPEND_ELT (v1, field,
872 value); 861 build1 (ADDR_EXPR, string_type, filename_string));
873 862
874 /* Build the fn_info type and initializer. */ 863 /* Build the fn_info type and initializer. */
875 fn_info_type = build_fn_info_type (n_ctr_types); 864 fn_info_type = build_fn_info_type (n_ctr_types);
876 fn_info_ptr_type = build_pointer_type (build_qualified_type 865 fn_info_ptr_type = build_pointer_type (build_qualified_type
877 (fn_info_type, TYPE_QUAL_CONST)); 866 (fn_info_type, TYPE_QUAL_CONST));
878 for (fn = functions_head, n_fns = 0; fn; fn = fn->next, n_fns++) 867 for (fn = functions_head, n_fns = 0; fn; fn = fn->next, n_fns++)
879 fn_info_value = tree_cons (NULL_TREE, 868 CONSTRUCTOR_APPEND_ELT (v2, NULL_TREE,
880 build_fn_info_value (fn, fn_info_type), 869 build_fn_info_value (fn, fn_info_type));
881 fn_info_value); 870
882 if (n_fns) 871 if (n_fns)
883 { 872 {
884 tree array_type; 873 tree array_type;
885 874
886 array_type = build_index_type (build_int_cst (NULL_TREE, n_fns - 1)); 875 array_type = build_index_type (build_int_cst (NULL_TREE, n_fns - 1));
887 array_type = build_array_type (fn_info_type, array_type); 876 array_type = build_array_type (fn_info_type, array_type);
888 877
889 /* FIXME: use build_constructor directly. */ 878 fn_info_value = build_constructor (array_type, v2);
890 fn_info_value = build_constructor_from_list (array_type,
891 nreverse (fn_info_value));
892 fn_info_value = build1 (ADDR_EXPR, fn_info_ptr_type, fn_info_value); 879 fn_info_value = build1 (ADDR_EXPR, fn_info_ptr_type, fn_info_value);
893 } 880 }
894 else 881 else
895 fn_info_value = null_pointer_node; 882 fn_info_value = null_pointer_node;
896 883
897 /* number of functions */ 884 /* number of functions */
898 field = build_decl (BUILTINS_LOCATION, 885 field = build_decl (BUILTINS_LOCATION,
899 FIELD_DECL, NULL_TREE, get_gcov_unsigned_t ()); 886 FIELD_DECL, NULL_TREE, get_gcov_unsigned_t ());
900 TREE_CHAIN (field) = fields; 887 TREE_CHAIN (field) = fields;
901 fields = field; 888 fields = field;
902 value = tree_cons (field, 889 CONSTRUCTOR_APPEND_ELT (v1, field,
903 build_int_cstu (get_gcov_unsigned_t (), n_fns), 890 build_int_cstu (get_gcov_unsigned_t (), n_fns));
904 value);
905 891
906 /* fn_info table */ 892 /* fn_info table */
907 field = build_decl (BUILTINS_LOCATION, 893 field = build_decl (BUILTINS_LOCATION,
908 FIELD_DECL, NULL_TREE, fn_info_ptr_type); 894 FIELD_DECL, NULL_TREE, fn_info_ptr_type);
909 TREE_CHAIN (field) = fields; 895 TREE_CHAIN (field) = fields;
910 fields = field; 896 fields = field;
911 value = tree_cons (field, fn_info_value, value); 897 CONSTRUCTOR_APPEND_ELT (v1, field, fn_info_value);
912 898
913 /* counter_mask */ 899 /* counter_mask */
914 field = build_decl (BUILTINS_LOCATION, 900 field = build_decl (BUILTINS_LOCATION,
915 FIELD_DECL, NULL_TREE, get_gcov_unsigned_t ()); 901 FIELD_DECL, NULL_TREE, get_gcov_unsigned_t ());
916 TREE_CHAIN (field) = fields; 902 TREE_CHAIN (field) = fields;
917 fields = field; 903 fields = field;
918 value = tree_cons (field, 904 CONSTRUCTOR_APPEND_ELT (v1, field,
919 build_int_cstu (get_gcov_unsigned_t (), prg_ctr_mask), 905 build_int_cstu (get_gcov_unsigned_t (),
920 value); 906 prg_ctr_mask));
921 907
922 /* counters */ 908 /* counters */
923 ctr_info_type = build_ctr_info_type (); 909 ctr_info_type = build_ctr_info_type ();
924 ctr_info_ary_type = build_index_type (build_int_cst (NULL_TREE, 910 ctr_info_ary_type = build_index_type (build_int_cst (NULL_TREE,
925 n_ctr_types)); 911 n_ctr_types));
926 ctr_info_ary_type = build_array_type (ctr_info_type, ctr_info_ary_type); 912 ctr_info_ary_type = build_array_type (ctr_info_type, ctr_info_ary_type);
913 v2 = NULL;
927 for (ix = 0; ix != GCOV_COUNTERS; ix++) 914 for (ix = 0; ix != GCOV_COUNTERS; ix++)
928 if (prg_ctr_mask & (1 << ix)) 915 if (prg_ctr_mask & (1 << ix))
929 ctr_info_value = tree_cons (NULL_TREE, 916 CONSTRUCTOR_APPEND_ELT (v2, NULL_TREE,
930 build_ctr_info_value (ix, ctr_info_type), 917 build_ctr_info_value (ix, ctr_info_type));
931 ctr_info_value); 918 ctr_info_value = build_constructor (ctr_info_ary_type, v2);
932 /* FIXME: use build_constructor directly. */
933 ctr_info_value = build_constructor_from_list (ctr_info_ary_type,
934 nreverse (ctr_info_value));
935 919
936 field = build_decl (BUILTINS_LOCATION, 920 field = build_decl (BUILTINS_LOCATION,
937 FIELD_DECL, NULL_TREE, ctr_info_ary_type); 921 FIELD_DECL, NULL_TREE, ctr_info_ary_type);
938 TREE_CHAIN (field) = fields; 922 TREE_CHAIN (field) = fields;
939 fields = field; 923 fields = field;
940 value = tree_cons (field, ctr_info_value, value); 924 CONSTRUCTOR_APPEND_ELT (v1, field, ctr_info_value);
941 925
942 finish_builtin_struct (type, "__gcov_info", fields, NULL_TREE); 926 finish_builtin_struct (type, "__gcov_info", fields, NULL_TREE);
943 927
944 /* FIXME: use build_constructor directly. */ 928 return build_constructor (type, v1);
945 value = build_constructor_from_list (type, nreverse (value));
946
947 return value;
948 } 929 }
949 930
950 /* Write out the structure which libgcov uses to locate all the 931 /* Write out the structure which libgcov uses to locate all the
951 counters. The structures used here must match those defined in 932 counters. The structures used here must match those defined in
952 gcov-io.h. Write out the constructor to call __gcov_init. */ 933 gcov-io.h. Write out the constructor to call __gcov_init. */