For common switches or switches can’t be finished by c_common_handle_option, common_handle_option is invoked.
655 static int
656 common_handle_option (size_t scode, const char *arg, in opts.c
657 int value ATTRIBUTE_UNUSED)
658 {
659 enum opt_code code = (enum opt_code) scode;
660
661 switch (code)
662 {
663 default:
664 abort ();
665
666 case OPT__help:
667 print_help ();
668 exit_after_options = true;
669 break;
670
671 case OPT__param:
672 handle_param (arg);
673 break;
Switch –param name=value sets some internal limits used by GCC to determine the amount of optimization to be done, so adjustments to these values are adjustments to the optimization.
The adjustment is done by handle_param.
1529 static void
1530 handle_param (const char *carg) in opts.c
1531 {
1532 char *equal, *arg;
1533 int value;
1534
1535 arg = xstrdup (carg);
1536 equal = strchr (arg, '=');
1537 if (!equal)
1538 error ("%s: --param arguments should be of the form NAME=VALUE", arg);
1539 else
1540 {
1541 value = integral_argument (equal + 1);
1542 if (value == -1)
1543 error ("invalid --param value `%s'", equal + 1);
1544 else
1545 {
1546 *equal = '/0';
1547 set_param_value (arg, value);
1548 }
1549 }
1550
1551 free (arg);
1552 }
The parameter must be positive integer. To set the value, set_param_value is invoked in turn.
58 void
59 set_param_value (const char *name, int value) in params.c
60 {
61 size_t i;
62
63 /* Make sure nobody tries to set a parameter to an invalid value. */
64 if (value == INVALID_PARAM_VAL)
65 abort ();
66
67 /* Scan the parameter table to find a matching entry. */
68 for (i = 0; i < num_compiler_params; ++i)
69 if (strcmp (compiler_params[i].option, name) == 0)
70 {
71 compiler_params[i].value = value;
72 return;
73 }
74
75 /* If we didn't find this parameter, issue an error message. */
76 error ("invalid parameter `%s'", name);
77 }
The names that can be used by --param are already determined. In general_init, at line 4264, add_params decides the names, and uses lang_independent_params to initialize compiler_params.
common_handle_option (continue)
675 case OPT__target_help:
676 display_target_options ();
677 exit_after_options = true;
678 break;
679
680 case OPT__version:
681 print_version (stderr, "");
682 exit_after_options = true;
683 break;
684
685 case OPT_G:
686 g_switch_value = value;
687 g_switch_set = true;
688 break;
689
690 case OPT_O:
691 case OPT_Os:
692 /* Currently handled in a prescan. */
693 break;
694
695 case OPT_W:
696 /* For backward compatibility, -W is the same as -Wextra. */
697 set_Wextra (value);
698 break;
699
700 case OPT_Waggregate_return:
701 warn_aggregate_return = value;
702 break;
703
704 case OPT_Wcast_align:
705 warn_cast_align = value;
706 break;
707
708 case OPT_Wdeprecated_declarations:
709 warn_deprecated_decl = value;
710 break;
711
712 case OPT_Wdisabled_optimization:
713 warn_disabled_optimization = value;
714 break;
715
716 case OPT_Werror:
717 warnings_are_errors = value;
718 break;
719
720 case OPT_Wextra:
721 set_Wextra (value);
722 break;
723
724 case OPT_Winline:
725 warn_inline = value;
726 break;
727
728 case OPT_Wlarger_than_:
729 larger_than_size = value;
730 warn_larger_than = value != -1;
731 break;
732
733 case OPT_Wmissing_noreturn:
734 warn_missing_noreturn = value;
735 break;
736
737 case OPT_Wpacked:
738 warn_packed = value;
739 break;
740
741 case OPT_Wpadded:
742 warn_padded = value;
743 break;
744
745 case OPT_Wshadow:
746 warn_shadow = value;
747 break;
748
749 case OPT_Wstrict_aliasing:
750 warn_strict_aliasing = value;
751 break;
752
753 case OPT_Wswitch:
754 warn_switch = value;
755 break;
756
757 case OPT_Wswitch_default:
758 warn_switch_default = value;
759 break;
760
761 case OPT_Wswitch_enum:
762 warn_switch_enum = value;
763 break;
764
765 case OPT_Wsystem_headers:
766 warn_system_headers = value;
767 break;
768
769 case OPT_Wuninitialized:
770 warn_uninitialized = value;
771 break;
772
773 case OPT_Wunreachable_code:
774 warn_notreached = value;
775 break;
776
777 case OPT_Wunused:
778 set_Wunused (value);
779 break;
780
781 case OPT_Wunused_function:
782 warn_unused_function = value;
783 break;
784
785 case OPT_Wunused_label:
786 warn_unused_label = value;
787 break;
788
789 case OPT_Wunused_parameter:
790 warn_unused_parameter = value;
791 break;
792
793 case OPT_Wunused_value:
794 warn_unused_value = value;
795 break;
796
797 case OPT_Wunused_variable:
798 warn_unused_variable = value;
799 break;
In above, the switches encountered and the variables related are:
g_switch_value (-G number), puts global and static objects less than or equal to number bytes into the small data or bss sections instead of the normal data or bss sections. The default value of number is 8. The -msdata option must be set to either sdata or use for this option to have any effect. All modules should be compiled with the same -msdata and -G settings. Compiling with different values for number may or may not work. If it does not work, the linker will detect the error preventing incorrect code from being generated.
Above at line 697, switch –W is handled by set_Wextra.
1555 static void
1556 set_Wextra (int setting) in opts.c
1557 {
1558 extra_warnings = setting;
1559 warn_unused_value = setting;
1560 warn_unused_parameter = (setting && maybe_warn_unused_parameter);
1561
1562 /* We save the value of warn_uninitialized, since if they put
1563 -Wuninitialized on the command line, we need to generate a
1564 warning about not using it without also specifying -O. */
1565 if (setting == 0)
1566 warn_uninitialized = 0;
1567 else if (warn_uninitialized != 1)
1568 warn_uninitialized = 2;
1569 }
-W This option enables the issuing of a family of warning messages dealing primarily with code that could possibly cause a problem, but it could also be what was intended by the programmer. This option enables all of the following:
Comparison A warning is issued if an unsigned value is tested for being less than zero. For example, because unsigned values can never be negative, the following test will always be false:
unsigned int x;
. . .
if(x < 0) . . .
Comparison A warning is issued for the comparison of a signed value with an unsigned value. An incorrect result can be produced when the unsigned value is converted to a signed value for the comparison. This warning can be suppressed by -Wno-sign-compare.
Comparison Algebraic notation and the C sytnax for comparison are not the same. A warning will be issued for the following statement:
if(a < b < c) . . .
In algebraic notation this expression is true only if b lies in the open interval between a and c. In C, this expression is the same as the following, which is very different:
int result;
result = a < b;
if(result < b) . . .
Const return Issue a warning for the return value of a function being declared as const. The const declaration has no meaning here because the return value from a function is an rvalue.
Aggregate initializers A warning is issued if initial values are specified for an aggregate data type, but values are not supplied for all members of the aggregate. In the following example an error message would be issued for both the array and the struct:
struct {
int a;
int b;
int c;
} trmp = { 1, 2 };
int arr[10] = { 1, 2, 3, 4, 5 };
No side effect A warning is issued for a statement that has no effect. For example, the result of the following addition is not used:
int a = 1;
int b = 2;
a + b;
Overflow In Fortran, warnings are issued when floating point constant declarations overflow.
Return value Issue a warning if a function is written so that it may or may not return a value, as in the following example which does not return value if x is negative:
ambigret(int x) {
if(x >= 0)
return(x);
}
Static syntax Issue a warning if the keyword static does not come first on a declaration line. This ordering is no longer a requirement in standard C.
Unused arguments If either -Wall or -Wunused is specified along with -W, a warning is issued for any unused arguments in the body of a function.
warn_inline (C, C++, ObjC, -Winline) if nonzero, issues a warning if a function that was declared as inline could not be expanded as inline code.
warn_larger_than (C, C++, ObjC, -Wlarger-than) if nonzero, issues a warning whenever an object larger than size bytes is declared, if the return value from a function is larger than size bytes.
warn_aggregate_return (C, C++, ObjC, -Waggregate-return) if nonzero, issues a warning if a function returns a structure, union, or an array.
warn_cast_align (C, C++, ObjC, -Wcast-align) if nonzero, issues a warning there is a possible problem with the alignment resulting from casting a pointer to a different type. For example, on some machines it is possible to address an int only on 2- or 4-byte boundaries, so casting a char pointer to an int pointer could result in an invalid address value.
warn_deprecated_decl (C, C++, ObjC, -Wdeprecated-declaration) if nonzero, issues warning about the use of items marked with the deprecated attribute unless -Wno-deprecated-declarations is specified.
warn_disabled_optimization (-Wdisabled-optimization) if nonzero, issues a warning if a requested optimization is disabled. This circumstance occurs not because of a problem with your code, but because of a limitation within the compiler itself. GCC will refuse to perform optimizations that are too complex and/or will take too long to perform.
warn_missing_noreturn, if nonzero, warns about functions which might be candidates for attribute noreturn.
warn_packed, if nonzero, warns if packed attribute on struct is unnecessary and inefficient.
warn_padded, if nonzero, warns when gcc pads a structure to an alignment boundary.
warn_shadow, if nonzero, means warn about all declarations which shadow others.
warn_switch_default, if nonzero, warns if a switch does not have a default case.
warn_switch_enum, if nonzero, warns if a switch on an enum fails to have a case for every enum value.
warn_system_headers (C, C++, ObjC, -Wsystem-headers), if nonzero, issues warning messages for code in the system header files as well in the program being compiled. Normally warnings caused by system headers are suppressed. To generate warnings about unknown pragmas in system headers it will be necessary to specify -Wunknown-pragmas because using -Wall only checks the pragmas in the program and ignores the ones in the system headers.
warn_notreached, if nonzero, warns about code which is never reached.
common_handle_option (continue)
801 case OPT_aux_info:
802 case OPT_aux_info_:
803 aux_info_file_name = arg;
804 flag_gen_aux_info = 1;
805 break;
806
807 case OPT_auxbase:
808 aux_base_name = arg;
809 break;
810
811 case OPT_auxbase_strip:
812 {
813 char *tmp = xstrdup (arg);
814 strip_off_ending (tmp, strlen (tmp));
815 if (tmp[0])
816 aux_base_name = tmp;
817 }
818 break;
819
820 case OPT_d:
821 decode_d_option (arg);
822 break;
823
824 case OPT_dumpbase:
825 dump_base_name = arg;
826 break;
827
828 case OPT_fPIC:
829 flag_pic = value + value;
830 break;
831
832 case OPT_fPIE:
833 flag_pie = value + value;
834 break;
835
836 case OPT_fabi_version_:
837 flag_abi_version = value;
838 break;
839
840 case OPT_falign_functions:
841 align_functions = !value;
842 break;
843
844 case OPT_falign_functions_:
845 align_functions = value;
846 break;
847
848 case OPT_falign_jumps:
849 align_jumps = !value;
850 break;
851
852 case OPT_falign_jumps_:
853 align_jumps = value;
854 break;
855
856 case OPT_falign_labels:
857 align_labels = !value;
858 break;
859
860 case OPT_falign_labels_:
861 align_labels = value;
862 break;
863
864 case OPT_falign_loops:
865 align_loops = !value;
866 break;
867
868 case OPT_falign_loops_:
869 align_loops = value;
870 break;
871
872 case OPT_fargument_alias:
873 flag_argument_noalias = !value;
874 break;
875
876 case OPT_fargument_noalias:
877 flag_argument_noalias = value;
878 break;
879
880 case OPT_fargument_noalias_global:
881 flag_argument_noalias = value + value;
882 break;
883
884 case OPT_fasynchronous_unwind_tables:
885 flag_asynchronous_unwind_tables = value;
886 break;
887
888 case OPT_fbounds_check:
889 flag_bounds_check = value;
890 break;
891
892 case OPT_fbranch_count_reg:
893 flag_branch_on_count_reg = value;
894 break;
895
896 case OPT_fbranch_probabilities:
897 flag_branch_probabilities_set = true;
898 flag_branch_probabilities = value;
899 break;
900
901 case OPT_fbranch_target_load_optimize:
902 flag_branch_target_load_optimize = value;
903 break;
904
905 case OPT_fbranch_target_load_optimize2:
906 flag_branch_target_load_optimize2 = value;
907 break;
aux_info_file_name (C, -aux-info filename) outputs prototype declarations for all the functions declared or defined in a single compilation unit (a C source file and all the header files it includes) to the named file
flag_gen_aux_info, if nonzero, means we should be saving declaration info into a .X file.
aux_base_name (-auxbase, -auxbase-strip) specify name to use as a base for auxiliary output files.
flag_abi_version (-fabi-version=) indicates the version of the C++ ABI in use. The following values are allowed:
0: The version of the ABI believed most conformant with the C++ ABI specification. This ABI may change as bugs are discovered and fixed. Therefore, 0 will not necessarily indicate the same ABI in different versions of G++.
1: The version of the ABI first used in G++ 3.2.
2: The version of the ABI first used in G++ 3.4.
Additional positive integers will be assigned as new versions of the ABI become the default version of the ABI.
flag_argument_noalias takes following values.
0 if pointer arguments may alias each other. True in C.
1 if pointer arguments may not alias each other but may alias global variables.
2 if pointer arguments may not alias each other and may not alias global variables. True in Fortran.
It defaults to 0 for C. And the value is passed by following switches.
-fargument-alias specifies that arguments passed to functions may be aliases of one another. That is, two or more parameters may represent the same memory location. It is also possible that an argument can be an alias of a global value. This is the default for C, C++, and ObjC.
-fargument-noalias specifies that arguments passed to functions will never be aliases of one another. That is, two or more parameters will not represent the same memory location. However, it is possible that an argument can be an alias of a global value.
-fargument-noalias-global specifies that arguments passed to functions will never be aliases of one another. That is, two or more parameters will not represent the same memory location. It is also not possible that an argument is an alias of a global value. This is the default for Fortran.
flag_bounds_check (-fbounds-check) causes gcc to generate array bounds checks. For C, C++, ObjC: defaults to off. For Java: defaults to on. For Fortran: defaults to off.
flag_branch_on_count_reg (-fbranch-count-reg) if nonzero, means try to replace add -1,compare,branch tupple by a cheaper branch on a count register.
flag_branch_probabilities (-fbranch-probabilities) if nonzero, after using -fprofile-arcs to compile a program and then running it to create the file containing execution counts for each block of code, the program can be compiled again with this option, and the information from the file is used to optimize the code for the branches that are taken most often. Without this information, GCC will guess which path is taken most often to perform optimization. The information is stored in a file with the name as the source and a .da suffix.
flag_branch_target_load_optimize (-fbranch-target-load-optimize) if nonzero, performs target register optimization before prologue/epilogue threading.
flag_branch_target_load_optimize2 (-fbranch-target-load-optimize2) if nonzero, performs target register optimization after prologue/epilogue threading and jump2.