From 2d7c7df665fd79a85731ca2a5d9d31775d2bc81e Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 27 Jan 2006 21:01:55 +0100 Subject: re PR fortran/25324 (Wrong DW_TAG_compile_unit generated when compiling preprocessed fortran code) PR fortran/25324 * Make-lang.in (fortran/scanner.o): Depend on toplev.h. * lang.opt (fpreprocessed): New option. * scanner.c: Include toplev.h. (gfc_src_file, gfc_src_preprocessor_lines): New variables. (preprocessor_line): Unescape filename if there were any backslashes. (load_file): If initial and gfc_src_file is not NULL, use it rather than opening the file. If gfc_src_preprocessor_lines has non-NULL elements, pass it to preprocessor_line. (unescape_filename, gfc_read_orig_filename): New functions. * gfortran.h (gfc_option_t): Add flag_preprocessed. (gfc_read_orig_filename): New prototype. * options.c (gfc_init_options): Clear flag_preprocessed. (gfc_post_options): If flag_preprocessed, call gfc_read_orig_filename. (gfc_handle_option): Handle OPT_fpreprocessed. * lang-specs.h: Pass -fpreprocessed to f951 if preprocessing sources. From-SVN: r110304 --- gcc/fortran/options.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) (limited to 'gcc/fortran/options.c') diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c index 64fa8a2..d65827c 100644 --- a/gcc/fortran/options.c +++ b/gcc/fortran/options.c @@ -72,6 +72,7 @@ gfc_init_options (unsigned int argc ATTRIBUTE_UNUSED, gfc_option.flag_no_backend = 0; gfc_option.flag_pack_derived = 0; gfc_option.flag_repack_arrays = 0; + gfc_option.flag_preprocessed = 0; gfc_option.flag_automatic = 1; gfc_option.flag_backslash = 1; gfc_option.flag_cray_pointer = 0; @@ -172,7 +173,7 @@ form_from_filename (const char *filename) bool gfc_post_options (const char **pfilename) { - const char *filename = *pfilename; + const char *filename = *pfilename, *canon_source_file = NULL; char *source_path; int i; @@ -182,23 +183,40 @@ gfc_post_options (const char **pfilename) filename = ""; } - gfc_source_file = filename; + if (gfc_option.flag_preprocessed) + { + /* For preprocessed files, if the first tokens are of the form # NUM. + handle the directives so we know the original file name. */ + gfc_source_file = gfc_read_orig_filename (filename, &canon_source_file); + if (gfc_source_file == NULL) + gfc_source_file = filename; + else + *pfilename = gfc_source_file; + } + else + gfc_source_file = filename; + + if (canon_source_file == NULL) + canon_source_file = gfc_source_file; /* Adds the path where the source file is to the list of include files. */ - i = strlen(gfc_source_file); - while (i > 0 && !IS_DIR_SEPARATOR(gfc_source_file[i])) + i = strlen (canon_source_file); + while (i > 0 && !IS_DIR_SEPARATOR (canon_source_file[i])) i--; if (i != 0) { source_path = alloca (i + 1); - memcpy (source_path, gfc_source_file, i); + memcpy (source_path, canon_source_file, i); source_path[i] = 0; gfc_add_include_path (source_path); } else gfc_add_include_path ("."); + if (canon_source_file != gfc_source_file) + gfc_free ((void *) canon_source_file); + /* Decide which form the file will be read in as. */ if (gfc_option.source_form != FORM_UNKNOWN) @@ -211,7 +229,7 @@ gfc_post_options (const char **pfilename) { gfc_current_form = FORM_FREE; gfc_warning_now ("Reading file '%s' as free form.", - (filename[0] == '\0') ? "" : filename); + (filename[0] == '\0') ? "" : filename); } } @@ -478,6 +496,10 @@ gfc_handle_option (size_t scode, const char *arg, int value) gfc_option.flag_repack_arrays = value; break; + case OPT_fpreprocessed: + gfc_option.flag_preprocessed = value; + break; + case OPT_fmax_identifier_length_: if (value > GFC_MAX_SYMBOL_LEN) gfc_fatal_error ("Maximum supported idenitifier length is %d", -- cgit v1.1