c-opts.c 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583
  1. /* C/ObjC/C++ 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 "coretypes.h"
  19. #include "options.h"
  20. #include "hash-set.h"
  21. #include "machmode.h"
  22. #include "vec.h"
  23. #include "double-int.h"
  24. #include "input.h"
  25. #include "alias.h"
  26. #include "symtab.h"
  27. #include "wide-int.h"
  28. #include "inchash.h"
  29. #include "tree.h"
  30. #include "c-common.h"
  31. #include "c-pragma.h"
  32. #include "flags.h"
  33. #include "toplev.h"
  34. #include "langhooks.h"
  35. #include "diagnostic.h"
  36. #include "tree-diagnostic.h" /* for virt_loc_aware_diagnostic_finalizer */
  37. #include "intl.h"
  38. #include "cppdefault.h"
  39. #include "incpath.h"
  40. #include "debug.h" /* For debug_hooks. */
  41. #include "opts.h"
  42. #include "plugin.h" /* For PLUGIN_INCLUDE_FILE event. */
  43. #include "mkdeps.h"
  44. #include "c-target.h"
  45. #include "tm.h" /* For BYTES_BIG_ENDIAN,
  46. DOLLARS_IN_IDENTIFIERS,
  47. STDC_0_IN_SYSTEM_HEADERS,
  48. TARGET_FLT_EVAL_METHOD_NON_DEFAULT and
  49. TARGET_OPTF. */
  50. #include "tm_p.h" /* For C_COMMON_OVERRIDE_OPTIONS. */
  51. #include "dumpfile.h"
  52. #ifndef DOLLARS_IN_IDENTIFIERS
  53. # define DOLLARS_IN_IDENTIFIERS true
  54. #endif
  55. #ifndef TARGET_SYSTEM_ROOT
  56. # define TARGET_SYSTEM_ROOT NULL
  57. #endif
  58. #ifndef TARGET_OPTF
  59. #define TARGET_OPTF(ARG)
  60. #endif
  61. /* CPP's options. */
  62. cpp_options *cpp_opts;
  63. /* Input filename. */
  64. static const char *this_input_filename;
  65. /* Filename and stream for preprocessed output. */
  66. static const char *out_fname;
  67. static FILE *out_stream;
  68. /* Append dependencies to deps_file. */
  69. static bool deps_append;
  70. /* If dependency switches (-MF etc.) have been given. */
  71. static bool deps_seen;
  72. /* If -v seen. */
  73. static bool verbose;
  74. /* Dependency output file. */
  75. static const char *deps_file;
  76. /* The prefix given by -iprefix, if any. */
  77. static const char *iprefix;
  78. /* The multilib directory given by -imultilib, if any. */
  79. static const char *imultilib;
  80. /* The system root, if any. Overridden by -isysroot. */
  81. static const char *sysroot = TARGET_SYSTEM_ROOT;
  82. /* Zero disables all standard directories for headers. */
  83. static bool std_inc = true;
  84. /* Zero disables the C++-specific standard directories for headers. */
  85. static bool std_cxx_inc = true;
  86. /* If the quote chain has been split by -I-. */
  87. static bool quote_chain_split;
  88. /* Number of deferred options. */
  89. static size_t deferred_count;
  90. /* Number of deferred options scanned for -include. */
  91. static size_t include_cursor;
  92. /* Dump files/flags to use during parsing. */
  93. static FILE *original_dump_file = NULL;
  94. static int original_dump_flags;
  95. static FILE *class_dump_file = NULL;
  96. static int class_dump_flags;
  97. /* Whether any standard preincluded header has been preincluded. */
  98. static bool done_preinclude;
  99. static void handle_OPT_d (const char *);
  100. static void set_std_cxx98 (int);
  101. static void set_std_cxx11 (int);
  102. static void set_std_cxx14 (int);
  103. static void set_std_cxx1z (int);
  104. static void set_std_c89 (int, int);
  105. static void set_std_c99 (int);
  106. static void set_std_c11 (int);
  107. static void check_deps_environment_vars (void);
  108. static void handle_deferred_opts (void);
  109. static void sanitize_cpp_opts (void);
  110. static void add_prefixed_path (const char *, size_t);
  111. static void push_command_line_include (void);
  112. static void cb_file_change (cpp_reader *, const struct line_map *);
  113. static void cb_dir_change (cpp_reader *, const char *);
  114. static void c_finish_options (void);
  115. #ifndef STDC_0_IN_SYSTEM_HEADERS
  116. #define STDC_0_IN_SYSTEM_HEADERS 0
  117. #endif
  118. /* Holds switches parsed by c_common_handle_option (), but whose
  119. handling is deferred to c_common_post_options (). */
  120. static void defer_opt (enum opt_code, const char *);
  121. static struct deferred_opt
  122. {
  123. enum opt_code code;
  124. const char *arg;
  125. } *deferred_opts;
  126. extern const unsigned int
  127. c_family_lang_mask = (CL_C | CL_CXX | CL_ObjC | CL_ObjCXX);
  128. /* Defer option CODE with argument ARG. */
  129. static void
  130. defer_opt (enum opt_code code, const char *arg)
  131. {
  132. deferred_opts[deferred_count].code = code;
  133. deferred_opts[deferred_count].arg = arg;
  134. deferred_count++;
  135. }
  136. /* Return language mask for option parsing. */
  137. unsigned int
  138. c_common_option_lang_mask (void)
  139. {
  140. static const unsigned int lang_flags[] = {CL_C, CL_ObjC, CL_CXX, CL_ObjCXX};
  141. return lang_flags[c_language];
  142. }
  143. /* Diagnostic finalizer for C/C++/Objective-C/Objective-C++. */
  144. static void
  145. c_diagnostic_finalizer (diagnostic_context *context,
  146. diagnostic_info *diagnostic)
  147. {
  148. diagnostic_show_locus (context, diagnostic);
  149. /* By default print macro expansion contexts in the diagnostic
  150. finalizer -- for tokens resulting from macro expansion. */
  151. virt_loc_aware_diagnostic_finalizer (context, diagnostic);
  152. pp_destroy_prefix (context->printer);
  153. pp_newline_and_flush (context->printer);
  154. }
  155. /* Common default settings for diagnostics. */
  156. void
  157. c_common_diagnostics_set_defaults (diagnostic_context *context)
  158. {
  159. diagnostic_finalizer (context) = c_diagnostic_finalizer;
  160. context->opt_permissive = OPT_fpermissive;
  161. }
  162. /* Whether options from all C-family languages should be accepted
  163. quietly. */
  164. static bool accept_all_c_family_options = false;
  165. /* Return whether to complain about a wrong-language option. */
  166. bool
  167. c_common_complain_wrong_lang_p (const struct cl_option *option)
  168. {
  169. if (accept_all_c_family_options
  170. && (option->flags & c_family_lang_mask))
  171. return false;
  172. return true;
  173. }
  174. /* Initialize options structure OPTS. */
  175. void
  176. c_common_init_options_struct (struct gcc_options *opts)
  177. {
  178. opts->x_flag_exceptions = c_dialect_cxx ();
  179. opts->x_warn_pointer_arith = c_dialect_cxx ();
  180. opts->x_warn_write_strings = c_dialect_cxx ();
  181. opts->x_flag_warn_unused_result = true;
  182. /* By default, C99-like requirements for complex multiply and divide. */
  183. opts->x_flag_complex_method = 2;
  184. }
  185. /* Common initialization before calling option handlers. */
  186. void
  187. c_common_init_options (unsigned int decoded_options_count,
  188. struct cl_decoded_option *decoded_options)
  189. {
  190. unsigned int i;
  191. struct cpp_callbacks *cb;
  192. parse_in = cpp_create_reader (c_dialect_cxx () ? CLK_GNUCXX: CLK_GNUC89,
  193. ident_hash, line_table);
  194. cb = cpp_get_callbacks (parse_in);
  195. cb->error = c_cpp_error;
  196. cpp_opts = cpp_get_options (parse_in);
  197. cpp_opts->dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
  198. cpp_opts->objc = c_dialect_objc ();
  199. /* Reset to avoid warnings on internal definitions. We set it just
  200. before passing on command-line options to cpplib. */
  201. cpp_opts->warn_dollars = 0;
  202. deferred_opts = XNEWVEC (struct deferred_opt, decoded_options_count);
  203. if (c_language == clk_c)
  204. {
  205. /* The default for C is gnu11. */
  206. set_std_c11 (false /* ISO */);
  207. /* If preprocessing assembly language, accept any of the C-family
  208. front end options since the driver may pass them through. */
  209. for (i = 1; i < decoded_options_count; i++)
  210. if (decoded_options[i].opt_index == OPT_lang_asm)
  211. {
  212. accept_all_c_family_options = true;
  213. break;
  214. }
  215. }
  216. }
  217. /* Handle switch SCODE with argument ARG. VALUE is true, unless no-
  218. form of an -f or -W option was given. Returns false if the switch was
  219. invalid, true if valid. Use HANDLERS in recursive handle_option calls. */
  220. bool
  221. c_common_handle_option (size_t scode, const char *arg, int value,
  222. int kind, location_t loc,
  223. const struct cl_option_handlers *handlers)
  224. {
  225. const struct cl_option *option = &cl_options[scode];
  226. enum opt_code code = (enum opt_code) scode;
  227. bool result = true;
  228. /* Prevent resetting the language standard to a C dialect when the driver
  229. has already determined that we're looking at assembler input. */
  230. bool preprocessing_asm_p = (cpp_get_options (parse_in)->lang == CLK_ASM);
  231. switch (code)
  232. {
  233. default:
  234. if (cl_options[code].flags & c_family_lang_mask)
  235. {
  236. if ((option->flags & CL_TARGET)
  237. && ! targetcm.handle_c_option (scode, arg, value))
  238. result = false;
  239. break;
  240. }
  241. result = false;
  242. break;
  243. case OPT__output_pch_:
  244. pch_file = arg;
  245. break;
  246. case OPT_A:
  247. defer_opt (code, arg);
  248. break;
  249. case OPT_C:
  250. cpp_opts->discard_comments = 0;
  251. break;
  252. case OPT_CC:
  253. cpp_opts->discard_comments = 0;
  254. cpp_opts->discard_comments_in_macro_exp = 0;
  255. break;
  256. case OPT_D:
  257. defer_opt (code, arg);
  258. break;
  259. case OPT_H:
  260. cpp_opts->print_include_names = 1;
  261. break;
  262. case OPT_F:
  263. TARGET_OPTF (xstrdup (arg));
  264. break;
  265. case OPT_I:
  266. if (strcmp (arg, "-"))
  267. add_path (xstrdup (arg), BRACKET, 0, true);
  268. else
  269. {
  270. if (quote_chain_split)
  271. error ("-I- specified twice");
  272. quote_chain_split = true;
  273. split_quote_chain ();
  274. inform (input_location, "obsolete option -I- used, please use -iquote instead");
  275. }
  276. break;
  277. case OPT_M:
  278. case OPT_MM:
  279. /* When doing dependencies with -M or -MM, suppress normal
  280. preprocessed output, but still do -dM etc. as software
  281. depends on this. Preprocessed output does occur if -MD, -MMD
  282. or environment var dependency generation is used. */
  283. cpp_opts->deps.style = (code == OPT_M ? DEPS_SYSTEM: DEPS_USER);
  284. flag_no_output = 1;
  285. break;
  286. case OPT_MD:
  287. case OPT_MMD:
  288. cpp_opts->deps.style = (code == OPT_MD ? DEPS_SYSTEM: DEPS_USER);
  289. cpp_opts->deps.need_preprocessor_output = true;
  290. deps_file = arg;
  291. break;
  292. case OPT_MF:
  293. deps_seen = true;
  294. deps_file = arg;
  295. break;
  296. case OPT_MG:
  297. deps_seen = true;
  298. cpp_opts->deps.missing_files = true;
  299. break;
  300. case OPT_MP:
  301. deps_seen = true;
  302. cpp_opts->deps.phony_targets = true;
  303. break;
  304. case OPT_MQ:
  305. case OPT_MT:
  306. deps_seen = true;
  307. defer_opt (code, arg);
  308. break;
  309. case OPT_P:
  310. flag_no_line_commands = 1;
  311. break;
  312. case OPT_U:
  313. defer_opt (code, arg);
  314. break;
  315. case OPT_Wall:
  316. /* ??? Don't add new options here. Use LangEnabledBy in c.opt. */
  317. cpp_opts->warn_num_sign_change = value;
  318. break;
  319. case OPT_Wunknown_pragmas:
  320. /* Set to greater than 1, so that even unknown pragmas in
  321. system headers will be warned about. */
  322. /* ??? There is no way to handle this automatically for now. */
  323. warn_unknown_pragmas = value * 2;
  324. break;
  325. case OPT_ansi:
  326. if (!c_dialect_cxx ())
  327. set_std_c89 (false, true);
  328. else
  329. set_std_cxx98 (true);
  330. break;
  331. case OPT_d:
  332. handle_OPT_d (arg);
  333. break;
  334. case OPT_Wabi_:
  335. warn_abi = true;
  336. if (value == 1)
  337. {
  338. warning (0, "%<-Wabi=1%> is not supported, using =2");
  339. value = 2;
  340. }
  341. flag_abi_compat_version = value;
  342. break;
  343. case OPT_fcanonical_system_headers:
  344. cpp_opts->canonical_system_headers = value;
  345. break;
  346. case OPT_fcond_mismatch:
  347. if (!c_dialect_cxx ())
  348. {
  349. flag_cond_mismatch = value;
  350. break;
  351. }
  352. warning (0, "switch %qs is no longer supported", option->opt_text);
  353. break;
  354. case OPT_fbuiltin_:
  355. if (value)
  356. result = false;
  357. else
  358. disable_builtin_function (arg);
  359. break;
  360. case OPT_fdirectives_only:
  361. cpp_opts->directives_only = value;
  362. break;
  363. case OPT_fdollars_in_identifiers:
  364. cpp_opts->dollars_in_ident = value;
  365. break;
  366. case OPT_ffreestanding:
  367. value = !value;
  368. /* Fall through.... */
  369. case OPT_fhosted:
  370. flag_hosted = value;
  371. flag_no_builtin = !value;
  372. break;
  373. case OPT_fconstant_string_class_:
  374. constant_string_class_name = arg;
  375. break;
  376. case OPT_fextended_identifiers:
  377. cpp_opts->extended_identifiers = value;
  378. break;
  379. case OPT_foperator_names:
  380. cpp_opts->operator_names = value;
  381. break;
  382. case OPT_fpch_deps:
  383. cpp_opts->restore_pch_deps = value;
  384. break;
  385. case OPT_fpch_preprocess:
  386. flag_pch_preprocess = value;
  387. break;
  388. case OPT_fpermissive:
  389. flag_permissive = value;
  390. global_dc->permissive = value;
  391. break;
  392. case OPT_fpreprocessed:
  393. cpp_opts->preprocessed = value;
  394. break;
  395. case OPT_fdebug_cpp:
  396. cpp_opts->debug = 1;
  397. break;
  398. case OPT_ftrack_macro_expansion:
  399. if (value)
  400. value = 2;
  401. /* Fall Through. */
  402. case OPT_ftrack_macro_expansion_:
  403. if (arg && *arg != '\0')
  404. cpp_opts->track_macro_expansion = value;
  405. else
  406. cpp_opts->track_macro_expansion = 2;
  407. break;
  408. case OPT_frepo:
  409. flag_use_repository = value;
  410. if (value)
  411. flag_implicit_templates = 0;
  412. break;
  413. case OPT_ftabstop_:
  414. /* It is documented that we silently ignore silly values. */
  415. if (value >= 1 && value <= 100)
  416. cpp_opts->tabstop = value;
  417. break;
  418. case OPT_fexec_charset_:
  419. cpp_opts->narrow_charset = arg;
  420. break;
  421. case OPT_fwide_exec_charset_:
  422. cpp_opts->wide_charset = arg;
  423. break;
  424. case OPT_finput_charset_:
  425. cpp_opts->input_charset = arg;
  426. break;
  427. case OPT_ftemplate_depth_:
  428. max_tinst_depth = value;
  429. break;
  430. case OPT_fvisibility_inlines_hidden:
  431. visibility_options.inlines_hidden = value;
  432. break;
  433. case OPT_femit_struct_debug_baseonly:
  434. set_struct_debug_option (&global_options, loc, "base");
  435. break;
  436. case OPT_femit_struct_debug_reduced:
  437. set_struct_debug_option (&global_options, loc,
  438. "dir:ord:sys,dir:gen:any,ind:base");
  439. break;
  440. case OPT_femit_struct_debug_detailed_:
  441. set_struct_debug_option (&global_options, loc, arg);
  442. break;
  443. case OPT_fext_numeric_literals:
  444. cpp_opts->ext_numeric_literals = value;
  445. break;
  446. case OPT_idirafter:
  447. add_path (xstrdup (arg), AFTER, 0, true);
  448. break;
  449. case OPT_imacros:
  450. case OPT_include:
  451. defer_opt (code, arg);
  452. break;
  453. case OPT_imultilib:
  454. imultilib = arg;
  455. break;
  456. case OPT_iprefix:
  457. iprefix = arg;
  458. break;
  459. case OPT_iquote:
  460. add_path (xstrdup (arg), QUOTE, 0, true);
  461. break;
  462. case OPT_isysroot:
  463. sysroot = arg;
  464. break;
  465. case OPT_isystem:
  466. add_path (xstrdup (arg), SYSTEM, 0, true);
  467. break;
  468. case OPT_iwithprefix:
  469. add_prefixed_path (arg, SYSTEM);
  470. break;
  471. case OPT_iwithprefixbefore:
  472. add_prefixed_path (arg, BRACKET);
  473. break;
  474. case OPT_lang_asm:
  475. cpp_set_lang (parse_in, CLK_ASM);
  476. cpp_opts->dollars_in_ident = false;
  477. break;
  478. case OPT_nostdinc:
  479. std_inc = false;
  480. break;
  481. case OPT_nostdinc__:
  482. std_cxx_inc = false;
  483. break;
  484. case OPT_o:
  485. if (!out_fname)
  486. out_fname = arg;
  487. else
  488. error ("output filename specified twice");
  489. break;
  490. case OPT_print_objc_runtime_info:
  491. print_struct_values = 1;
  492. break;
  493. case OPT_remap:
  494. cpp_opts->remap = 1;
  495. break;
  496. case OPT_std_c__98:
  497. case OPT_std_gnu__98:
  498. if (!preprocessing_asm_p)
  499. set_std_cxx98 (code == OPT_std_c__98 /* ISO */);
  500. break;
  501. case OPT_std_c__11:
  502. case OPT_std_gnu__11:
  503. if (!preprocessing_asm_p)
  504. {
  505. set_std_cxx11 (code == OPT_std_c__11 /* ISO */);
  506. if (code == OPT_std_c__11)
  507. cpp_opts->ext_numeric_literals = 0;
  508. }
  509. break;
  510. case OPT_std_c__14:
  511. case OPT_std_gnu__14:
  512. if (!preprocessing_asm_p)
  513. {
  514. set_std_cxx14 (code == OPT_std_c__14 /* ISO */);
  515. if (code == OPT_std_c__14)
  516. cpp_opts->ext_numeric_literals = 0;
  517. }
  518. break;
  519. case OPT_std_c__1z:
  520. case OPT_std_gnu__1z:
  521. if (!preprocessing_asm_p)
  522. {
  523. set_std_cxx1z (code == OPT_std_c__1z /* ISO */);
  524. if (code == OPT_std_c__1z)
  525. cpp_opts->ext_numeric_literals = 0;
  526. }
  527. break;
  528. case OPT_std_c90:
  529. case OPT_std_iso9899_199409:
  530. if (!preprocessing_asm_p)
  531. set_std_c89 (code == OPT_std_iso9899_199409 /* c94 */, true /* ISO */);
  532. break;
  533. case OPT_std_gnu90:
  534. if (!preprocessing_asm_p)
  535. set_std_c89 (false /* c94 */, false /* ISO */);
  536. break;
  537. case OPT_std_c99:
  538. if (!preprocessing_asm_p)
  539. set_std_c99 (true /* ISO */);
  540. break;
  541. case OPT_std_gnu99:
  542. if (!preprocessing_asm_p)
  543. set_std_c99 (false /* ISO */);
  544. break;
  545. case OPT_std_c11:
  546. if (!preprocessing_asm_p)
  547. set_std_c11 (true /* ISO */);
  548. break;
  549. case OPT_std_gnu11:
  550. if (!preprocessing_asm_p)
  551. set_std_c11 (false /* ISO */);
  552. break;
  553. case OPT_trigraphs:
  554. cpp_opts->trigraphs = 1;
  555. break;
  556. case OPT_traditional_cpp:
  557. cpp_opts->traditional = 1;
  558. break;
  559. case OPT_v:
  560. verbose = true;
  561. break;
  562. }
  563. switch (c_language)
  564. {
  565. case clk_c:
  566. C_handle_option_auto (&global_options, &global_options_set,
  567. scode, arg, value,
  568. c_family_lang_mask, kind,
  569. loc, handlers, global_dc);
  570. break;
  571. case clk_objc:
  572. ObjC_handle_option_auto (&global_options, &global_options_set,
  573. scode, arg, value,
  574. c_family_lang_mask, kind,
  575. loc, handlers, global_dc);
  576. break;
  577. case clk_cxx:
  578. CXX_handle_option_auto (&global_options, &global_options_set,
  579. scode, arg, value,
  580. c_family_lang_mask, kind,
  581. loc, handlers, global_dc);
  582. break;
  583. case clk_objcxx:
  584. ObjCXX_handle_option_auto (&global_options, &global_options_set,
  585. scode, arg, value,
  586. c_family_lang_mask, kind,
  587. loc, handlers, global_dc);
  588. break;
  589. default:
  590. gcc_unreachable ();
  591. }
  592. cpp_handle_option_auto (&global_options, scode, cpp_opts);
  593. return result;
  594. }
  595. /* Default implementation of TARGET_HANDLE_C_OPTION. */
  596. bool
  597. default_handle_c_option (size_t code ATTRIBUTE_UNUSED,
  598. const char *arg ATTRIBUTE_UNUSED,
  599. int value ATTRIBUTE_UNUSED)
  600. {
  601. return false;
  602. }
  603. /* Post-switch processing. */
  604. bool
  605. c_common_post_options (const char **pfilename)
  606. {
  607. struct cpp_callbacks *cb;
  608. /* Canonicalize the input and output filenames. */
  609. if (in_fnames == NULL)
  610. {
  611. in_fnames = XNEWVEC (const char *, 1);
  612. in_fnames[0] = "";
  613. }
  614. else if (strcmp (in_fnames[0], "-") == 0)
  615. in_fnames[0] = "";
  616. if (out_fname == NULL || !strcmp (out_fname, "-"))
  617. out_fname = "";
  618. if (cpp_opts->deps.style == DEPS_NONE)
  619. check_deps_environment_vars ();
  620. handle_deferred_opts ();
  621. sanitize_cpp_opts ();
  622. register_include_chains (parse_in, sysroot, iprefix, imultilib,
  623. std_inc, std_cxx_inc && c_dialect_cxx (), verbose);
  624. #ifdef C_COMMON_OVERRIDE_OPTIONS
  625. /* Some machines may reject certain combinations of C
  626. language-specific options. */
  627. C_COMMON_OVERRIDE_OPTIONS;
  628. #endif
  629. /* Excess precision other than "fast" requires front-end
  630. support. */
  631. if (c_dialect_cxx ())
  632. {
  633. if (flag_excess_precision_cmdline == EXCESS_PRECISION_STANDARD
  634. && TARGET_FLT_EVAL_METHOD_NON_DEFAULT)
  635. sorry ("-fexcess-precision=standard for C++");
  636. flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
  637. }
  638. else if (flag_excess_precision_cmdline == EXCESS_PRECISION_DEFAULT)
  639. flag_excess_precision_cmdline = (flag_iso
  640. ? EXCESS_PRECISION_STANDARD
  641. : EXCESS_PRECISION_FAST);
  642. /* ISO C restricts floating-point expression contraction to within
  643. source-language expressions (-ffp-contract=on, currently an alias
  644. for -ffp-contract=off). */
  645. if (flag_iso
  646. && !c_dialect_cxx ()
  647. && (global_options_set.x_flag_fp_contract_mode
  648. == (enum fp_contract_mode) 0)
  649. && flag_unsafe_math_optimizations == 0)
  650. flag_fp_contract_mode = FP_CONTRACT_OFF;
  651. /* By default we use C99 inline semantics in GNU99 or C99 mode. C99
  652. inline semantics are not supported in GNU89 or C89 mode. */
  653. if (flag_gnu89_inline == -1)
  654. flag_gnu89_inline = !flag_isoc99;
  655. else if (!flag_gnu89_inline && !flag_isoc99)
  656. error ("-fno-gnu89-inline is only supported in GNU99 or C99 mode");
  657. /* Default to ObjC sjlj exception handling if NeXT runtime. */
  658. if (flag_objc_sjlj_exceptions < 0)
  659. flag_objc_sjlj_exceptions = flag_next_runtime;
  660. if (flag_objc_exceptions && !flag_objc_sjlj_exceptions)
  661. flag_exceptions = 1;
  662. /* If -ffreestanding, -fno-hosted or -fno-builtin then disable
  663. pattern recognition. */
  664. if (!global_options_set.x_flag_tree_loop_distribute_patterns
  665. && flag_no_builtin)
  666. flag_tree_loop_distribute_patterns = 0;
  667. /* -Woverlength-strings is off by default, but is enabled by -Wpedantic.
  668. It is never enabled in C++, as the minimum limit is not normative
  669. in that standard. */
  670. if (c_dialect_cxx ())
  671. warn_overlength_strings = 0;
  672. /* Wmain is enabled by default in C++ but not in C. */
  673. /* Wmain is disabled by default for -ffreestanding (!flag_hosted),
  674. even if -Wall or -Wpedantic was given (warn_main will be 2 if set
  675. by -Wall, 1 if set by -Wmain). */
  676. if (warn_main == -1)
  677. warn_main = (c_dialect_cxx () && flag_hosted) ? 1 : 0;
  678. else if (warn_main == 2)
  679. warn_main = flag_hosted ? 1 : 0;
  680. /* In C, -Wall and -Wc++-compat enable -Wenum-compare; if it has not
  681. yet been set, it is disabled by default. In C++, it is enabled
  682. by default. */
  683. if (warn_enum_compare == -1)
  684. warn_enum_compare = c_dialect_cxx () ? 1 : 0;
  685. /* -Wpacked-bitfield-compat is on by default for the C languages. The
  686. warning is issued in stor-layout.c which is not part of the front-end so
  687. we need to selectively turn it on here. */
  688. if (warn_packed_bitfield_compat == -1)
  689. warn_packed_bitfield_compat = 1;
  690. /* Special format checking options don't work without -Wformat; warn if
  691. they are used. */
  692. if (!warn_format)
  693. {
  694. warning (OPT_Wformat_y2k,
  695. "-Wformat-y2k ignored without -Wformat");
  696. warning (OPT_Wformat_extra_args,
  697. "-Wformat-extra-args ignored without -Wformat");
  698. warning (OPT_Wformat_zero_length,
  699. "-Wformat-zero-length ignored without -Wformat");
  700. warning (OPT_Wformat_nonliteral,
  701. "-Wformat-nonliteral ignored without -Wformat");
  702. warning (OPT_Wformat_contains_nul,
  703. "-Wformat-contains-nul ignored without -Wformat");
  704. warning (OPT_Wformat_security,
  705. "-Wformat-security ignored without -Wformat");
  706. }
  707. /* -Wimplicit-function-declaration is enabled by default for C99. */
  708. if (warn_implicit_function_declaration == -1)
  709. warn_implicit_function_declaration = flag_isoc99;
  710. /* -Wimplicit-int is enabled by default for C99. */
  711. if (warn_implicit_int == -1)
  712. warn_implicit_int = flag_isoc99;
  713. /* Declone C++ 'structors if -Os. */
  714. if (flag_declone_ctor_dtor == -1)
  715. flag_declone_ctor_dtor = optimize_size;
  716. if (flag_abi_compat_version == 1)
  717. {
  718. warning (0, "%<-fabi-compat-version=1%> is not supported, using =2");
  719. flag_abi_compat_version = 2;
  720. }
  721. else if (flag_abi_compat_version == -1)
  722. {
  723. /* Generate compatibility aliases for ABI v2 (3.4-4.9) by default. */
  724. flag_abi_compat_version = (flag_abi_version == 0 ? 2 : 0);
  725. /* But don't warn about backward compatibility unless explicitly
  726. requested with -Wabi=n. */
  727. if (flag_abi_version == 0)
  728. warn_abi = false;
  729. }
  730. /* Change flag_abi_version to be the actual current ABI level for the
  731. benefit of c_cpp_builtins. */
  732. if (flag_abi_version == 0)
  733. flag_abi_version = 9;
  734. if (cxx_dialect >= cxx11)
  735. {
  736. /* If we're allowing C++0x constructs, don't warn about C++98
  737. identifiers which are keywords in C++0x. */
  738. warn_cxx0x_compat = 0;
  739. if (warn_narrowing == -1)
  740. warn_narrowing = 1;
  741. }
  742. else if (warn_narrowing == -1)
  743. warn_narrowing = 0;
  744. /* Global sized deallocation is new in C++14. */
  745. if (flag_sized_deallocation == -1)
  746. flag_sized_deallocation = (cxx_dialect >= cxx14);
  747. if (flag_extern_tls_init)
  748. {
  749. #if !defined (ASM_OUTPUT_DEF) || !SUPPORTS_WEAK
  750. /* Lazy TLS initialization for a variable in another TU requires
  751. alias and weak reference support. */
  752. if (flag_extern_tls_init > 0)
  753. sorry ("external TLS initialization functions not supported "
  754. "on this target");
  755. flag_extern_tls_init = 0;
  756. #else
  757. flag_extern_tls_init = 1;
  758. #endif
  759. }
  760. if (flag_preprocess_only)
  761. {
  762. /* Open the output now. We must do so even if flag_no_output is
  763. on, because there may be other output than from the actual
  764. preprocessing (e.g. from -dM). */
  765. if (out_fname[0] == '\0')
  766. out_stream = stdout;
  767. else
  768. out_stream = fopen (out_fname, "w");
  769. if (out_stream == NULL)
  770. {
  771. fatal_error (input_location, "opening output file %s: %m", out_fname);
  772. return false;
  773. }
  774. if (num_in_fnames > 1)
  775. error ("too many filenames given. Type %s --help for usage",
  776. progname);
  777. init_pp_output (out_stream);
  778. }
  779. else
  780. {
  781. init_c_lex ();
  782. /* When writing a PCH file, avoid reading some other PCH file,
  783. because the default address space slot then can't be used
  784. for the output PCH file. */
  785. if (pch_file)
  786. {
  787. c_common_no_more_pch ();
  788. /* Only -g0 and -gdwarf* are supported with PCH, for other
  789. debug formats we warn here and refuse to load any PCH files. */
  790. if (write_symbols != NO_DEBUG && write_symbols != DWARF2_DEBUG)
  791. warning (OPT_Wdeprecated,
  792. "the \"%s\" debug format cannot be used with "
  793. "pre-compiled headers", debug_type_names[write_symbols]);
  794. }
  795. else if (write_symbols != NO_DEBUG && write_symbols != DWARF2_DEBUG)
  796. c_common_no_more_pch ();
  797. /* Yuk. WTF is this? I do know ObjC relies on it somewhere. */
  798. input_location = UNKNOWN_LOCATION;
  799. }
  800. cb = cpp_get_callbacks (parse_in);
  801. cb->file_change = cb_file_change;
  802. cb->dir_change = cb_dir_change;
  803. cpp_post_options (parse_in);
  804. init_global_opts_from_cpp (&global_options, cpp_get_options (parse_in));
  805. input_location = UNKNOWN_LOCATION;
  806. *pfilename = this_input_filename
  807. = cpp_read_main_file (parse_in, in_fnames[0]);
  808. /* Don't do any compilation or preprocessing if there is no input file. */
  809. if (this_input_filename == NULL)
  810. {
  811. errorcount++;
  812. return false;
  813. }
  814. if (flag_working_directory
  815. && flag_preprocess_only && !flag_no_line_commands)
  816. pp_dir_change (parse_in, get_src_pwd ());
  817. /* Disable LTO output when outputting a precompiled header. */
  818. if (pch_file && flag_lto)
  819. {
  820. flag_lto = 0;
  821. flag_generate_lto = 0;
  822. }
  823. return flag_preprocess_only;
  824. }
  825. /* Front end initialization common to C, ObjC and C++. */
  826. bool
  827. c_common_init (void)
  828. {
  829. /* Set up preprocessor arithmetic. Must be done after call to
  830. c_common_nodes_and_builtins for type nodes to be good. */
  831. cpp_opts->precision = TYPE_PRECISION (intmax_type_node);
  832. cpp_opts->char_precision = TYPE_PRECISION (char_type_node);
  833. cpp_opts->int_precision = TYPE_PRECISION (integer_type_node);
  834. cpp_opts->wchar_precision = TYPE_PRECISION (wchar_type_node);
  835. cpp_opts->unsigned_wchar = TYPE_UNSIGNED (wchar_type_node);
  836. cpp_opts->bytes_big_endian = BYTES_BIG_ENDIAN;
  837. /* This can't happen until after wchar_precision and bytes_big_endian
  838. are known. */
  839. cpp_init_iconv (parse_in);
  840. if (version_flag)
  841. {
  842. int i;
  843. fputs ("Compiler executable checksum: ", stderr);
  844. for (i = 0; i < 16; i++)
  845. fprintf (stderr, "%02x", executable_checksum[i]);
  846. putc ('\n', stderr);
  847. }
  848. /* Has to wait until now so that cpplib has its hash table. */
  849. init_pragma ();
  850. if (flag_preprocess_only)
  851. {
  852. c_finish_options ();
  853. preprocess_file (parse_in);
  854. return false;
  855. }
  856. return true;
  857. }
  858. /* Initialize the integrated preprocessor after debug output has been
  859. initialized; loop over each input file. */
  860. void
  861. c_common_parse_file (void)
  862. {
  863. unsigned int i;
  864. i = 0;
  865. for (;;)
  866. {
  867. c_finish_options ();
  868. /* Open the dump files to use for the original and class dump output
  869. here, to be used during parsing for the current file. */
  870. original_dump_file = dump_begin (TDI_original, &original_dump_flags);
  871. class_dump_file = dump_begin (TDI_class, &class_dump_flags);
  872. pch_init ();
  873. push_file_scope ();
  874. c_parse_file ();
  875. pop_file_scope ();
  876. /* And end the main input file, if the debug writer wants it */
  877. if (debug_hooks->start_end_main_source_file)
  878. (*debug_hooks->end_source_file) (0);
  879. if (++i >= num_in_fnames)
  880. break;
  881. cpp_undef_all (parse_in);
  882. cpp_clear_file_cache (parse_in);
  883. this_input_filename
  884. = cpp_read_main_file (parse_in, in_fnames[i]);
  885. if (original_dump_file)
  886. {
  887. dump_end (TDI_original, original_dump_file);
  888. original_dump_file = NULL;
  889. }
  890. if (class_dump_file)
  891. {
  892. dump_end (TDI_class, class_dump_file);
  893. class_dump_file = NULL;
  894. }
  895. /* If an input file is missing, abandon further compilation.
  896. cpplib has issued a diagnostic. */
  897. if (!this_input_filename)
  898. break;
  899. }
  900. }
  901. /* Returns the appropriate dump file for PHASE to dump with FLAGS. */
  902. FILE *
  903. get_dump_info (int phase, int *flags)
  904. {
  905. gcc_assert (phase == TDI_original || phase == TDI_class);
  906. if (phase == TDI_original)
  907. {
  908. *flags = original_dump_flags;
  909. return original_dump_file;
  910. }
  911. else
  912. {
  913. *flags = class_dump_flags;
  914. return class_dump_file;
  915. }
  916. }
  917. /* Common finish hook for the C, ObjC and C++ front ends. */
  918. void
  919. c_common_finish (void)
  920. {
  921. FILE *deps_stream = NULL;
  922. /* Don't write the deps file if there are errors. */
  923. if (cpp_opts->deps.style != DEPS_NONE && !seen_error ())
  924. {
  925. /* If -M or -MM was seen without -MF, default output to the
  926. output stream. */
  927. if (!deps_file)
  928. deps_stream = out_stream;
  929. else
  930. {
  931. deps_stream = fopen (deps_file, deps_append ? "a": "w");
  932. if (!deps_stream)
  933. fatal_error (input_location, "opening dependency file %s: %m",
  934. deps_file);
  935. }
  936. }
  937. /* For performance, avoid tearing down cpplib's internal structures
  938. with cpp_destroy (). */
  939. cpp_finish (parse_in, deps_stream);
  940. if (deps_stream && deps_stream != out_stream
  941. && (ferror (deps_stream) || fclose (deps_stream)))
  942. fatal_error (input_location, "closing dependency file %s: %m", deps_file);
  943. if (out_stream && (ferror (out_stream) || fclose (out_stream)))
  944. fatal_error (input_location, "when writing output to %s: %m", out_fname);
  945. }
  946. /* Either of two environment variables can specify output of
  947. dependencies. Their value is either "OUTPUT_FILE" or "OUTPUT_FILE
  948. DEPS_TARGET", where OUTPUT_FILE is the file to write deps info to
  949. and DEPS_TARGET is the target to mention in the deps. They also
  950. result in dependency information being appended to the output file
  951. rather than overwriting it, and like Sun's compiler
  952. SUNPRO_DEPENDENCIES suppresses the dependency on the main file. */
  953. static void
  954. check_deps_environment_vars (void)
  955. {
  956. char *spec;
  957. spec = getenv ("DEPENDENCIES_OUTPUT");
  958. if (spec)
  959. cpp_opts->deps.style = DEPS_USER;
  960. else
  961. {
  962. spec = getenv ("SUNPRO_DEPENDENCIES");
  963. if (spec)
  964. {
  965. cpp_opts->deps.style = DEPS_SYSTEM;
  966. cpp_opts->deps.ignore_main_file = true;
  967. }
  968. }
  969. if (spec)
  970. {
  971. /* Find the space before the DEPS_TARGET, if there is one. */
  972. char *s = strchr (spec, ' ');
  973. if (s)
  974. {
  975. /* Let the caller perform MAKE quoting. */
  976. defer_opt (OPT_MT, s + 1);
  977. *s = '\0';
  978. }
  979. /* Command line -MF overrides environment variables and default. */
  980. if (!deps_file)
  981. deps_file = spec;
  982. deps_append = 1;
  983. deps_seen = true;
  984. }
  985. }
  986. /* Handle deferred command line switches. */
  987. static void
  988. handle_deferred_opts (void)
  989. {
  990. size_t i;
  991. struct deps *deps;
  992. /* Avoid allocating the deps buffer if we don't need it.
  993. (This flag may be true without there having been -MT or -MQ
  994. options, but we'll still need the deps buffer.) */
  995. if (!deps_seen)
  996. return;
  997. deps = cpp_get_deps (parse_in);
  998. for (i = 0; i < deferred_count; i++)
  999. {
  1000. struct deferred_opt *opt = &deferred_opts[i];
  1001. if (opt->code == OPT_MT || opt->code == OPT_MQ)
  1002. deps_add_target (deps, opt->arg, opt->code == OPT_MQ);
  1003. }
  1004. }
  1005. /* These settings are appropriate for GCC, but not necessarily so for
  1006. cpplib as a library. */
  1007. static void
  1008. sanitize_cpp_opts (void)
  1009. {
  1010. /* If we don't know what style of dependencies to output, complain
  1011. if any other dependency switches have been given. */
  1012. if (deps_seen && cpp_opts->deps.style == DEPS_NONE)
  1013. error ("to generate dependencies you must specify either -M or -MM");
  1014. /* -dM and dependencies suppress normal output; do it here so that
  1015. the last -d[MDN] switch overrides earlier ones. */
  1016. if (flag_dump_macros == 'M')
  1017. flag_no_output = 1;
  1018. /* By default, -fdirectives-only implies -dD. This allows subsequent phases
  1019. to perform proper macro expansion. */
  1020. if (cpp_opts->directives_only && !cpp_opts->preprocessed && !flag_dump_macros)
  1021. flag_dump_macros = 'D';
  1022. /* Disable -dD, -dN and -dI if normal output is suppressed. Allow
  1023. -dM since at least glibc relies on -M -dM to work. */
  1024. /* Also, flag_no_output implies flag_no_line_commands, always. */
  1025. if (flag_no_output)
  1026. {
  1027. if (flag_dump_macros != 'M')
  1028. flag_dump_macros = 0;
  1029. flag_dump_includes = 0;
  1030. flag_no_line_commands = 1;
  1031. }
  1032. else if (cpp_opts->deps.missing_files)
  1033. error ("-MG may only be used with -M or -MM");
  1034. cpp_opts->unsigned_char = !flag_signed_char;
  1035. cpp_opts->stdc_0_in_system_headers = STDC_0_IN_SYSTEM_HEADERS;
  1036. /* Wlong-long is disabled by default. It is enabled by:
  1037. [-Wpedantic | -Wtraditional] -std=[gnu|c]++98 ; or
  1038. [-Wpedantic | -Wtraditional] -std=non-c99
  1039. Either -Wlong-long or -Wno-long-long override any other settings.
  1040. ??? These conditions should be handled in c.opt. */
  1041. if (warn_long_long == -1)
  1042. {
  1043. warn_long_long = ((pedantic || warn_traditional)
  1044. && (c_dialect_cxx () ? cxx_dialect == cxx98 : !flag_isoc99));
  1045. cpp_opts->cpp_warn_long_long = warn_long_long;
  1046. }
  1047. /* If we're generating preprocessor output, emit current directory
  1048. if explicitly requested or if debugging information is enabled.
  1049. ??? Maybe we should only do it for debugging formats that
  1050. actually output the current directory? */
  1051. if (flag_working_directory == -1)
  1052. flag_working_directory = (debug_info_level != DINFO_LEVEL_NONE);
  1053. if (cpp_opts->directives_only)
  1054. {
  1055. if (cpp_warn_unused_macros)
  1056. error ("-fdirectives-only is incompatible with -Wunused_macros");
  1057. if (cpp_opts->traditional)
  1058. error ("-fdirectives-only is incompatible with -traditional");
  1059. }
  1060. }
  1061. /* Add include path with a prefix at the front of its name. */
  1062. static void
  1063. add_prefixed_path (const char *suffix, size_t chain)
  1064. {
  1065. char *path;
  1066. const char *prefix;
  1067. size_t prefix_len, suffix_len;
  1068. suffix_len = strlen (suffix);
  1069. prefix = iprefix ? iprefix : cpp_GCC_INCLUDE_DIR;
  1070. prefix_len = iprefix ? strlen (iprefix) : cpp_GCC_INCLUDE_DIR_len;
  1071. path = (char *) xmalloc (prefix_len + suffix_len + 1);
  1072. memcpy (path, prefix, prefix_len);
  1073. memcpy (path + prefix_len, suffix, suffix_len);
  1074. path[prefix_len + suffix_len] = '\0';
  1075. add_path (path, chain, 0, false);
  1076. }
  1077. /* Handle -D, -U, -A, -imacros, and the first -include. */
  1078. static void
  1079. c_finish_options (void)
  1080. {
  1081. if (!cpp_opts->preprocessed)
  1082. {
  1083. size_t i;
  1084. cb_file_change (parse_in,
  1085. linemap_add (line_table, LC_RENAME, 0,
  1086. _("<built-in>"), 0));
  1087. /* Make sure all of the builtins about to be declared have
  1088. BUILTINS_LOCATION has their source_location. */
  1089. source_location builtins_loc = BUILTINS_LOCATION;
  1090. cpp_force_token_locations (parse_in, &builtins_loc);
  1091. cpp_init_builtins (parse_in, flag_hosted);
  1092. c_cpp_builtins (parse_in);
  1093. cpp_stop_forcing_token_locations (parse_in);
  1094. /* We're about to send user input to cpplib, so make it warn for
  1095. things that we previously (when we sent it internal definitions)
  1096. told it to not warn.
  1097. C99 permits implementation-defined characters in identifiers.
  1098. The documented meaning of -std= is to turn off extensions that
  1099. conflict with the specified standard, and since a strictly
  1100. conforming program cannot contain a '$', we do not condition
  1101. their acceptance on the -std= setting. */
  1102. cpp_opts->warn_dollars = (cpp_opts->cpp_pedantic && !cpp_opts->c99);
  1103. cb_file_change (parse_in,
  1104. linemap_add (line_table, LC_RENAME, 0,
  1105. _("<command-line>"), 0));
  1106. for (i = 0; i < deferred_count; i++)
  1107. {
  1108. struct deferred_opt *opt = &deferred_opts[i];
  1109. if (opt->code == OPT_D)
  1110. cpp_define (parse_in, opt->arg);
  1111. else if (opt->code == OPT_U)
  1112. cpp_undef (parse_in, opt->arg);
  1113. else if (opt->code == OPT_A)
  1114. {
  1115. if (opt->arg[0] == '-')
  1116. cpp_unassert (parse_in, opt->arg + 1);
  1117. else
  1118. cpp_assert (parse_in, opt->arg);
  1119. }
  1120. }
  1121. /* Start the main input file, if the debug writer wants it. */
  1122. if (debug_hooks->start_end_main_source_file
  1123. && !flag_preprocess_only)
  1124. (*debug_hooks->start_source_file) (0, this_input_filename);
  1125. /* Handle -imacros after -D and -U. */
  1126. for (i = 0; i < deferred_count; i++)
  1127. {
  1128. struct deferred_opt *opt = &deferred_opts[i];
  1129. if (opt->code == OPT_imacros
  1130. && cpp_push_include (parse_in, opt->arg))
  1131. {
  1132. /* Disable push_command_line_include callback for now. */
  1133. include_cursor = deferred_count + 1;
  1134. cpp_scan_nooutput (parse_in);
  1135. }
  1136. }
  1137. }
  1138. else
  1139. {
  1140. if (cpp_opts->directives_only)
  1141. cpp_init_special_builtins (parse_in);
  1142. /* Start the main input file, if the debug writer wants it. */
  1143. if (debug_hooks->start_end_main_source_file
  1144. && !flag_preprocess_only)
  1145. (*debug_hooks->start_source_file) (0, this_input_filename);
  1146. }
  1147. include_cursor = 0;
  1148. push_command_line_include ();
  1149. }
  1150. /* Give CPP the next file given by -include, if any. */
  1151. static void
  1152. push_command_line_include (void)
  1153. {
  1154. /* This can happen if disabled by -imacros for example.
  1155. Punt so that we don't set "<command-line>" as the filename for
  1156. the header. */
  1157. if (include_cursor > deferred_count)
  1158. return;
  1159. if (!done_preinclude)
  1160. {
  1161. done_preinclude = true;
  1162. if (flag_hosted && std_inc && !cpp_opts->preprocessed)
  1163. {
  1164. const char *preinc = targetcm.c_preinclude ();
  1165. if (preinc && cpp_push_default_include (parse_in, preinc))
  1166. return;
  1167. }
  1168. }
  1169. pch_cpp_save_state ();
  1170. while (include_cursor < deferred_count)
  1171. {
  1172. struct deferred_opt *opt = &deferred_opts[include_cursor++];
  1173. if (!cpp_opts->preprocessed && opt->code == OPT_include
  1174. && cpp_push_include (parse_in, opt->arg))
  1175. return;
  1176. }
  1177. if (include_cursor == deferred_count)
  1178. {
  1179. include_cursor++;
  1180. /* -Wunused-macros should only warn about macros defined hereafter. */
  1181. cpp_opts->warn_unused_macros = cpp_warn_unused_macros;
  1182. /* Restore the line map from <command line>. */
  1183. if (!cpp_opts->preprocessed)
  1184. cpp_change_file (parse_in, LC_RENAME, this_input_filename);
  1185. /* Set this here so the client can change the option if it wishes,
  1186. and after stacking the main file so we don't trace the main file. */
  1187. line_table->trace_includes = cpp_opts->print_include_names;
  1188. }
  1189. }
  1190. /* File change callback. Has to handle -include files. */
  1191. static void
  1192. cb_file_change (cpp_reader * ARG_UNUSED (pfile),
  1193. const struct line_map *new_map)
  1194. {
  1195. if (flag_preprocess_only)
  1196. pp_file_change (new_map);
  1197. else
  1198. fe_file_change (new_map);
  1199. if (new_map
  1200. && (new_map->reason == LC_ENTER || new_map->reason == LC_RENAME))
  1201. {
  1202. /* Signal to plugins that a file is included. This could happen
  1203. several times with the same file path, e.g. because of
  1204. several '#include' or '#line' directives... */
  1205. invoke_plugin_callbacks
  1206. (PLUGIN_INCLUDE_FILE,
  1207. const_cast<char*> (ORDINARY_MAP_FILE_NAME (new_map)));
  1208. }
  1209. if (new_map == 0 || (new_map->reason == LC_LEAVE && MAIN_FILE_P (new_map)))
  1210. {
  1211. pch_cpp_save_state ();
  1212. push_command_line_include ();
  1213. }
  1214. }
  1215. void
  1216. cb_dir_change (cpp_reader * ARG_UNUSED (pfile), const char *dir)
  1217. {
  1218. if (!set_src_pwd (dir))
  1219. warning (0, "too late for # directive to set debug directory");
  1220. }
  1221. /* Set the C 89 standard (with 1994 amendments if C94, without GNU
  1222. extensions if ISO). There is no concept of gnu94. */
  1223. static void
  1224. set_std_c89 (int c94, int iso)
  1225. {
  1226. cpp_set_lang (parse_in, c94 ? CLK_STDC94: iso ? CLK_STDC89: CLK_GNUC89);
  1227. flag_iso = iso;
  1228. flag_no_asm = iso;
  1229. flag_no_gnu_keywords = iso;
  1230. flag_no_nonansi_builtin = iso;
  1231. flag_isoc94 = c94;
  1232. flag_isoc99 = 0;
  1233. flag_isoc11 = 0;
  1234. lang_hooks.name = "GNU C89";
  1235. }
  1236. /* Set the C 99 standard (without GNU extensions if ISO). */
  1237. static void
  1238. set_std_c99 (int iso)
  1239. {
  1240. cpp_set_lang (parse_in, iso ? CLK_STDC99: CLK_GNUC99);
  1241. flag_no_asm = iso;
  1242. flag_no_nonansi_builtin = iso;
  1243. flag_iso = iso;
  1244. flag_isoc11 = 0;
  1245. flag_isoc99 = 1;
  1246. flag_isoc94 = 1;
  1247. lang_hooks.name = "GNU C99";
  1248. }
  1249. /* Set the C 11 standard (without GNU extensions if ISO). */
  1250. static void
  1251. set_std_c11 (int iso)
  1252. {
  1253. cpp_set_lang (parse_in, iso ? CLK_STDC11: CLK_GNUC11);
  1254. flag_no_asm = iso;
  1255. flag_no_nonansi_builtin = iso;
  1256. flag_iso = iso;
  1257. flag_isoc11 = 1;
  1258. flag_isoc99 = 1;
  1259. flag_isoc94 = 1;
  1260. lang_hooks.name = "GNU C11";
  1261. }
  1262. /* Set the C++ 98 standard (without GNU extensions if ISO). */
  1263. static void
  1264. set_std_cxx98 (int iso)
  1265. {
  1266. cpp_set_lang (parse_in, iso ? CLK_CXX98: CLK_GNUCXX);
  1267. flag_no_gnu_keywords = iso;
  1268. flag_no_nonansi_builtin = iso;
  1269. flag_iso = iso;
  1270. cxx_dialect = cxx98;
  1271. lang_hooks.name = "GNU C++98";
  1272. }
  1273. /* Set the C++ 2011 standard (without GNU extensions if ISO). */
  1274. static void
  1275. set_std_cxx11 (int iso)
  1276. {
  1277. cpp_set_lang (parse_in, iso ? CLK_CXX11: CLK_GNUCXX11);
  1278. flag_no_gnu_keywords = iso;
  1279. flag_no_nonansi_builtin = iso;
  1280. flag_iso = iso;
  1281. /* C++11 includes the C99 standard library. */
  1282. flag_isoc94 = 1;
  1283. flag_isoc99 = 1;
  1284. cxx_dialect = cxx11;
  1285. lang_hooks.name = "GNU C++11";
  1286. }
  1287. /* Set the C++ 2014 draft standard (without GNU extensions if ISO). */
  1288. static void
  1289. set_std_cxx14 (int iso)
  1290. {
  1291. cpp_set_lang (parse_in, iso ? CLK_CXX14: CLK_GNUCXX14);
  1292. flag_no_gnu_keywords = iso;
  1293. flag_no_nonansi_builtin = iso;
  1294. flag_iso = iso;
  1295. /* C++11 includes the C99 standard library. */
  1296. flag_isoc94 = 1;
  1297. flag_isoc99 = 1;
  1298. cxx_dialect = cxx14;
  1299. lang_hooks.name = "GNU C++14";
  1300. }
  1301. /* Set the C++ 201z draft standard (without GNU extensions if ISO). */
  1302. static void
  1303. set_std_cxx1z (int iso)
  1304. {
  1305. cpp_set_lang (parse_in, iso ? CLK_CXX1Z: CLK_GNUCXX1Z);
  1306. flag_no_gnu_keywords = iso;
  1307. flag_no_nonansi_builtin = iso;
  1308. flag_iso = iso;
  1309. /* C++11 includes the C99 standard library. */
  1310. flag_isoc94 = 1;
  1311. flag_isoc99 = 1;
  1312. flag_isoc11 = 1;
  1313. cxx_dialect = cxx1z;
  1314. lang_hooks.name = "GNU C++14"; /* Pretend C++14 till standarization. */
  1315. }
  1316. /* Args to -d specify what to dump. Silently ignore
  1317. unrecognized options; they may be aimed at toplev.c. */
  1318. static void
  1319. handle_OPT_d (const char *arg)
  1320. {
  1321. char c;
  1322. while ((c = *arg++) != '\0')
  1323. switch (c)
  1324. {
  1325. case 'M': /* Dump macros only. */
  1326. case 'N': /* Dump names. */
  1327. case 'D': /* Dump definitions. */
  1328. case 'U': /* Dump used macros. */
  1329. flag_dump_macros = c;
  1330. break;
  1331. case 'I':
  1332. flag_dump_includes = 1;
  1333. break;
  1334. }
  1335. }