opts.c 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389
  1. /* Command line option handling.
  2. Copyright (C) 2002-2015 Free Software Foundation, Inc.
  3. Contributed by Neil Booth.
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify it under
  6. the terms of the GNU General Public License as published by the Free
  7. Software Foundation; either version 3, or (at your option) any later
  8. version.
  9. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GCC; see the file COPYING3. If not see
  15. <http://www.gnu.org/licenses/>. */
  16. #include "config.h"
  17. #include "system.h"
  18. #include "intl.h"
  19. #include "coretypes.h"
  20. #include "opts.h"
  21. #include "options.h"
  22. #include "tm.h" /* For STACK_CHECK_BUILTIN,
  23. STACK_CHECK_STATIC_BUILTIN, DEFAULT_GDB_EXTENSIONS,
  24. DWARF2_DEBUGGING_INFO and DBX_DEBUGGING_INFO. */
  25. #include "flags.h"
  26. #include "params.h"
  27. #include "diagnostic.h"
  28. #include "opts-diagnostic.h"
  29. #include "insn-attr-common.h"
  30. #include "common/common-target.h"
  31. static void set_Wstrict_aliasing (struct gcc_options *opts, int onoff);
  32. /* Indexed by enum debug_info_type. */
  33. const char *const debug_type_names[] =
  34. {
  35. "none", "stabs", "coff", "dwarf-2", "xcoff", "vms"
  36. };
  37. /* Parse the -femit-struct-debug-detailed option value
  38. and set the flag variables. */
  39. #define MATCH( prefix, string ) \
  40. ((strncmp (prefix, string, sizeof prefix - 1) == 0) \
  41. ? ((string += sizeof prefix - 1), 1) : 0)
  42. void
  43. set_struct_debug_option (struct gcc_options *opts, location_t loc,
  44. const char *spec)
  45. {
  46. /* various labels for comparison */
  47. static const char dfn_lbl[] = "dfn:", dir_lbl[] = "dir:", ind_lbl[] = "ind:";
  48. static const char ord_lbl[] = "ord:", gen_lbl[] = "gen:";
  49. static const char none_lbl[] = "none", any_lbl[] = "any";
  50. static const char base_lbl[] = "base", sys_lbl[] = "sys";
  51. enum debug_struct_file files = DINFO_STRUCT_FILE_ANY;
  52. /* Default is to apply to as much as possible. */
  53. enum debug_info_usage usage = DINFO_USAGE_NUM_ENUMS;
  54. int ord = 1, gen = 1;
  55. /* What usage? */
  56. if (MATCH (dfn_lbl, spec))
  57. usage = DINFO_USAGE_DFN;
  58. else if (MATCH (dir_lbl, spec))
  59. usage = DINFO_USAGE_DIR_USE;
  60. else if (MATCH (ind_lbl, spec))
  61. usage = DINFO_USAGE_IND_USE;
  62. /* Generics or not? */
  63. if (MATCH (ord_lbl, spec))
  64. gen = 0;
  65. else if (MATCH (gen_lbl, spec))
  66. ord = 0;
  67. /* What allowable environment? */
  68. if (MATCH (none_lbl, spec))
  69. files = DINFO_STRUCT_FILE_NONE;
  70. else if (MATCH (any_lbl, spec))
  71. files = DINFO_STRUCT_FILE_ANY;
  72. else if (MATCH (sys_lbl, spec))
  73. files = DINFO_STRUCT_FILE_SYS;
  74. else if (MATCH (base_lbl, spec))
  75. files = DINFO_STRUCT_FILE_BASE;
  76. else
  77. error_at (loc,
  78. "argument %qs to %<-femit-struct-debug-detailed%> "
  79. "not recognized",
  80. spec);
  81. /* Effect the specification. */
  82. if (usage == DINFO_USAGE_NUM_ENUMS)
  83. {
  84. if (ord)
  85. {
  86. opts->x_debug_struct_ordinary[DINFO_USAGE_DFN] = files;
  87. opts->x_debug_struct_ordinary[DINFO_USAGE_DIR_USE] = files;
  88. opts->x_debug_struct_ordinary[DINFO_USAGE_IND_USE] = files;
  89. }
  90. if (gen)
  91. {
  92. opts->x_debug_struct_generic[DINFO_USAGE_DFN] = files;
  93. opts->x_debug_struct_generic[DINFO_USAGE_DIR_USE] = files;
  94. opts->x_debug_struct_generic[DINFO_USAGE_IND_USE] = files;
  95. }
  96. }
  97. else
  98. {
  99. if (ord)
  100. opts->x_debug_struct_ordinary[usage] = files;
  101. if (gen)
  102. opts->x_debug_struct_generic[usage] = files;
  103. }
  104. if (*spec == ',')
  105. set_struct_debug_option (opts, loc, spec+1);
  106. else
  107. {
  108. /* No more -femit-struct-debug-detailed specifications.
  109. Do final checks. */
  110. if (*spec != '\0')
  111. error_at (loc,
  112. "argument %qs to %<-femit-struct-debug-detailed%> unknown",
  113. spec);
  114. if (opts->x_debug_struct_ordinary[DINFO_USAGE_DIR_USE]
  115. < opts->x_debug_struct_ordinary[DINFO_USAGE_IND_USE]
  116. || opts->x_debug_struct_generic[DINFO_USAGE_DIR_USE]
  117. < opts->x_debug_struct_generic[DINFO_USAGE_IND_USE])
  118. error_at (loc,
  119. "%<-femit-struct-debug-detailed=dir:...%> must allow "
  120. "at least as much as "
  121. "%<-femit-struct-debug-detailed=ind:...%>");
  122. }
  123. }
  124. /* Strip off a legitimate source ending from the input string NAME of
  125. length LEN. Rather than having to know the names used by all of
  126. our front ends, we strip off an ending of a period followed by
  127. up to five characters. (Java uses ".class".) */
  128. void
  129. strip_off_ending (char *name, int len)
  130. {
  131. int i;
  132. for (i = 2; i < 6 && len > i; i++)
  133. {
  134. if (name[len - i] == '.')
  135. {
  136. name[len - i] = '\0';
  137. break;
  138. }
  139. }
  140. }
  141. /* Find the base name of a path, stripping off both directories and
  142. a single final extension. */
  143. int
  144. base_of_path (const char *path, const char **base_out)
  145. {
  146. const char *base = path;
  147. const char *dot = 0;
  148. const char *p = path;
  149. char c = *p;
  150. while (c)
  151. {
  152. if (IS_DIR_SEPARATOR (c))
  153. {
  154. base = p + 1;
  155. dot = 0;
  156. }
  157. else if (c == '.')
  158. dot = p;
  159. c = *++p;
  160. }
  161. if (!dot)
  162. dot = p;
  163. *base_out = base;
  164. return dot - base;
  165. }
  166. /* What to print when a switch has no documentation. */
  167. static const char undocumented_msg[] = N_("This switch lacks documentation");
  168. typedef char *char_p; /* For DEF_VEC_P. */
  169. static void handle_param (struct gcc_options *opts,
  170. struct gcc_options *opts_set, location_t loc,
  171. const char *carg);
  172. static void set_debug_level (enum debug_info_type type, int extended,
  173. const char *arg, struct gcc_options *opts,
  174. struct gcc_options *opts_set,
  175. location_t loc);
  176. static void set_fast_math_flags (struct gcc_options *opts, int set);
  177. static void decode_d_option (const char *arg, struct gcc_options *opts,
  178. location_t loc, diagnostic_context *dc);
  179. static void set_unsafe_math_optimizations_flags (struct gcc_options *opts,
  180. int set);
  181. static void enable_warning_as_error (const char *arg, int value,
  182. unsigned int lang_mask,
  183. const struct cl_option_handlers *handlers,
  184. struct gcc_options *opts,
  185. struct gcc_options *opts_set,
  186. location_t loc,
  187. diagnostic_context *dc);
  188. /* Handle a back-end option; arguments and return value as for
  189. handle_option. */
  190. bool
  191. target_handle_option (struct gcc_options *opts,
  192. struct gcc_options *opts_set,
  193. const struct cl_decoded_option *decoded,
  194. unsigned int lang_mask ATTRIBUTE_UNUSED, int kind,
  195. location_t loc,
  196. const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED,
  197. diagnostic_context *dc)
  198. {
  199. gcc_assert (dc == global_dc);
  200. gcc_assert (kind == DK_UNSPECIFIED);
  201. return targetm_common.handle_option (opts, opts_set, decoded, loc);
  202. }
  203. /* Add comma-separated strings to a char_p vector. */
  204. static void
  205. add_comma_separated_to_vector (void **pvec, const char *arg)
  206. {
  207. char *tmp;
  208. char *r;
  209. char *w;
  210. char *token_start;
  211. vec<char_p> *v = (vec<char_p> *) *pvec;
  212. vec_check_alloc (v, 1);
  213. /* We never free this string. */
  214. tmp = xstrdup (arg);
  215. r = tmp;
  216. w = tmp;
  217. token_start = tmp;
  218. while (*r != '\0')
  219. {
  220. if (*r == ',')
  221. {
  222. *w++ = '\0';
  223. ++r;
  224. v->safe_push (token_start);
  225. token_start = w;
  226. }
  227. if (*r == '\\' && r[1] == ',')
  228. {
  229. *w++ = ',';
  230. r += 2;
  231. }
  232. else
  233. *w++ = *r++;
  234. }
  235. if (*token_start != '\0')
  236. v->safe_push (token_start);
  237. *pvec = v;
  238. }
  239. /* Initialize OPTS and OPTS_SET before using them in parsing options. */
  240. void
  241. init_options_struct (struct gcc_options *opts, struct gcc_options *opts_set)
  242. {
  243. size_t num_params = get_num_compiler_params ();
  244. gcc_obstack_init (&opts_obstack);
  245. *opts = global_options_init;
  246. if (opts_set)
  247. memset (opts_set, 0, sizeof (*opts_set));
  248. opts->x_param_values = XNEWVEC (int, num_params);
  249. if (opts_set)
  250. opts_set->x_param_values = XCNEWVEC (int, num_params);
  251. init_param_values (opts->x_param_values);
  252. /* Initialize whether `char' is signed. */
  253. opts->x_flag_signed_char = DEFAULT_SIGNED_CHAR;
  254. /* Set this to a special "uninitialized" value. The actual default
  255. is set after target options have been processed. */
  256. opts->x_flag_short_enums = 2;
  257. /* Initialize target_flags before default_options_optimization
  258. so the latter can modify it. */
  259. opts->x_target_flags = targetm_common.default_target_flags;
  260. /* Some targets have ABI-specified unwind tables. */
  261. opts->x_flag_unwind_tables = targetm_common.unwind_tables_default;
  262. /* Some targets have other target-specific initialization. */
  263. targetm_common.option_init_struct (opts);
  264. }
  265. /* Release any allocations owned by OPTS. */
  266. void
  267. finalize_options_struct (struct gcc_options *opts)
  268. {
  269. XDELETEVEC (opts->x_param_values);
  270. }
  271. /* If indicated by the optimization level LEVEL (-Os if SIZE is set,
  272. -Ofast if FAST is set, -Og if DEBUG is set), apply the option DEFAULT_OPT
  273. to OPTS and OPTS_SET, diagnostic context DC, location LOC, with language
  274. mask LANG_MASK and option handlers HANDLERS. */
  275. static void
  276. maybe_default_option (struct gcc_options *opts,
  277. struct gcc_options *opts_set,
  278. const struct default_options *default_opt,
  279. int level, bool size, bool fast, bool debug,
  280. unsigned int lang_mask,
  281. const struct cl_option_handlers *handlers,
  282. location_t loc,
  283. diagnostic_context *dc)
  284. {
  285. const struct cl_option *option = &cl_options[default_opt->opt_index];
  286. bool enabled;
  287. if (size)
  288. gcc_assert (level == 2);
  289. if (fast)
  290. gcc_assert (level == 3);
  291. if (debug)
  292. gcc_assert (level == 1);
  293. switch (default_opt->levels)
  294. {
  295. case OPT_LEVELS_ALL:
  296. enabled = true;
  297. break;
  298. case OPT_LEVELS_0_ONLY:
  299. enabled = (level == 0);
  300. break;
  301. case OPT_LEVELS_1_PLUS:
  302. enabled = (level >= 1);
  303. break;
  304. case OPT_LEVELS_1_PLUS_SPEED_ONLY:
  305. enabled = (level >= 1 && !size && !debug);
  306. break;
  307. case OPT_LEVELS_1_PLUS_NOT_DEBUG:
  308. enabled = (level >= 1 && !debug);
  309. break;
  310. case OPT_LEVELS_2_PLUS:
  311. enabled = (level >= 2);
  312. break;
  313. case OPT_LEVELS_2_PLUS_SPEED_ONLY:
  314. enabled = (level >= 2 && !size && !debug);
  315. break;
  316. case OPT_LEVELS_3_PLUS:
  317. enabled = (level >= 3);
  318. break;
  319. case OPT_LEVELS_3_PLUS_AND_SIZE:
  320. enabled = (level >= 3 || size);
  321. break;
  322. case OPT_LEVELS_SIZE:
  323. enabled = size;
  324. break;
  325. case OPT_LEVELS_FAST:
  326. enabled = fast;
  327. break;
  328. case OPT_LEVELS_NONE:
  329. default:
  330. gcc_unreachable ();
  331. }
  332. if (enabled)
  333. handle_generated_option (opts, opts_set, default_opt->opt_index,
  334. default_opt->arg, default_opt->value,
  335. lang_mask, DK_UNSPECIFIED, loc,
  336. handlers, dc);
  337. else if (default_opt->arg == NULL
  338. && !option->cl_reject_negative)
  339. handle_generated_option (opts, opts_set, default_opt->opt_index,
  340. default_opt->arg, !default_opt->value,
  341. lang_mask, DK_UNSPECIFIED, loc,
  342. handlers, dc);
  343. }
  344. /* As indicated by the optimization level LEVEL (-Os if SIZE is set,
  345. -Ofast if FAST is set), apply the options in array DEFAULT_OPTS to
  346. OPTS and OPTS_SET, diagnostic context DC, location LOC, with
  347. language mask LANG_MASK and option handlers HANDLERS. */
  348. static void
  349. maybe_default_options (struct gcc_options *opts,
  350. struct gcc_options *opts_set,
  351. const struct default_options *default_opts,
  352. int level, bool size, bool fast, bool debug,
  353. unsigned int lang_mask,
  354. const struct cl_option_handlers *handlers,
  355. location_t loc,
  356. diagnostic_context *dc)
  357. {
  358. size_t i;
  359. for (i = 0; default_opts[i].levels != OPT_LEVELS_NONE; i++)
  360. maybe_default_option (opts, opts_set, &default_opts[i],
  361. level, size, fast, debug,
  362. lang_mask, handlers, loc, dc);
  363. }
  364. /* Table of options enabled by default at different levels. */
  365. static const struct default_options default_options_table[] =
  366. {
  367. /* -O1 optimizations. */
  368. { OPT_LEVELS_1_PLUS, OPT_fdefer_pop, NULL, 1 },
  369. #ifdef DELAY_SLOTS
  370. { OPT_LEVELS_1_PLUS, OPT_fdelayed_branch, NULL, 1 },
  371. #endif
  372. { OPT_LEVELS_1_PLUS, OPT_fguess_branch_probability, NULL, 1 },
  373. { OPT_LEVELS_1_PLUS, OPT_fcprop_registers, NULL, 1 },
  374. { OPT_LEVELS_1_PLUS, OPT_fforward_propagate, NULL, 1 },
  375. { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fif_conversion, NULL, 1 },
  376. { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fif_conversion2, NULL, 1 },
  377. { OPT_LEVELS_1_PLUS, OPT_fipa_pure_const, NULL, 1 },
  378. { OPT_LEVELS_1_PLUS, OPT_fipa_reference, NULL, 1 },
  379. { OPT_LEVELS_1_PLUS, OPT_fipa_profile, NULL, 1 },
  380. { OPT_LEVELS_1_PLUS, OPT_fmerge_constants, NULL, 1 },
  381. { OPT_LEVELS_1_PLUS, OPT_fshrink_wrap, NULL, 1 },
  382. { OPT_LEVELS_1_PLUS, OPT_fsplit_wide_types, NULL, 1 },
  383. { OPT_LEVELS_1_PLUS, OPT_ftree_ccp, NULL, 1 },
  384. { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_ftree_bit_ccp, NULL, 1 },
  385. { OPT_LEVELS_1_PLUS, OPT_ftree_dce, NULL, 1 },
  386. { OPT_LEVELS_1_PLUS, OPT_ftree_dominator_opts, NULL, 1 },
  387. { OPT_LEVELS_1_PLUS, OPT_ftree_dse, NULL, 1 },
  388. { OPT_LEVELS_1_PLUS, OPT_ftree_ter, NULL, 1 },
  389. { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_ftree_sra, NULL, 1 },
  390. { OPT_LEVELS_1_PLUS, OPT_ftree_copyrename, NULL, 1 },
  391. { OPT_LEVELS_1_PLUS, OPT_ftree_fre, NULL, 1 },
  392. { OPT_LEVELS_1_PLUS, OPT_ftree_copy_prop, NULL, 1 },
  393. { OPT_LEVELS_1_PLUS, OPT_ftree_sink, NULL, 1 },
  394. { OPT_LEVELS_1_PLUS, OPT_ftree_ch, NULL, 1 },
  395. { OPT_LEVELS_1_PLUS, OPT_fcombine_stack_adjustments, NULL, 1 },
  396. { OPT_LEVELS_1_PLUS, OPT_fcompare_elim, NULL, 1 },
  397. { OPT_LEVELS_1_PLUS, OPT_ftree_slsr, NULL, 1 },
  398. { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fbranch_count_reg, NULL, 1 },
  399. { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fmove_loop_invariants, NULL, 1 },
  400. { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_ftree_pta, NULL, 1 },
  401. { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fssa_phiopt, NULL, 1 },
  402. /* -O2 optimizations. */
  403. { OPT_LEVELS_2_PLUS, OPT_finline_small_functions, NULL, 1 },
  404. { OPT_LEVELS_2_PLUS, OPT_findirect_inlining, NULL, 1 },
  405. { OPT_LEVELS_2_PLUS, OPT_fpartial_inlining, NULL, 1 },
  406. { OPT_LEVELS_2_PLUS, OPT_fthread_jumps, NULL, 1 },
  407. { OPT_LEVELS_2_PLUS, OPT_fcrossjumping, NULL, 1 },
  408. { OPT_LEVELS_2_PLUS, OPT_foptimize_sibling_calls, NULL, 1 },
  409. { OPT_LEVELS_2_PLUS, OPT_fcse_follow_jumps, NULL, 1 },
  410. { OPT_LEVELS_2_PLUS, OPT_fgcse, NULL, 1 },
  411. { OPT_LEVELS_2_PLUS, OPT_fexpensive_optimizations, NULL, 1 },
  412. { OPT_LEVELS_2_PLUS, OPT_frerun_cse_after_loop, NULL, 1 },
  413. { OPT_LEVELS_2_PLUS, OPT_fcaller_saves, NULL, 1 },
  414. { OPT_LEVELS_2_PLUS, OPT_fpeephole2, NULL, 1 },
  415. #ifdef INSN_SCHEDULING
  416. /* Only run the pre-regalloc scheduling pass if optimizing for speed. */
  417. { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_fschedule_insns, NULL, 1 },
  418. { OPT_LEVELS_2_PLUS, OPT_fschedule_insns2, NULL, 1 },
  419. #endif
  420. { OPT_LEVELS_2_PLUS, OPT_fstrict_aliasing, NULL, 1 },
  421. { OPT_LEVELS_2_PLUS, OPT_fstrict_overflow, NULL, 1 },
  422. { OPT_LEVELS_2_PLUS, OPT_freorder_blocks, NULL, 1 },
  423. { OPT_LEVELS_2_PLUS, OPT_freorder_functions, NULL, 1 },
  424. { OPT_LEVELS_2_PLUS, OPT_ftree_vrp, NULL, 1 },
  425. { OPT_LEVELS_2_PLUS, OPT_ftree_builtin_call_dce, NULL, 1 },
  426. { OPT_LEVELS_2_PLUS, OPT_ftree_pre, NULL, 1 },
  427. { OPT_LEVELS_2_PLUS, OPT_ftree_switch_conversion, NULL, 1 },
  428. { OPT_LEVELS_2_PLUS, OPT_fipa_cp, NULL, 1 },
  429. { OPT_LEVELS_2_PLUS, OPT_fipa_cp_alignment, NULL, 1 },
  430. { OPT_LEVELS_2_PLUS, OPT_fdevirtualize, NULL, 1 },
  431. { OPT_LEVELS_2_PLUS, OPT_fdevirtualize_speculatively, NULL, 1 },
  432. { OPT_LEVELS_2_PLUS, OPT_fipa_sra, NULL, 1 },
  433. { OPT_LEVELS_2_PLUS, OPT_falign_loops, NULL, 1 },
  434. { OPT_LEVELS_2_PLUS, OPT_falign_jumps, NULL, 1 },
  435. { OPT_LEVELS_2_PLUS, OPT_falign_labels, NULL, 1 },
  436. { OPT_LEVELS_2_PLUS, OPT_falign_functions, NULL, 1 },
  437. { OPT_LEVELS_2_PLUS, OPT_ftree_tail_merge, NULL, 1 },
  438. { OPT_LEVELS_2_PLUS, OPT_fvect_cost_model_, NULL, VECT_COST_MODEL_CHEAP },
  439. { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_foptimize_strlen, NULL, 1 },
  440. { OPT_LEVELS_2_PLUS, OPT_fhoist_adjacent_loads, NULL, 1 },
  441. { OPT_LEVELS_2_PLUS, OPT_fipa_icf, NULL, 1 },
  442. { OPT_LEVELS_2_PLUS, OPT_fisolate_erroneous_paths_dereference, NULL, 1 },
  443. { OPT_LEVELS_2_PLUS, OPT_fipa_ra, NULL, 1 },
  444. { OPT_LEVELS_2_PLUS, OPT_flra_remat, NULL, 1 },
  445. /* -O3 optimizations. */
  446. { OPT_LEVELS_3_PLUS, OPT_ftree_loop_distribute_patterns, NULL, 1 },
  447. { OPT_LEVELS_3_PLUS, OPT_fpredictive_commoning, NULL, 1 },
  448. /* Inlining of functions reducing size is a good idea with -Os
  449. regardless of them being declared inline. */
  450. { OPT_LEVELS_3_PLUS_AND_SIZE, OPT_finline_functions, NULL, 1 },
  451. { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_finline_functions_called_once, NULL, 1 },
  452. { OPT_LEVELS_3_PLUS, OPT_funswitch_loops, NULL, 1 },
  453. { OPT_LEVELS_3_PLUS, OPT_fgcse_after_reload, NULL, 1 },
  454. { OPT_LEVELS_3_PLUS, OPT_ftree_loop_vectorize, NULL, 1 },
  455. { OPT_LEVELS_3_PLUS, OPT_ftree_slp_vectorize, NULL, 1 },
  456. { OPT_LEVELS_3_PLUS, OPT_fvect_cost_model_, NULL, VECT_COST_MODEL_DYNAMIC },
  457. { OPT_LEVELS_3_PLUS, OPT_fipa_cp_clone, NULL, 1 },
  458. { OPT_LEVELS_3_PLUS, OPT_ftree_partial_pre, NULL, 1 },
  459. /* -Ofast adds optimizations to -O3. */
  460. { OPT_LEVELS_FAST, OPT_ffast_math, NULL, 1 },
  461. { OPT_LEVELS_NONE, 0, NULL, 0 }
  462. };
  463. /* Default the options in OPTS and OPTS_SET based on the optimization
  464. settings in DECODED_OPTIONS and DECODED_OPTIONS_COUNT. */
  465. void
  466. default_options_optimization (struct gcc_options *opts,
  467. struct gcc_options *opts_set,
  468. struct cl_decoded_option *decoded_options,
  469. unsigned int decoded_options_count,
  470. location_t loc,
  471. unsigned int lang_mask,
  472. const struct cl_option_handlers *handlers,
  473. diagnostic_context *dc)
  474. {
  475. unsigned int i;
  476. int opt2;
  477. /* Scan to see what optimization level has been specified. That will
  478. determine the default value of many flags. */
  479. for (i = 1; i < decoded_options_count; i++)
  480. {
  481. struct cl_decoded_option *opt = &decoded_options[i];
  482. switch (opt->opt_index)
  483. {
  484. case OPT_O:
  485. if (*opt->arg == '\0')
  486. {
  487. opts->x_optimize = 1;
  488. opts->x_optimize_size = 0;
  489. opts->x_optimize_fast = 0;
  490. opts->x_optimize_debug = 0;
  491. }
  492. else
  493. {
  494. const int optimize_val = integral_argument (opt->arg);
  495. if (optimize_val == -1)
  496. error_at (loc, "argument to %<-O%> should be a non-negative "
  497. "integer, %<g%>, %<s%> or %<fast%>");
  498. else
  499. {
  500. opts->x_optimize = optimize_val;
  501. if ((unsigned int) opts->x_optimize > 255)
  502. opts->x_optimize = 255;
  503. opts->x_optimize_size = 0;
  504. opts->x_optimize_fast = 0;
  505. opts->x_optimize_debug = 0;
  506. }
  507. }
  508. break;
  509. case OPT_Os:
  510. opts->x_optimize_size = 1;
  511. /* Optimizing for size forces optimize to be 2. */
  512. opts->x_optimize = 2;
  513. opts->x_optimize_fast = 0;
  514. opts->x_optimize_debug = 0;
  515. break;
  516. case OPT_Ofast:
  517. /* -Ofast only adds flags to -O3. */
  518. opts->x_optimize_size = 0;
  519. opts->x_optimize = 3;
  520. opts->x_optimize_fast = 1;
  521. opts->x_optimize_debug = 0;
  522. break;
  523. case OPT_Og:
  524. /* -Og selects optimization level 1. */
  525. opts->x_optimize_size = 0;
  526. opts->x_optimize = 1;
  527. opts->x_optimize_fast = 0;
  528. opts->x_optimize_debug = 1;
  529. break;
  530. default:
  531. /* Ignore other options in this prescan. */
  532. break;
  533. }
  534. }
  535. maybe_default_options (opts, opts_set, default_options_table,
  536. opts->x_optimize, opts->x_optimize_size,
  537. opts->x_optimize_fast, opts->x_optimize_debug,
  538. lang_mask, handlers, loc, dc);
  539. /* -O2 param settings. */
  540. opt2 = (opts->x_optimize >= 2);
  541. /* Track fields in field-sensitive alias analysis. */
  542. maybe_set_param_value
  543. (PARAM_MAX_FIELDS_FOR_FIELD_SENSITIVE,
  544. opt2 ? 100 : default_param_value (PARAM_MAX_FIELDS_FOR_FIELD_SENSITIVE),
  545. opts->x_param_values, opts_set->x_param_values);
  546. /* For -O1 only do loop invariant motion for very small loops. */
  547. maybe_set_param_value
  548. (PARAM_LOOP_INVARIANT_MAX_BBS_IN_LOOP,
  549. opt2 ? default_param_value (PARAM_LOOP_INVARIANT_MAX_BBS_IN_LOOP) : 1000,
  550. opts->x_param_values, opts_set->x_param_values);
  551. /* At -Ofast, allow store motion to introduce potential race conditions. */
  552. maybe_set_param_value
  553. (PARAM_ALLOW_STORE_DATA_RACES,
  554. opts->x_optimize_fast ? 1
  555. : default_param_value (PARAM_ALLOW_STORE_DATA_RACES),
  556. opts->x_param_values, opts_set->x_param_values);
  557. if (opts->x_optimize_size)
  558. /* We want to crossjump as much as possible. */
  559. maybe_set_param_value (PARAM_MIN_CROSSJUMP_INSNS, 1,
  560. opts->x_param_values, opts_set->x_param_values);
  561. else
  562. maybe_set_param_value (PARAM_MIN_CROSSJUMP_INSNS,
  563. default_param_value (PARAM_MIN_CROSSJUMP_INSNS),
  564. opts->x_param_values, opts_set->x_param_values);
  565. /* Restrict the amount of work combine does at -Og while retaining
  566. most of its useful transforms. */
  567. if (opts->x_optimize_debug)
  568. maybe_set_param_value (PARAM_MAX_COMBINE_INSNS, 2,
  569. opts->x_param_values, opts_set->x_param_values);
  570. /* Allow default optimizations to be specified on a per-machine basis. */
  571. maybe_default_options (opts, opts_set,
  572. targetm_common.option_optimization_table,
  573. opts->x_optimize, opts->x_optimize_size,
  574. opts->x_optimize_fast, opts->x_optimize_debug,
  575. lang_mask, handlers, loc, dc);
  576. }
  577. /* After all options at LOC have been read into OPTS and OPTS_SET,
  578. finalize settings of those options and diagnose incompatible
  579. combinations. */
  580. void
  581. finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
  582. location_t loc)
  583. {
  584. enum unwind_info_type ui_except;
  585. if (opts->x_dump_base_name
  586. && ! IS_ABSOLUTE_PATH (opts->x_dump_base_name)
  587. && ! opts->x_dump_base_name_prefixed)
  588. {
  589. /* First try to make OPTS->X_DUMP_BASE_NAME relative to the
  590. OPTS->X_DUMP_DIR_NAME directory. Then try to make
  591. OPTS->X_DUMP_BASE_NAME relative to the OPTS->X_AUX_BASE_NAME
  592. directory, typically the directory to contain the object
  593. file. */
  594. if (opts->x_dump_dir_name)
  595. opts->x_dump_base_name = opts_concat (opts->x_dump_dir_name,
  596. opts->x_dump_base_name, NULL);
  597. else if (opts->x_aux_base_name
  598. && strcmp (opts->x_aux_base_name, HOST_BIT_BUCKET) != 0)
  599. {
  600. const char *aux_base;
  601. base_of_path (opts->x_aux_base_name, &aux_base);
  602. if (opts->x_aux_base_name != aux_base)
  603. {
  604. int dir_len = aux_base - opts->x_aux_base_name;
  605. char *new_dump_base_name
  606. = XOBNEWVEC (&opts_obstack, char,
  607. strlen (opts->x_dump_base_name) + dir_len + 1);
  608. /* Copy directory component from OPTS->X_AUX_BASE_NAME. */
  609. memcpy (new_dump_base_name, opts->x_aux_base_name, dir_len);
  610. /* Append existing OPTS->X_DUMP_BASE_NAME. */
  611. strcpy (new_dump_base_name + dir_len, opts->x_dump_base_name);
  612. opts->x_dump_base_name = new_dump_base_name;
  613. }
  614. }
  615. opts->x_dump_base_name_prefixed = true;
  616. }
  617. /* Handle related options for unit-at-a-time, toplevel-reorder, and
  618. section-anchors. */
  619. if (!opts->x_flag_unit_at_a_time)
  620. {
  621. if (opts->x_flag_section_anchors && opts_set->x_flag_section_anchors)
  622. error_at (loc, "section anchors must be disabled when unit-at-a-time "
  623. "is disabled");
  624. opts->x_flag_section_anchors = 0;
  625. if (opts->x_flag_toplevel_reorder == 1)
  626. error_at (loc, "toplevel reorder must be disabled when unit-at-a-time "
  627. "is disabled");
  628. opts->x_flag_toplevel_reorder = 0;
  629. }
  630. if (opts->x_flag_tm && opts->x_flag_non_call_exceptions)
  631. sorry ("transactional memory is not supported with non-call exceptions");
  632. /* Unless the user has asked for section anchors, we disable toplevel
  633. reordering at -O0 to disable transformations that might be surprising
  634. to end users and to get -fno-toplevel-reorder tested. */
  635. if (!opts->x_optimize
  636. && opts->x_flag_toplevel_reorder == 2
  637. && !(opts->x_flag_section_anchors && opts_set->x_flag_section_anchors))
  638. {
  639. opts->x_flag_toplevel_reorder = 0;
  640. opts->x_flag_section_anchors = 0;
  641. }
  642. if (!opts->x_flag_toplevel_reorder)
  643. {
  644. if (opts->x_flag_section_anchors && opts_set->x_flag_section_anchors)
  645. error_at (loc, "section anchors must be disabled when toplevel reorder"
  646. " is disabled");
  647. opts->x_flag_section_anchors = 0;
  648. }
  649. if (!opts->x_flag_opts_finished)
  650. {
  651. if (opts->x_flag_pie)
  652. opts->x_flag_pic = opts->x_flag_pie;
  653. if (opts->x_flag_pic && !opts->x_flag_pie)
  654. opts->x_flag_shlib = 1;
  655. opts->x_flag_opts_finished = true;
  656. }
  657. if (opts->x_optimize == 0)
  658. {
  659. /* Inlining does not work if not optimizing,
  660. so force it not to be done. */
  661. opts->x_warn_inline = 0;
  662. opts->x_flag_no_inline = 1;
  663. }
  664. /* The optimization to partition hot and cold basic blocks into separate
  665. sections of the .o and executable files does not work (currently)
  666. with exception handling. This is because there is no support for
  667. generating unwind info. If opts->x_flag_exceptions is turned on
  668. we need to turn off the partitioning optimization. */
  669. ui_except = targetm_common.except_unwind_info (opts);
  670. if (opts->x_flag_exceptions
  671. && opts->x_flag_reorder_blocks_and_partition
  672. && (ui_except == UI_SJLJ || ui_except >= UI_TARGET))
  673. {
  674. if (opts_set->x_flag_reorder_blocks_and_partition)
  675. inform (loc,
  676. "-freorder-blocks-and-partition does not work "
  677. "with exceptions on this architecture");
  678. opts->x_flag_reorder_blocks_and_partition = 0;
  679. opts->x_flag_reorder_blocks = 1;
  680. }
  681. /* If user requested unwind info, then turn off the partitioning
  682. optimization. */
  683. if (opts->x_flag_unwind_tables
  684. && !targetm_common.unwind_tables_default
  685. && opts->x_flag_reorder_blocks_and_partition
  686. && (ui_except == UI_SJLJ || ui_except >= UI_TARGET))
  687. {
  688. if (opts_set->x_flag_reorder_blocks_and_partition)
  689. inform (loc,
  690. "-freorder-blocks-and-partition does not support "
  691. "unwind info on this architecture");
  692. opts->x_flag_reorder_blocks_and_partition = 0;
  693. opts->x_flag_reorder_blocks = 1;
  694. }
  695. /* If the target requested unwind info, then turn off the partitioning
  696. optimization with a different message. Likewise, if the target does not
  697. support named sections. */
  698. if (opts->x_flag_reorder_blocks_and_partition
  699. && (!targetm_common.have_named_sections
  700. || (opts->x_flag_unwind_tables
  701. && targetm_common.unwind_tables_default
  702. && (ui_except == UI_SJLJ || ui_except >= UI_TARGET))))
  703. {
  704. if (opts_set->x_flag_reorder_blocks_and_partition)
  705. inform (loc,
  706. "-freorder-blocks-and-partition does not work "
  707. "on this architecture");
  708. opts->x_flag_reorder_blocks_and_partition = 0;
  709. opts->x_flag_reorder_blocks = 1;
  710. }
  711. if (opts->x_flag_reorder_blocks_and_partition
  712. && !opts_set->x_flag_reorder_functions)
  713. opts->x_flag_reorder_functions = 1;
  714. /* Pipelining of outer loops is only possible when general pipelining
  715. capabilities are requested. */
  716. if (!opts->x_flag_sel_sched_pipelining)
  717. opts->x_flag_sel_sched_pipelining_outer_loops = 0;
  718. if (opts->x_flag_conserve_stack)
  719. {
  720. maybe_set_param_value (PARAM_LARGE_STACK_FRAME, 100,
  721. opts->x_param_values, opts_set->x_param_values);
  722. maybe_set_param_value (PARAM_STACK_FRAME_GROWTH, 40,
  723. opts->x_param_values, opts_set->x_param_values);
  724. }
  725. if (opts->x_flag_lto)
  726. {
  727. #ifdef ENABLE_LTO
  728. opts->x_flag_generate_lto = 1;
  729. /* When generating IL, do not operate in whole-program mode.
  730. Otherwise, symbols will be privatized too early, causing link
  731. errors later. */
  732. opts->x_flag_whole_program = 0;
  733. #else
  734. error_at (loc, "LTO support has not been enabled in this configuration");
  735. #endif
  736. if (!opts->x_flag_fat_lto_objects
  737. && (!HAVE_LTO_PLUGIN
  738. || (opts_set->x_flag_use_linker_plugin
  739. && !opts->x_flag_use_linker_plugin)))
  740. {
  741. if (opts_set->x_flag_fat_lto_objects)
  742. error_at (loc, "-fno-fat-lto-objects are supported only with linker plugin");
  743. opts->x_flag_fat_lto_objects = 1;
  744. }
  745. }
  746. /* We initialize opts->x_flag_split_stack to -1 so that targets can set a
  747. default value if they choose based on other options. */
  748. if (opts->x_flag_split_stack == -1)
  749. opts->x_flag_split_stack = 0;
  750. else if (opts->x_flag_split_stack)
  751. {
  752. if (!targetm_common.supports_split_stack (true, opts))
  753. {
  754. error_at (loc, "%<-fsplit-stack%> is not supported by "
  755. "this compiler configuration");
  756. opts->x_flag_split_stack = 0;
  757. }
  758. }
  759. /* Tune vectorization related parametees according to cost model. */
  760. if (opts->x_flag_vect_cost_model == VECT_COST_MODEL_CHEAP)
  761. {
  762. maybe_set_param_value (PARAM_VECT_MAX_VERSION_FOR_ALIAS_CHECKS,
  763. 6, opts->x_param_values, opts_set->x_param_values);
  764. maybe_set_param_value (PARAM_VECT_MAX_VERSION_FOR_ALIGNMENT_CHECKS,
  765. 0, opts->x_param_values, opts_set->x_param_values);
  766. maybe_set_param_value (PARAM_VECT_MAX_PEELING_FOR_ALIGNMENT,
  767. 0, opts->x_param_values, opts_set->x_param_values);
  768. }
  769. /* Set PARAM_MAX_STORES_TO_SINK to 0 if either vectorization or if-conversion
  770. is disabled. */
  771. if ((!opts->x_flag_tree_loop_vectorize && !opts->x_flag_tree_slp_vectorize)
  772. || !opts->x_flag_tree_loop_if_convert)
  773. maybe_set_param_value (PARAM_MAX_STORES_TO_SINK, 0,
  774. opts->x_param_values, opts_set->x_param_values);
  775. /* The -gsplit-dwarf option requires -ggnu-pubnames. */
  776. if (opts->x_dwarf_split_debug_info)
  777. opts->x_debug_generate_pub_sections = 2;
  778. /* Userspace and kernel ASan conflict with each other. */
  779. if ((opts->x_flag_sanitize & SANITIZE_USER_ADDRESS)
  780. && (opts->x_flag_sanitize & SANITIZE_KERNEL_ADDRESS))
  781. error_at (loc,
  782. "-fsanitize=address is incompatible with "
  783. "-fsanitize=kernel-address");
  784. /* And with TSan. */
  785. if ((opts->x_flag_sanitize & SANITIZE_ADDRESS)
  786. && (opts->x_flag_sanitize & SANITIZE_THREAD))
  787. error_at (loc,
  788. "-fsanitize=address and -fsanitize=kernel-address "
  789. "are incompatible with -fsanitize=thread");
  790. /* Error recovery is not allowed for ASan and TSan. */
  791. if (opts->x_flag_sanitize_recover & SANITIZE_USER_ADDRESS)
  792. error_at (loc, "-fsanitize-recover=address is not supported");
  793. if (opts->x_flag_sanitize_recover & SANITIZE_THREAD)
  794. error_at (loc, "-fsanitize-recover=thread is not supported");
  795. if (opts->x_flag_sanitize_recover & SANITIZE_LEAK)
  796. error_at (loc, "-fsanitize-recover=leak is not supported");
  797. /* When instrumenting the pointers, we don't want to remove
  798. the null pointer checks. */
  799. if (opts->x_flag_sanitize & (SANITIZE_NULL | SANITIZE_NONNULL_ATTRIBUTE
  800. | SANITIZE_RETURNS_NONNULL_ATTRIBUTE))
  801. opts->x_flag_delete_null_pointer_checks = 0;
  802. /* Aggressive compiler optimizations may cause false negatives. */
  803. if (opts->x_flag_sanitize)
  804. {
  805. opts->x_flag_aggressive_loop_optimizations = 0;
  806. opts->x_flag_strict_overflow = 0;
  807. }
  808. }
  809. #define LEFT_COLUMN 27
  810. /* Output ITEM, of length ITEM_WIDTH, in the left column,
  811. followed by word-wrapped HELP in a second column. */
  812. static void
  813. wrap_help (const char *help,
  814. const char *item,
  815. unsigned int item_width,
  816. unsigned int columns)
  817. {
  818. unsigned int col_width = LEFT_COLUMN;
  819. unsigned int remaining, room, len;
  820. remaining = strlen (help);
  821. do
  822. {
  823. room = columns - 3 - MAX (col_width, item_width);
  824. if (room > columns)
  825. room = 0;
  826. len = remaining;
  827. if (room < len)
  828. {
  829. unsigned int i;
  830. for (i = 0; help[i]; i++)
  831. {
  832. if (i >= room && len != remaining)
  833. break;
  834. if (help[i] == ' ')
  835. len = i;
  836. else if ((help[i] == '-' || help[i] == '/')
  837. && help[i + 1] != ' '
  838. && i > 0 && ISALPHA (help[i - 1]))
  839. len = i + 1;
  840. }
  841. }
  842. printf (" %-*.*s %.*s\n", col_width, item_width, item, len, help);
  843. item_width = 0;
  844. while (help[len] == ' ')
  845. len++;
  846. help += len;
  847. remaining -= len;
  848. }
  849. while (remaining);
  850. }
  851. /* Print help for a specific front-end, etc. */
  852. static void
  853. print_filtered_help (unsigned int include_flags,
  854. unsigned int exclude_flags,
  855. unsigned int any_flags,
  856. unsigned int columns,
  857. struct gcc_options *opts,
  858. unsigned int lang_mask)
  859. {
  860. unsigned int i;
  861. const char *help;
  862. bool found = false;
  863. bool displayed = false;
  864. char new_help[128];
  865. if (include_flags == CL_PARAMS)
  866. {
  867. for (i = 0; i < LAST_PARAM; i++)
  868. {
  869. const char *param = compiler_params[i].option;
  870. help = compiler_params[i].help;
  871. if (help == NULL || *help == '\0')
  872. {
  873. if (exclude_flags & CL_UNDOCUMENTED)
  874. continue;
  875. help = undocumented_msg;
  876. }
  877. /* Get the translation. */
  878. help = _(help);
  879. if (!opts->x_quiet_flag)
  880. {
  881. snprintf (new_help, sizeof (new_help),
  882. _("default %d minimum %d maximum %d"),
  883. compiler_params[i].default_value,
  884. compiler_params[i].min_value,
  885. compiler_params[i].max_value);
  886. help = new_help;
  887. }
  888. wrap_help (help, param, strlen (param), columns);
  889. }
  890. putchar ('\n');
  891. return;
  892. }
  893. if (!opts->x_help_printed)
  894. opts->x_help_printed = XCNEWVAR (char, cl_options_count);
  895. if (!opts->x_help_enum_printed)
  896. opts->x_help_enum_printed = XCNEWVAR (char, cl_enums_count);
  897. for (i = 0; i < cl_options_count; i++)
  898. {
  899. const struct cl_option *option = cl_options + i;
  900. unsigned int len;
  901. const char *opt;
  902. const char *tab;
  903. if (include_flags == 0
  904. || ((option->flags & include_flags) != include_flags))
  905. {
  906. if ((option->flags & any_flags) == 0)
  907. continue;
  908. }
  909. /* Skip unwanted switches. */
  910. if ((option->flags & exclude_flags) != 0)
  911. continue;
  912. /* The driver currently prints its own help text. */
  913. if ((option->flags & CL_DRIVER) != 0
  914. && (option->flags & (((1U << cl_lang_count) - 1)
  915. | CL_COMMON | CL_TARGET)) == 0)
  916. continue;
  917. found = true;
  918. /* Skip switches that have already been printed. */
  919. if (opts->x_help_printed[i])
  920. continue;
  921. opts->x_help_printed[i] = true;
  922. help = option->help;
  923. if (help == NULL)
  924. {
  925. if (exclude_flags & CL_UNDOCUMENTED)
  926. continue;
  927. help = undocumented_msg;
  928. }
  929. /* Get the translation. */
  930. help = _(help);
  931. /* Find the gap between the name of the
  932. option and its descriptive text. */
  933. tab = strchr (help, '\t');
  934. if (tab)
  935. {
  936. len = tab - help;
  937. opt = help;
  938. help = tab + 1;
  939. }
  940. else
  941. {
  942. opt = option->opt_text;
  943. len = strlen (opt);
  944. }
  945. /* With the -Q option enabled we change the descriptive text associated
  946. with an option to be an indication of its current setting. */
  947. if (!opts->x_quiet_flag)
  948. {
  949. void *flag_var = option_flag_var (i, opts);
  950. if (len < (LEFT_COLUMN + 2))
  951. strcpy (new_help, "\t\t");
  952. else
  953. strcpy (new_help, "\t");
  954. if (flag_var != NULL
  955. && option->var_type != CLVC_DEFER)
  956. {
  957. if (option->flags & CL_JOINED)
  958. {
  959. if (option->var_type == CLVC_STRING)
  960. {
  961. if (* (const char **) flag_var != NULL)
  962. snprintf (new_help + strlen (new_help),
  963. sizeof (new_help) - strlen (new_help),
  964. "%s", * (const char **) flag_var);
  965. }
  966. else if (option->var_type == CLVC_ENUM)
  967. {
  968. const struct cl_enum *e = &cl_enums[option->var_enum];
  969. int value;
  970. const char *arg = NULL;
  971. value = e->get (flag_var);
  972. enum_value_to_arg (e->values, &arg, value, lang_mask);
  973. if (arg == NULL)
  974. arg = _("[default]");
  975. snprintf (new_help + strlen (new_help),
  976. sizeof (new_help) - strlen (new_help),
  977. "%s", arg);
  978. }
  979. else
  980. sprintf (new_help + strlen (new_help),
  981. "%#x", * (int *) flag_var);
  982. }
  983. else
  984. strcat (new_help, option_enabled (i, opts)
  985. ? _("[enabled]") : _("[disabled]"));
  986. }
  987. help = new_help;
  988. }
  989. wrap_help (help, opt, len, columns);
  990. displayed = true;
  991. if (option->var_type == CLVC_ENUM
  992. && opts->x_help_enum_printed[option->var_enum] != 2)
  993. opts->x_help_enum_printed[option->var_enum] = 1;
  994. }
  995. if (! found)
  996. {
  997. unsigned int langs = include_flags & CL_LANG_ALL;
  998. if (langs == 0)
  999. printf (_(" No options with the desired characteristics were found\n"));
  1000. else
  1001. {
  1002. unsigned int i;
  1003. /* PR 31349: Tell the user how to see all of the
  1004. options supported by a specific front end. */
  1005. for (i = 0; (1U << i) < CL_LANG_ALL; i ++)
  1006. if ((1U << i) & langs)
  1007. printf (_(" None found. Use --help=%s to show *all* the options supported by the %s front-end\n"),
  1008. lang_names[i], lang_names[i]);
  1009. }
  1010. }
  1011. else if (! displayed)
  1012. printf (_(" All options with the desired characteristics have already been displayed\n"));
  1013. putchar ('\n');
  1014. /* Print details of enumerated option arguments, if those
  1015. enumerations have help text headings provided. If no help text
  1016. is provided, presume that the possible values are listed in the
  1017. help text for the relevant options. */
  1018. for (i = 0; i < cl_enums_count; i++)
  1019. {
  1020. unsigned int j, pos;
  1021. if (opts->x_help_enum_printed[i] != 1)
  1022. continue;
  1023. if (cl_enums[i].help == NULL)
  1024. continue;
  1025. printf (" %s\n ", _(cl_enums[i].help));
  1026. pos = 4;
  1027. for (j = 0; cl_enums[i].values[j].arg != NULL; j++)
  1028. {
  1029. unsigned int len = strlen (cl_enums[i].values[j].arg);
  1030. if (pos > 4 && pos + 1 + len <= columns)
  1031. {
  1032. printf (" %s", cl_enums[i].values[j].arg);
  1033. pos += 1 + len;
  1034. }
  1035. else
  1036. {
  1037. if (pos > 4)
  1038. {
  1039. printf ("\n ");
  1040. pos = 4;
  1041. }
  1042. printf ("%s", cl_enums[i].values[j].arg);
  1043. pos += len;
  1044. }
  1045. }
  1046. printf ("\n\n");
  1047. opts->x_help_enum_printed[i] = 2;
  1048. }
  1049. }
  1050. /* Display help for a specified type of option.
  1051. The options must have ALL of the INCLUDE_FLAGS set
  1052. ANY of the flags in the ANY_FLAGS set
  1053. and NONE of the EXCLUDE_FLAGS set. The current option state is in
  1054. OPTS; LANG_MASK is used for interpreting enumerated option state. */
  1055. static void
  1056. print_specific_help (unsigned int include_flags,
  1057. unsigned int exclude_flags,
  1058. unsigned int any_flags,
  1059. struct gcc_options *opts,
  1060. unsigned int lang_mask)
  1061. {
  1062. unsigned int all_langs_mask = (1U << cl_lang_count) - 1;
  1063. const char * description = NULL;
  1064. const char * descrip_extra = "";
  1065. size_t i;
  1066. unsigned int flag;
  1067. /* Sanity check: Make sure that we do not have more
  1068. languages than we have bits available to enumerate them. */
  1069. gcc_assert ((1U << cl_lang_count) <= CL_MIN_OPTION_CLASS);
  1070. /* If we have not done so already, obtain
  1071. the desired maximum width of the output. */
  1072. if (opts->x_help_columns == 0)
  1073. {
  1074. opts->x_help_columns = get_terminal_width ();
  1075. if (opts->x_help_columns == INT_MAX)
  1076. /* Use a reasonable default. */
  1077. opts->x_help_columns = 80;
  1078. }
  1079. /* Decide upon the title for the options that we are going to display. */
  1080. for (i = 0, flag = 1; flag <= CL_MAX_OPTION_CLASS; flag <<= 1, i ++)
  1081. {
  1082. switch (flag & include_flags)
  1083. {
  1084. case 0:
  1085. case CL_DRIVER:
  1086. break;
  1087. case CL_TARGET:
  1088. description = _("The following options are target specific");
  1089. break;
  1090. case CL_WARNING:
  1091. description = _("The following options control compiler warning messages");
  1092. break;
  1093. case CL_OPTIMIZATION:
  1094. description = _("The following options control optimizations");
  1095. break;
  1096. case CL_COMMON:
  1097. description = _("The following options are language-independent");
  1098. break;
  1099. case CL_PARAMS:
  1100. description = _("The --param option recognizes the following as parameters");
  1101. break;
  1102. default:
  1103. if (i >= cl_lang_count)
  1104. break;
  1105. if (exclude_flags & all_langs_mask)
  1106. description = _("The following options are specific to just the language ");
  1107. else
  1108. description = _("The following options are supported by the language ");
  1109. descrip_extra = lang_names [i];
  1110. break;
  1111. }
  1112. }
  1113. if (description == NULL)
  1114. {
  1115. if (any_flags == 0)
  1116. {
  1117. if (include_flags & CL_UNDOCUMENTED)
  1118. description = _("The following options are not documented");
  1119. else if (include_flags & CL_SEPARATE)
  1120. description = _("The following options take separate arguments");
  1121. else if (include_flags & CL_JOINED)
  1122. description = _("The following options take joined arguments");
  1123. else
  1124. {
  1125. internal_error ("unrecognized include_flags 0x%x passed to print_specific_help",
  1126. include_flags);
  1127. return;
  1128. }
  1129. }
  1130. else
  1131. {
  1132. if (any_flags & all_langs_mask)
  1133. description = _("The following options are language-related");
  1134. else
  1135. description = _("The following options are language-independent");
  1136. }
  1137. }
  1138. printf ("%s%s:\n", description, descrip_extra);
  1139. print_filtered_help (include_flags, exclude_flags, any_flags,
  1140. opts->x_help_columns, opts, lang_mask);
  1141. }
  1142. /* Enable FDO-related flags. */
  1143. static void
  1144. enable_fdo_optimizations (struct gcc_options *opts,
  1145. struct gcc_options *opts_set,
  1146. int value)
  1147. {
  1148. if (!opts_set->x_flag_branch_probabilities)
  1149. opts->x_flag_branch_probabilities = value;
  1150. if (!opts_set->x_flag_profile_values)
  1151. opts->x_flag_profile_values = value;
  1152. if (!opts_set->x_flag_unroll_loops)
  1153. opts->x_flag_unroll_loops = value;
  1154. if (!opts_set->x_flag_peel_loops)
  1155. opts->x_flag_peel_loops = value;
  1156. if (!opts_set->x_flag_tracer)
  1157. opts->x_flag_tracer = value;
  1158. if (!opts_set->x_flag_value_profile_transformations)
  1159. opts->x_flag_value_profile_transformations = value;
  1160. if (!opts_set->x_flag_inline_functions)
  1161. opts->x_flag_inline_functions = value;
  1162. if (!opts_set->x_flag_ipa_cp)
  1163. opts->x_flag_ipa_cp = value;
  1164. if (!opts_set->x_flag_ipa_cp_clone
  1165. && value && opts->x_flag_ipa_cp)
  1166. opts->x_flag_ipa_cp_clone = value;
  1167. if (!opts_set->x_flag_ipa_cp_alignment
  1168. && value && opts->x_flag_ipa_cp)
  1169. opts->x_flag_ipa_cp_alignment = value;
  1170. if (!opts_set->x_flag_predictive_commoning)
  1171. opts->x_flag_predictive_commoning = value;
  1172. if (!opts_set->x_flag_unswitch_loops)
  1173. opts->x_flag_unswitch_loops = value;
  1174. if (!opts_set->x_flag_gcse_after_reload)
  1175. opts->x_flag_gcse_after_reload = value;
  1176. if (!opts_set->x_flag_tree_loop_vectorize
  1177. && !opts_set->x_flag_tree_vectorize)
  1178. opts->x_flag_tree_loop_vectorize = value;
  1179. if (!opts_set->x_flag_tree_slp_vectorize
  1180. && !opts_set->x_flag_tree_vectorize)
  1181. opts->x_flag_tree_slp_vectorize = value;
  1182. if (!opts_set->x_flag_vect_cost_model)
  1183. opts->x_flag_vect_cost_model = VECT_COST_MODEL_DYNAMIC;
  1184. if (!opts_set->x_flag_tree_loop_distribute_patterns)
  1185. opts->x_flag_tree_loop_distribute_patterns = value;
  1186. }
  1187. /* Handle target- and language-independent options. Return zero to
  1188. generate an "unknown option" message. Only options that need
  1189. extra handling need to be listed here; if you simply want
  1190. DECODED->value assigned to a variable, it happens automatically. */
  1191. bool
  1192. common_handle_option (struct gcc_options *opts,
  1193. struct gcc_options *opts_set,
  1194. const struct cl_decoded_option *decoded,
  1195. unsigned int lang_mask, int kind ATTRIBUTE_UNUSED,
  1196. location_t loc,
  1197. const struct cl_option_handlers *handlers,
  1198. diagnostic_context *dc)
  1199. {
  1200. size_t scode = decoded->opt_index;
  1201. const char *arg = decoded->arg;
  1202. int value = decoded->value;
  1203. enum opt_code code = (enum opt_code) scode;
  1204. gcc_assert (decoded->canonical_option_num_elements <= 2);
  1205. switch (code)
  1206. {
  1207. case OPT__param:
  1208. handle_param (opts, opts_set, loc, arg);
  1209. break;
  1210. case OPT__help:
  1211. {
  1212. unsigned int all_langs_mask = (1U << cl_lang_count) - 1;
  1213. unsigned int undoc_mask;
  1214. unsigned int i;
  1215. if (lang_mask == CL_DRIVER)
  1216. break;;
  1217. undoc_mask = ((opts->x_verbose_flag | opts->x_extra_warnings)
  1218. ? 0
  1219. : CL_UNDOCUMENTED);
  1220. /* First display any single language specific options. */
  1221. for (i = 0; i < cl_lang_count; i++)
  1222. print_specific_help
  1223. (1U << i, (all_langs_mask & (~ (1U << i))) | undoc_mask, 0, opts,
  1224. lang_mask);
  1225. /* Next display any multi language specific options. */
  1226. print_specific_help (0, undoc_mask, all_langs_mask, opts, lang_mask);
  1227. /* Then display any remaining, non-language options. */
  1228. for (i = CL_MIN_OPTION_CLASS; i <= CL_MAX_OPTION_CLASS; i <<= 1)
  1229. if (i != CL_DRIVER)
  1230. print_specific_help (i, undoc_mask, 0, opts, lang_mask);
  1231. opts->x_exit_after_options = true;
  1232. break;
  1233. }
  1234. case OPT__target_help:
  1235. if (lang_mask == CL_DRIVER)
  1236. break;
  1237. print_specific_help (CL_TARGET, CL_UNDOCUMENTED, 0, opts, lang_mask);
  1238. opts->x_exit_after_options = true;
  1239. break;
  1240. case OPT__help_:
  1241. {
  1242. const char * a = arg;
  1243. unsigned int include_flags = 0;
  1244. /* Note - by default we include undocumented options when listing
  1245. specific classes. If you only want to see documented options
  1246. then add ",^undocumented" to the --help= option. E.g.:
  1247. --help=target,^undocumented */
  1248. unsigned int exclude_flags = 0;
  1249. if (lang_mask == CL_DRIVER)
  1250. break;
  1251. /* Walk along the argument string, parsing each word in turn.
  1252. The format is:
  1253. arg = [^]{word}[,{arg}]
  1254. word = {optimizers|target|warnings|undocumented|
  1255. params|common|<language>} */
  1256. while (* a != 0)
  1257. {
  1258. static const struct
  1259. {
  1260. const char * string;
  1261. unsigned int flag;
  1262. }
  1263. specifics[] =
  1264. {
  1265. { "optimizers", CL_OPTIMIZATION },
  1266. { "target", CL_TARGET },
  1267. { "warnings", CL_WARNING },
  1268. { "undocumented", CL_UNDOCUMENTED },
  1269. { "params", CL_PARAMS },
  1270. { "joined", CL_JOINED },
  1271. { "separate", CL_SEPARATE },
  1272. { "common", CL_COMMON },
  1273. { NULL, 0 }
  1274. };
  1275. unsigned int * pflags;
  1276. const char * comma;
  1277. unsigned int lang_flag, specific_flag;
  1278. unsigned int len;
  1279. unsigned int i;
  1280. if (* a == '^')
  1281. {
  1282. ++ a;
  1283. pflags = & exclude_flags;
  1284. }
  1285. else
  1286. pflags = & include_flags;
  1287. comma = strchr (a, ',');
  1288. if (comma == NULL)
  1289. len = strlen (a);
  1290. else
  1291. len = comma - a;
  1292. if (len == 0)
  1293. {
  1294. a = comma + 1;
  1295. continue;
  1296. }
  1297. /* Check to see if the string matches an option class name. */
  1298. for (i = 0, specific_flag = 0; specifics[i].string != NULL; i++)
  1299. if (strncasecmp (a, specifics[i].string, len) == 0)
  1300. {
  1301. specific_flag = specifics[i].flag;
  1302. break;
  1303. }
  1304. /* Check to see if the string matches a language name.
  1305. Note - we rely upon the alpha-sorted nature of the entries in
  1306. the lang_names array, specifically that shorter names appear
  1307. before their longer variants. (i.e. C before C++). That way
  1308. when we are attempting to match --help=c for example we will
  1309. match with C first and not C++. */
  1310. for (i = 0, lang_flag = 0; i < cl_lang_count; i++)
  1311. if (strncasecmp (a, lang_names[i], len) == 0)
  1312. {
  1313. lang_flag = 1U << i;
  1314. break;
  1315. }
  1316. if (specific_flag != 0)
  1317. {
  1318. if (lang_flag == 0)
  1319. * pflags |= specific_flag;
  1320. else
  1321. {
  1322. /* The option's argument matches both the start of a
  1323. language name and the start of an option class name.
  1324. We have a special case for when the user has
  1325. specified "--help=c", but otherwise we have to issue
  1326. a warning. */
  1327. if (strncasecmp (a, "c", len) == 0)
  1328. * pflags |= lang_flag;
  1329. else
  1330. warning_at (loc, 0,
  1331. "--help argument %q.*s is ambiguous, "
  1332. "please be more specific",
  1333. len, a);
  1334. }
  1335. }
  1336. else if (lang_flag != 0)
  1337. * pflags |= lang_flag;
  1338. else
  1339. warning_at (loc, 0,
  1340. "unrecognized argument to --help= option: %q.*s",
  1341. len, a);
  1342. if (comma == NULL)
  1343. break;
  1344. a = comma + 1;
  1345. }
  1346. if (include_flags)
  1347. print_specific_help (include_flags, exclude_flags, 0, opts,
  1348. lang_mask);
  1349. opts->x_exit_after_options = true;
  1350. break;
  1351. }
  1352. case OPT__version:
  1353. if (lang_mask == CL_DRIVER)
  1354. break;
  1355. opts->x_exit_after_options = true;
  1356. break;
  1357. case OPT_fsanitize_:
  1358. case OPT_fsanitize_recover_:
  1359. {
  1360. const char *p = arg;
  1361. unsigned int *flag
  1362. = code == OPT_fsanitize_ ? &opts->x_flag_sanitize
  1363. : &opts->x_flag_sanitize_recover;
  1364. while (*p != 0)
  1365. {
  1366. static const struct
  1367. {
  1368. const char *const name;
  1369. unsigned int flag;
  1370. size_t len;
  1371. } spec[] =
  1372. {
  1373. { "address", SANITIZE_ADDRESS | SANITIZE_USER_ADDRESS,
  1374. sizeof "address" - 1 },
  1375. { "kernel-address", SANITIZE_ADDRESS | SANITIZE_KERNEL_ADDRESS,
  1376. sizeof "kernel-address" - 1 },
  1377. { "thread", SANITIZE_THREAD, sizeof "thread" - 1 },
  1378. { "leak", SANITIZE_LEAK, sizeof "leak" - 1 },
  1379. { "shift", SANITIZE_SHIFT, sizeof "shift" - 1 },
  1380. { "integer-divide-by-zero", SANITIZE_DIVIDE,
  1381. sizeof "integer-divide-by-zero" - 1 },
  1382. { "undefined", SANITIZE_UNDEFINED, sizeof "undefined" - 1 },
  1383. { "unreachable", SANITIZE_UNREACHABLE,
  1384. sizeof "unreachable" - 1 },
  1385. { "vla-bound", SANITIZE_VLA, sizeof "vla-bound" - 1 },
  1386. { "return", SANITIZE_RETURN, sizeof "return" - 1 },
  1387. { "null", SANITIZE_NULL, sizeof "null" - 1 },
  1388. { "signed-integer-overflow", SANITIZE_SI_OVERFLOW,
  1389. sizeof "signed-integer-overflow" -1 },
  1390. { "bool", SANITIZE_BOOL, sizeof "bool" - 1 },
  1391. { "enum", SANITIZE_ENUM, sizeof "enum" - 1 },
  1392. { "float-divide-by-zero", SANITIZE_FLOAT_DIVIDE,
  1393. sizeof "float-divide-by-zero" - 1 },
  1394. { "float-cast-overflow", SANITIZE_FLOAT_CAST,
  1395. sizeof "float-cast-overflow" - 1 },
  1396. { "bounds", SANITIZE_BOUNDS, sizeof "bounds" - 1 },
  1397. { "alignment", SANITIZE_ALIGNMENT, sizeof "alignment" - 1 },
  1398. { "nonnull-attribute", SANITIZE_NONNULL_ATTRIBUTE,
  1399. sizeof "nonnull-attribute" - 1 },
  1400. { "returns-nonnull-attribute",
  1401. SANITIZE_RETURNS_NONNULL_ATTRIBUTE,
  1402. sizeof "returns-nonnull-attribute" - 1 },
  1403. { "object-size", SANITIZE_OBJECT_SIZE,
  1404. sizeof "object-size" - 1 },
  1405. { "vptr", SANITIZE_VPTR, sizeof "vptr" - 1 },
  1406. { "all", ~0, sizeof "all" - 1 },
  1407. { NULL, 0, 0 }
  1408. };
  1409. const char *comma;
  1410. size_t len, i;
  1411. bool found = false;
  1412. comma = strchr (p, ',');
  1413. if (comma == NULL)
  1414. len = strlen (p);
  1415. else
  1416. len = comma - p;
  1417. if (len == 0)
  1418. {
  1419. p = comma + 1;
  1420. continue;
  1421. }
  1422. /* Check to see if the string matches an option class name. */
  1423. for (i = 0; spec[i].name != NULL; ++i)
  1424. if (len == spec[i].len
  1425. && memcmp (p, spec[i].name, len) == 0)
  1426. {
  1427. /* Handle both -fsanitize and -fno-sanitize cases. */
  1428. if (value && spec[i].flag == ~0U)
  1429. {
  1430. if (code == OPT_fsanitize_)
  1431. error_at (loc, "-fsanitize=all option is not valid");
  1432. else
  1433. *flag |= ~(SANITIZE_USER_ADDRESS | SANITIZE_THREAD
  1434. | SANITIZE_LEAK);
  1435. }
  1436. else if (value)
  1437. *flag |= spec[i].flag;
  1438. else
  1439. *flag &= ~spec[i].flag;
  1440. found = true;
  1441. break;
  1442. }
  1443. if (! found)
  1444. error_at (loc,
  1445. "unrecognized argument to -fsanitize%s= option: %q.*s",
  1446. code == OPT_fsanitize_ ? "" : "-recover", (int) len, p);
  1447. if (comma == NULL)
  1448. break;
  1449. p = comma + 1;
  1450. }
  1451. if (code != OPT_fsanitize_)
  1452. break;
  1453. /* Kernel ASan implies normal ASan but does not yet support
  1454. all features. */
  1455. if (opts->x_flag_sanitize & SANITIZE_KERNEL_ADDRESS)
  1456. {
  1457. maybe_set_param_value (PARAM_ASAN_INSTRUMENTATION_WITH_CALL_THRESHOLD, 0,
  1458. opts->x_param_values,
  1459. opts_set->x_param_values);
  1460. maybe_set_param_value (PARAM_ASAN_GLOBALS, 0,
  1461. opts->x_param_values,
  1462. opts_set->x_param_values);
  1463. maybe_set_param_value (PARAM_ASAN_STACK, 0,
  1464. opts->x_param_values,
  1465. opts_set->x_param_values);
  1466. maybe_set_param_value (PARAM_ASAN_USE_AFTER_RETURN, 0,
  1467. opts->x_param_values,
  1468. opts_set->x_param_values);
  1469. }
  1470. break;
  1471. }
  1472. case OPT_fasan_shadow_offset_:
  1473. /* Deferred. */
  1474. break;
  1475. case OPT_fsanitize_recover:
  1476. if (value)
  1477. opts->x_flag_sanitize_recover
  1478. |= SANITIZE_UNDEFINED | SANITIZE_NONDEFAULT;
  1479. else
  1480. opts->x_flag_sanitize_recover
  1481. &= ~(SANITIZE_UNDEFINED | SANITIZE_NONDEFAULT);
  1482. break;
  1483. case OPT_O:
  1484. case OPT_Os:
  1485. case OPT_Ofast:
  1486. case OPT_Og:
  1487. /* Currently handled in a prescan. */
  1488. break;
  1489. case OPT_Werror:
  1490. dc->warning_as_error_requested = value;
  1491. break;
  1492. case OPT_Werror_:
  1493. if (lang_mask == CL_DRIVER)
  1494. break;
  1495. enable_warning_as_error (arg, value, lang_mask, handlers,
  1496. opts, opts_set, loc, dc);
  1497. break;
  1498. case OPT_Wlarger_than_:
  1499. opts->x_larger_than_size = value;
  1500. opts->x_warn_larger_than = value != -1;
  1501. break;
  1502. case OPT_Wfatal_errors:
  1503. dc->fatal_errors = value;
  1504. break;
  1505. case OPT_Wframe_larger_than_:
  1506. opts->x_frame_larger_than_size = value;
  1507. opts->x_warn_frame_larger_than = value != -1;
  1508. break;
  1509. case OPT_Wstack_usage_:
  1510. opts->x_warn_stack_usage = value;
  1511. opts->x_flag_stack_usage_info = value != -1;
  1512. break;
  1513. case OPT_Wstrict_aliasing:
  1514. set_Wstrict_aliasing (opts, value);
  1515. break;
  1516. case OPT_Wstrict_overflow:
  1517. opts->x_warn_strict_overflow = (value
  1518. ? (int) WARN_STRICT_OVERFLOW_CONDITIONAL
  1519. : 0);
  1520. break;
  1521. case OPT_Wsystem_headers:
  1522. dc->dc_warn_system_headers = value;
  1523. break;
  1524. case OPT_aux_info:
  1525. opts->x_flag_gen_aux_info = 1;
  1526. break;
  1527. case OPT_auxbase_strip:
  1528. {
  1529. char *tmp = xstrdup (arg);
  1530. strip_off_ending (tmp, strlen (tmp));
  1531. if (tmp[0])
  1532. opts->x_aux_base_name = tmp;
  1533. else
  1534. free (tmp);
  1535. }
  1536. break;
  1537. case OPT_d:
  1538. decode_d_option (arg, opts, loc, dc);
  1539. break;
  1540. case OPT_fcall_used_:
  1541. case OPT_fcall_saved_:
  1542. /* Deferred. */
  1543. break;
  1544. case OPT_fdbg_cnt_:
  1545. case OPT_fdbg_cnt_list:
  1546. /* Deferred. */
  1547. break;
  1548. case OPT_fdebug_prefix_map_:
  1549. /* Deferred. */
  1550. break;
  1551. case OPT_fdiagnostics_show_location_:
  1552. diagnostic_prefixing_rule (dc) = (diagnostic_prefixing_rule_t) value;
  1553. break;
  1554. case OPT_fdiagnostics_show_caret:
  1555. dc->show_caret = value;
  1556. break;
  1557. case OPT_fdiagnostics_color_:
  1558. diagnostic_color_init (dc, value);
  1559. break;
  1560. case OPT_fdiagnostics_show_option:
  1561. dc->show_option_requested = value;
  1562. break;
  1563. case OPT_fdump_:
  1564. /* Deferred. */
  1565. break;
  1566. case OPT_ffast_math:
  1567. set_fast_math_flags (opts, value);
  1568. break;
  1569. case OPT_funsafe_math_optimizations:
  1570. set_unsafe_math_optimizations_flags (opts, value);
  1571. break;
  1572. case OPT_ffixed_:
  1573. /* Deferred. */
  1574. break;
  1575. case OPT_finline_limit_:
  1576. set_param_value ("max-inline-insns-single", value / 2,
  1577. opts->x_param_values, opts_set->x_param_values);
  1578. set_param_value ("max-inline-insns-auto", value / 2,
  1579. opts->x_param_values, opts_set->x_param_values);
  1580. break;
  1581. case OPT_finstrument_functions_exclude_function_list_:
  1582. add_comma_separated_to_vector
  1583. (&opts->x_flag_instrument_functions_exclude_functions, arg);
  1584. break;
  1585. case OPT_finstrument_functions_exclude_file_list_:
  1586. add_comma_separated_to_vector
  1587. (&opts->x_flag_instrument_functions_exclude_files, arg);
  1588. break;
  1589. case OPT_fmessage_length_:
  1590. pp_set_line_maximum_length (dc->printer, value);
  1591. diagnostic_set_caret_max_width (dc, value);
  1592. break;
  1593. case OPT_fopt_info:
  1594. case OPT_fopt_info_:
  1595. /* Deferred. */
  1596. break;
  1597. case OPT_foffload_:
  1598. /* Deferred. */
  1599. break;
  1600. #ifndef ACCEL_COMPILER
  1601. case OPT_foffload_abi_:
  1602. error_at (loc, "-foffload-abi option can be specified only for "
  1603. "offload compiler");
  1604. break;
  1605. #endif
  1606. case OPT_fpack_struct_:
  1607. if (value <= 0 || (value & (value - 1)) || value > 16)
  1608. error_at (loc,
  1609. "structure alignment must be a small power of two, not %d",
  1610. value);
  1611. else
  1612. opts->x_initial_max_fld_align = value;
  1613. break;
  1614. case OPT_fplugin_:
  1615. case OPT_fplugin_arg_:
  1616. /* Deferred. */
  1617. break;
  1618. case OPT_fprofile_use_:
  1619. opts->x_profile_data_prefix = xstrdup (arg);
  1620. opts->x_flag_profile_use = true;
  1621. value = true;
  1622. /* No break here - do -fprofile-use processing. */
  1623. case OPT_fprofile_use:
  1624. enable_fdo_optimizations (opts, opts_set, value);
  1625. if (!opts_set->x_flag_profile_reorder_functions)
  1626. opts->x_flag_profile_reorder_functions = value;
  1627. /* Indirect call profiling should do all useful transformations
  1628. speculative devirtualization does. */
  1629. if (!opts_set->x_flag_devirtualize_speculatively
  1630. && opts->x_flag_value_profile_transformations)
  1631. opts->x_flag_devirtualize_speculatively = false;
  1632. break;
  1633. case OPT_fauto_profile_:
  1634. opts->x_auto_profile_file = xstrdup (arg);
  1635. opts->x_flag_auto_profile = true;
  1636. value = true;
  1637. /* No break here - do -fauto-profile processing. */
  1638. case OPT_fauto_profile:
  1639. enable_fdo_optimizations (opts, opts_set, value);
  1640. if (!opts_set->x_flag_profile_correction)
  1641. opts->x_flag_profile_correction = value;
  1642. maybe_set_param_value (
  1643. PARAM_EARLY_INLINER_MAX_ITERATIONS, 10,
  1644. opts->x_param_values, opts_set->x_param_values);
  1645. break;
  1646. case OPT_fprofile_generate_:
  1647. opts->x_profile_data_prefix = xstrdup (arg);
  1648. value = true;
  1649. /* No break here - do -fprofile-generate processing. */
  1650. case OPT_fprofile_generate:
  1651. if (!opts_set->x_profile_arc_flag)
  1652. opts->x_profile_arc_flag = value;
  1653. if (!opts_set->x_flag_profile_values)
  1654. opts->x_flag_profile_values = value;
  1655. if (!opts_set->x_flag_inline_functions)
  1656. opts->x_flag_inline_functions = value;
  1657. /* FIXME: Instrumentation we insert makes ipa-reference bitmaps
  1658. quadratic. Disable the pass until better memory representation
  1659. is done. */
  1660. if (!opts_set->x_flag_ipa_reference)
  1661. opts->x_flag_ipa_reference = false;
  1662. break;
  1663. case OPT_ftree_vectorize:
  1664. if (!opts_set->x_flag_tree_loop_vectorize)
  1665. opts->x_flag_tree_loop_vectorize = value;
  1666. if (!opts_set->x_flag_tree_slp_vectorize)
  1667. opts->x_flag_tree_slp_vectorize = value;
  1668. break;
  1669. case OPT_fshow_column:
  1670. dc->show_column = value;
  1671. break;
  1672. case OPT_frandom_seed:
  1673. /* The real switch is -fno-random-seed. */
  1674. if (value)
  1675. return false;
  1676. /* Deferred. */
  1677. break;
  1678. case OPT_frandom_seed_:
  1679. /* Deferred. */
  1680. break;
  1681. case OPT_fsched_verbose_:
  1682. #ifdef INSN_SCHEDULING
  1683. /* Handled with Var in common.opt. */
  1684. break;
  1685. #else
  1686. return false;
  1687. #endif
  1688. case OPT_fsched_stalled_insns_:
  1689. opts->x_flag_sched_stalled_insns = value;
  1690. if (opts->x_flag_sched_stalled_insns == 0)
  1691. opts->x_flag_sched_stalled_insns = -1;
  1692. break;
  1693. case OPT_fsched_stalled_insns_dep_:
  1694. opts->x_flag_sched_stalled_insns_dep = value;
  1695. break;
  1696. case OPT_fstack_check_:
  1697. if (!strcmp (arg, "no"))
  1698. opts->x_flag_stack_check = NO_STACK_CHECK;
  1699. else if (!strcmp (arg, "generic"))
  1700. /* This is the old stack checking method. */
  1701. opts->x_flag_stack_check = STACK_CHECK_BUILTIN
  1702. ? FULL_BUILTIN_STACK_CHECK
  1703. : GENERIC_STACK_CHECK;
  1704. else if (!strcmp (arg, "specific"))
  1705. /* This is the new stack checking method. */
  1706. opts->x_flag_stack_check = STACK_CHECK_BUILTIN
  1707. ? FULL_BUILTIN_STACK_CHECK
  1708. : STACK_CHECK_STATIC_BUILTIN
  1709. ? STATIC_BUILTIN_STACK_CHECK
  1710. : GENERIC_STACK_CHECK;
  1711. else
  1712. warning_at (loc, 0, "unknown stack check parameter %qs", arg);
  1713. break;
  1714. case OPT_fstack_limit:
  1715. /* The real switch is -fno-stack-limit. */
  1716. if (value)
  1717. return false;
  1718. /* Deferred. */
  1719. break;
  1720. case OPT_fstack_limit_register_:
  1721. case OPT_fstack_limit_symbol_:
  1722. /* Deferred. */
  1723. break;
  1724. case OPT_fstack_usage:
  1725. opts->x_flag_stack_usage = value;
  1726. opts->x_flag_stack_usage_info = value != 0;
  1727. break;
  1728. case OPT_g:
  1729. set_debug_level (NO_DEBUG, DEFAULT_GDB_EXTENSIONS, arg, opts, opts_set,
  1730. loc);
  1731. break;
  1732. case OPT_gcoff:
  1733. set_debug_level (SDB_DEBUG, false, arg, opts, opts_set, loc);
  1734. break;
  1735. case OPT_gdwarf:
  1736. if (arg && strlen (arg) != 0)
  1737. {
  1738. error_at (loc, "%<-gdwarf%s%> is ambiguous; "
  1739. "use %<-gdwarf-%s%> for DWARF version "
  1740. "or %<-gdwarf -g%s%> for debug level", arg, arg, arg);
  1741. break;
  1742. }
  1743. else
  1744. value = opts->x_dwarf_version;
  1745. /* FALLTHRU */
  1746. case OPT_gdwarf_:
  1747. if (value < 2 || value > 5)
  1748. error_at (loc, "dwarf version %d is not supported", value);
  1749. else
  1750. opts->x_dwarf_version = value;
  1751. set_debug_level (DWARF2_DEBUG, false, "", opts, opts_set, loc);
  1752. break;
  1753. case OPT_gsplit_dwarf:
  1754. set_debug_level (NO_DEBUG, DEFAULT_GDB_EXTENSIONS, "", opts, opts_set,
  1755. loc);
  1756. break;
  1757. case OPT_ggdb:
  1758. set_debug_level (NO_DEBUG, 2, arg, opts, opts_set, loc);
  1759. break;
  1760. case OPT_gstabs:
  1761. case OPT_gstabs_:
  1762. set_debug_level (DBX_DEBUG, code == OPT_gstabs_, arg, opts, opts_set,
  1763. loc);
  1764. break;
  1765. case OPT_gvms:
  1766. set_debug_level (VMS_DEBUG, false, arg, opts, opts_set, loc);
  1767. break;
  1768. case OPT_gxcoff:
  1769. case OPT_gxcoff_:
  1770. set_debug_level (XCOFF_DEBUG, code == OPT_gxcoff_, arg, opts, opts_set,
  1771. loc);
  1772. break;
  1773. case OPT_gz:
  1774. case OPT_gz_:
  1775. /* Handled completely via specs. */
  1776. break;
  1777. case OPT_pedantic_errors:
  1778. dc->pedantic_errors = 1;
  1779. control_warning_option (OPT_Wpedantic, DK_ERROR, value,
  1780. loc, lang_mask,
  1781. handlers, opts, opts_set,
  1782. dc);
  1783. break;
  1784. case OPT_flto:
  1785. opts->x_flag_lto = value ? "" : NULL;
  1786. break;
  1787. case OPT_w:
  1788. dc->dc_inhibit_warnings = true;
  1789. break;
  1790. case OPT_fmax_errors_:
  1791. dc->max_errors = value;
  1792. break;
  1793. case OPT_fuse_ld_bfd:
  1794. case OPT_fuse_ld_gold:
  1795. case OPT_fuse_linker_plugin:
  1796. /* No-op. Used by the driver and passed to us because it starts with f.*/
  1797. break;
  1798. case OPT_fwrapv:
  1799. if (value)
  1800. opts->x_flag_trapv = 0;
  1801. break;
  1802. case OPT_ftrapv:
  1803. if (value)
  1804. opts->x_flag_wrapv = 0;
  1805. break;
  1806. case OPT_fipa_icf:
  1807. opts->x_flag_ipa_icf_functions = value;
  1808. opts->x_flag_ipa_icf_variables = value;
  1809. break;
  1810. default:
  1811. /* If the flag was handled in a standard way, assume the lack of
  1812. processing here is intentional. */
  1813. gcc_assert (option_flag_var (scode, opts));
  1814. break;
  1815. }
  1816. common_handle_option_auto (opts, opts_set, decoded, lang_mask, kind,
  1817. loc, handlers, dc);
  1818. return true;
  1819. }
  1820. /* Handle --param NAME=VALUE. */
  1821. static void
  1822. handle_param (struct gcc_options *opts, struct gcc_options *opts_set,
  1823. location_t loc, const char *carg)
  1824. {
  1825. char *equal, *arg;
  1826. int value;
  1827. arg = xstrdup (carg);
  1828. equal = strchr (arg, '=');
  1829. if (!equal)
  1830. error_at (loc, "%s: --param arguments should be of the form NAME=VALUE",
  1831. arg);
  1832. else
  1833. {
  1834. value = integral_argument (equal + 1);
  1835. if (value == -1)
  1836. error_at (loc, "invalid --param value %qs", equal + 1);
  1837. else
  1838. {
  1839. *equal = '\0';
  1840. set_param_value (arg, value,
  1841. opts->x_param_values, opts_set->x_param_values);
  1842. }
  1843. }
  1844. free (arg);
  1845. }
  1846. /* Used to set the level of strict aliasing warnings in OPTS,
  1847. when no level is specified (i.e., when -Wstrict-aliasing, and not
  1848. -Wstrict-aliasing=level was given).
  1849. ONOFF is assumed to take value 1 when -Wstrict-aliasing is specified,
  1850. and 0 otherwise. After calling this function, wstrict_aliasing will be
  1851. set to the default value of -Wstrict_aliasing=level, currently 3. */
  1852. static void
  1853. set_Wstrict_aliasing (struct gcc_options *opts, int onoff)
  1854. {
  1855. gcc_assert (onoff == 0 || onoff == 1);
  1856. if (onoff != 0)
  1857. opts->x_warn_strict_aliasing = 3;
  1858. else
  1859. opts->x_warn_strict_aliasing = 0;
  1860. }
  1861. /* The following routines are useful in setting all the flags that
  1862. -ffast-math and -fno-fast-math imply. */
  1863. static void
  1864. set_fast_math_flags (struct gcc_options *opts, int set)
  1865. {
  1866. if (!opts->frontend_set_flag_unsafe_math_optimizations)
  1867. {
  1868. opts->x_flag_unsafe_math_optimizations = set;
  1869. set_unsafe_math_optimizations_flags (opts, set);
  1870. }
  1871. if (!opts->frontend_set_flag_finite_math_only)
  1872. opts->x_flag_finite_math_only = set;
  1873. if (!opts->frontend_set_flag_errno_math)
  1874. opts->x_flag_errno_math = !set;
  1875. if (set)
  1876. {
  1877. if (!opts->frontend_set_flag_signaling_nans)
  1878. opts->x_flag_signaling_nans = 0;
  1879. if (!opts->frontend_set_flag_rounding_math)
  1880. opts->x_flag_rounding_math = 0;
  1881. if (!opts->frontend_set_flag_cx_limited_range)
  1882. opts->x_flag_cx_limited_range = 1;
  1883. }
  1884. }
  1885. /* When -funsafe-math-optimizations is set the following
  1886. flags are set as well. */
  1887. static void
  1888. set_unsafe_math_optimizations_flags (struct gcc_options *opts, int set)
  1889. {
  1890. if (!opts->frontend_set_flag_trapping_math)
  1891. opts->x_flag_trapping_math = !set;
  1892. if (!opts->frontend_set_flag_signed_zeros)
  1893. opts->x_flag_signed_zeros = !set;
  1894. if (!opts->frontend_set_flag_associative_math)
  1895. opts->x_flag_associative_math = set;
  1896. if (!opts->frontend_set_flag_reciprocal_math)
  1897. opts->x_flag_reciprocal_math = set;
  1898. }
  1899. /* Return true iff flags in OPTS are set as if -ffast-math. */
  1900. bool
  1901. fast_math_flags_set_p (const struct gcc_options *opts)
  1902. {
  1903. return (!opts->x_flag_trapping_math
  1904. && opts->x_flag_unsafe_math_optimizations
  1905. && opts->x_flag_finite_math_only
  1906. && !opts->x_flag_signed_zeros
  1907. && !opts->x_flag_errno_math);
  1908. }
  1909. /* Return true iff flags are set as if -ffast-math but using the flags stored
  1910. in the struct cl_optimization structure. */
  1911. bool
  1912. fast_math_flags_struct_set_p (struct cl_optimization *opt)
  1913. {
  1914. return (!opt->x_flag_trapping_math
  1915. && opt->x_flag_unsafe_math_optimizations
  1916. && opt->x_flag_finite_math_only
  1917. && !opt->x_flag_signed_zeros
  1918. && !opt->x_flag_errno_math);
  1919. }
  1920. /* Handle a debug output -g switch for options OPTS
  1921. (OPTS_SET->x_write_symbols storing whether a debug type was passed
  1922. explicitly), location LOC. EXTENDED is true or false to support
  1923. extended output (2 is special and means "-ggdb" was given). */
  1924. static void
  1925. set_debug_level (enum debug_info_type type, int extended, const char *arg,
  1926. struct gcc_options *opts, struct gcc_options *opts_set,
  1927. location_t loc)
  1928. {
  1929. opts->x_use_gnu_debug_info_extensions = extended;
  1930. if (type == NO_DEBUG)
  1931. {
  1932. if (opts->x_write_symbols == NO_DEBUG)
  1933. {
  1934. opts->x_write_symbols = PREFERRED_DEBUGGING_TYPE;
  1935. if (extended == 2)
  1936. {
  1937. #ifdef DWARF2_DEBUGGING_INFO
  1938. opts->x_write_symbols = DWARF2_DEBUG;
  1939. #elif defined DBX_DEBUGGING_INFO
  1940. opts->x_write_symbols = DBX_DEBUG;
  1941. #endif
  1942. }
  1943. if (opts->x_write_symbols == NO_DEBUG)
  1944. warning_at (loc, 0, "target system does not support debug output");
  1945. }
  1946. }
  1947. else
  1948. {
  1949. /* Does it conflict with an already selected type? */
  1950. if (opts_set->x_write_symbols != NO_DEBUG
  1951. && opts->x_write_symbols != NO_DEBUG
  1952. && type != opts->x_write_symbols)
  1953. error_at (loc, "debug format %qs conflicts with prior selection",
  1954. debug_type_names[type]);
  1955. opts->x_write_symbols = type;
  1956. opts_set->x_write_symbols = type;
  1957. }
  1958. /* A debug flag without a level defaults to level 2.
  1959. If off or at level 1, set it to level 2, but if already
  1960. at level 3, don't lower it. */
  1961. if (*arg == '\0')
  1962. {
  1963. if (opts->x_debug_info_level < DINFO_LEVEL_NORMAL)
  1964. opts->x_debug_info_level = DINFO_LEVEL_NORMAL;
  1965. }
  1966. else
  1967. {
  1968. int argval = integral_argument (arg);
  1969. if (argval == -1)
  1970. error_at (loc, "unrecognised debug output level %qs", arg);
  1971. else if (argval > 3)
  1972. error_at (loc, "debug output level %qs is too high", arg);
  1973. else
  1974. opts->x_debug_info_level = (enum debug_info_levels) argval;
  1975. }
  1976. }
  1977. /* Arrange to dump core on error for diagnostic context DC. (The
  1978. regular error message is still printed first, except in the case of
  1979. abort ().) */
  1980. static void
  1981. setup_core_dumping (diagnostic_context *dc)
  1982. {
  1983. #ifdef SIGABRT
  1984. signal (SIGABRT, SIG_DFL);
  1985. #endif
  1986. #if defined(HAVE_SETRLIMIT)
  1987. {
  1988. struct rlimit rlim;
  1989. if (getrlimit (RLIMIT_CORE, &rlim) != 0)
  1990. fatal_error (input_location, "getting core file size maximum limit: %m");
  1991. rlim.rlim_cur = rlim.rlim_max;
  1992. if (setrlimit (RLIMIT_CORE, &rlim) != 0)
  1993. fatal_error (input_location,
  1994. "setting core file size limit to maximum: %m");
  1995. }
  1996. #endif
  1997. diagnostic_abort_on_error (dc);
  1998. }
  1999. /* Parse a -d<ARG> command line switch for OPTS, location LOC,
  2000. diagnostic context DC. */
  2001. static void
  2002. decode_d_option (const char *arg, struct gcc_options *opts,
  2003. location_t loc, diagnostic_context *dc)
  2004. {
  2005. int c;
  2006. while (*arg)
  2007. switch (c = *arg++)
  2008. {
  2009. case 'A':
  2010. opts->x_flag_debug_asm = 1;
  2011. break;
  2012. case 'p':
  2013. opts->x_flag_print_asm_name = 1;
  2014. break;
  2015. case 'P':
  2016. opts->x_flag_dump_rtl_in_asm = 1;
  2017. opts->x_flag_print_asm_name = 1;
  2018. break;
  2019. case 'x':
  2020. opts->x_rtl_dump_and_exit = 1;
  2021. break;
  2022. case 'D': /* These are handled by the preprocessor. */
  2023. case 'I':
  2024. case 'M':
  2025. case 'N':
  2026. case 'U':
  2027. break;
  2028. case 'H':
  2029. setup_core_dumping (dc);
  2030. break;
  2031. case 'a':
  2032. opts->x_flag_dump_all_passed = true;
  2033. break;
  2034. default:
  2035. warning_at (loc, 0, "unrecognized gcc debugging option: %c", c);
  2036. break;
  2037. }
  2038. }
  2039. /* Enable (or disable if VALUE is 0) a warning option ARG (language
  2040. mask LANG_MASK, option handlers HANDLERS) as an error for option
  2041. structures OPTS and OPTS_SET, diagnostic context DC (possibly
  2042. NULL), location LOC. This is used by -Werror=. */
  2043. static void
  2044. enable_warning_as_error (const char *arg, int value, unsigned int lang_mask,
  2045. const struct cl_option_handlers *handlers,
  2046. struct gcc_options *opts,
  2047. struct gcc_options *opts_set,
  2048. location_t loc, diagnostic_context *dc)
  2049. {
  2050. char *new_option;
  2051. int option_index;
  2052. new_option = XNEWVEC (char, strlen (arg) + 2);
  2053. new_option[0] = 'W';
  2054. strcpy (new_option + 1, arg);
  2055. option_index = find_opt (new_option, lang_mask);
  2056. if (option_index == OPT_SPECIAL_unknown)
  2057. {
  2058. error_at (loc, "-Werror=%s: no option -%s", arg, new_option);
  2059. }
  2060. else
  2061. {
  2062. const diagnostic_t kind = value ? DK_ERROR : DK_WARNING;
  2063. control_warning_option (option_index, (int) kind, value,
  2064. loc, lang_mask,
  2065. handlers, opts, opts_set, dc);
  2066. }
  2067. free (new_option);
  2068. }
  2069. /* Return malloced memory for the name of the option OPTION_INDEX
  2070. which enabled a diagnostic (context CONTEXT), originally of type
  2071. ORIG_DIAG_KIND but possibly converted to DIAG_KIND by options such
  2072. as -Werror. */
  2073. char *
  2074. option_name (diagnostic_context *context, int option_index,
  2075. diagnostic_t orig_diag_kind, diagnostic_t diag_kind)
  2076. {
  2077. if (option_index)
  2078. {
  2079. /* A warning classified as an error. */
  2080. if ((orig_diag_kind == DK_WARNING || orig_diag_kind == DK_PEDWARN)
  2081. && diag_kind == DK_ERROR)
  2082. return concat (cl_options[OPT_Werror_].opt_text,
  2083. /* Skip over "-W". */
  2084. cl_options[option_index].opt_text + 2,
  2085. NULL);
  2086. /* A warning with option. */
  2087. else
  2088. return xstrdup (cl_options[option_index].opt_text);
  2089. }
  2090. /* A warning without option classified as an error. */
  2091. else if ((orig_diag_kind == DK_WARNING || orig_diag_kind == DK_PEDWARN
  2092. || diag_kind == DK_WARNING)
  2093. && context->warning_as_error_requested)
  2094. return xstrdup (cl_options[OPT_Werror].opt_text);
  2095. else
  2096. return NULL;
  2097. }