11debfc3dSmrg /* Basic error reporting routines.
2*8feb0f0bSmrg Copyright (C) 1999-2020 Free Software Foundation, Inc.
31debfc3dSmrg
41debfc3dSmrg This file is part of GCC.
51debfc3dSmrg
61debfc3dSmrg GCC is free software; you can redistribute it and/or modify it under
71debfc3dSmrg the terms of the GNU General Public License as published by the Free
81debfc3dSmrg Software Foundation; either version 3, or (at your option) any later
91debfc3dSmrg version.
101debfc3dSmrg
111debfc3dSmrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY
121debfc3dSmrg WARRANTY; without even the implied warranty of MERCHANTABILITY or
131debfc3dSmrg FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
141debfc3dSmrg for more details.
151debfc3dSmrg
161debfc3dSmrg You should have received a copy of the GNU General Public License
171debfc3dSmrg along with GCC; see the file COPYING3. If not see
181debfc3dSmrg <http://www.gnu.org/licenses/>. */
191debfc3dSmrg
201debfc3dSmrg /* warning, error, and fatal. These definitions are suitable for use
211debfc3dSmrg in the generator programs; the compiler has a more elaborate suite
221debfc3dSmrg of diagnostic printers, found in diagnostic.c. */
231debfc3dSmrg
241debfc3dSmrg #ifdef HOST_GENERATOR_FILE
251debfc3dSmrg #include "config.h"
261debfc3dSmrg #define GENERATOR_FILE 1
271debfc3dSmrg #else
281debfc3dSmrg #include "bconfig.h"
291debfc3dSmrg #endif
301debfc3dSmrg #include "system.h"
311debfc3dSmrg #include "errors.h"
321debfc3dSmrg
331debfc3dSmrg /* Set this to argv[0] at the beginning of main. */
341debfc3dSmrg
351debfc3dSmrg const char *progname;
361debfc3dSmrg
371debfc3dSmrg /* Starts out 0, set to 1 if error is called. */
381debfc3dSmrg
391debfc3dSmrg int have_error = 0;
401debfc3dSmrg
411debfc3dSmrg /* Print a warning message - output produced, but there may be problems. */
421debfc3dSmrg
431debfc3dSmrg void
warning(const char * format,...)441debfc3dSmrg warning (const char *format, ...)
451debfc3dSmrg {
461debfc3dSmrg va_list ap;
471debfc3dSmrg
481debfc3dSmrg va_start (ap, format);
491debfc3dSmrg fprintf (stderr, "%s: warning: ", progname);
501debfc3dSmrg vfprintf (stderr, format, ap);
511debfc3dSmrg va_end (ap);
521debfc3dSmrg fputc ('\n', stderr);
531debfc3dSmrg }
541debfc3dSmrg
551debfc3dSmrg
561debfc3dSmrg /* Print an error message - we keep going but the output is unusable. */
571debfc3dSmrg
581debfc3dSmrg void
error(const char * format,...)591debfc3dSmrg error (const char *format, ...)
601debfc3dSmrg {
611debfc3dSmrg va_list ap;
621debfc3dSmrg
631debfc3dSmrg va_start (ap, format);
641debfc3dSmrg fprintf (stderr, "%s: ", progname);
651debfc3dSmrg vfprintf (stderr, format, ap);
661debfc3dSmrg va_end (ap);
671debfc3dSmrg fputc ('\n', stderr);
681debfc3dSmrg
691debfc3dSmrg have_error = 1;
701debfc3dSmrg }
711debfc3dSmrg
721debfc3dSmrg
731debfc3dSmrg /* Fatal error - terminate execution immediately. Does not return. */
741debfc3dSmrg
751debfc3dSmrg void
fatal(const char * format,...)761debfc3dSmrg fatal (const char *format, ...)
771debfc3dSmrg {
781debfc3dSmrg va_list ap;
791debfc3dSmrg
801debfc3dSmrg va_start (ap, format);
811debfc3dSmrg fprintf (stderr, "%s: ", progname);
821debfc3dSmrg vfprintf (stderr, format, ap);
831debfc3dSmrg va_end (ap);
841debfc3dSmrg fputc ('\n', stderr);
851debfc3dSmrg exit (FATAL_EXIT_CODE);
861debfc3dSmrg }
871debfc3dSmrg
881debfc3dSmrg /* Similar, but say we got an internal error. */
891debfc3dSmrg
901debfc3dSmrg void
internal_error(const char * format,...)911debfc3dSmrg internal_error (const char *format, ...)
921debfc3dSmrg {
931debfc3dSmrg va_list ap;
941debfc3dSmrg
951debfc3dSmrg va_start (ap, format);
961debfc3dSmrg fprintf (stderr, "%s: Internal error: ", progname);
971debfc3dSmrg vfprintf (stderr, format, ap);
981debfc3dSmrg va_end (ap);
991debfc3dSmrg fputc ('\n', stderr);
1001debfc3dSmrg exit (FATAL_EXIT_CODE);
1011debfc3dSmrg }
1021debfc3dSmrg
1031debfc3dSmrg /* Given a partial pathname as input, return another pathname that
1041debfc3dSmrg shares no directory elements with the pathname of __FILE__. This
1051debfc3dSmrg is used by fancy_abort() to print `Internal compiler error in expr.c'
1061debfc3dSmrg instead of `Internal compiler error in ../../GCC/gcc/expr.c'. This
1071debfc3dSmrg version is meant to be used for the gen* programs and therefor need not
1081debfc3dSmrg handle subdirectories. */
1091debfc3dSmrg
1101debfc3dSmrg const char *
trim_filename(const char * name)1111debfc3dSmrg trim_filename (const char *name)
1121debfc3dSmrg {
1131debfc3dSmrg static const char this_file[] = __FILE__;
1141debfc3dSmrg const char *p = name, *q = this_file;
1151debfc3dSmrg
1161debfc3dSmrg /* Skip any parts the two filenames have in common. */
1171debfc3dSmrg while (*p == *q && *p != 0 && *q != 0)
1181debfc3dSmrg p++, q++;
1191debfc3dSmrg
1201debfc3dSmrg /* Now go backwards until the previous directory separator. */
1211debfc3dSmrg while (p > name && !IS_DIR_SEPARATOR (p[-1]))
1221debfc3dSmrg p--;
1231debfc3dSmrg
1241debfc3dSmrg return p;
1251debfc3dSmrg }
1261debfc3dSmrg
1271debfc3dSmrg /* "Fancy" abort. Reports where in the compiler someone gave up.
1281debfc3dSmrg This file is used only by build programs, so we're not as polite as
1291debfc3dSmrg the version in diagnostic.c. */
1301debfc3dSmrg void
fancy_abort(const char * file,int line,const char * func)1311debfc3dSmrg fancy_abort (const char *file, int line, const char *func)
1321debfc3dSmrg {
1331debfc3dSmrg internal_error ("abort in %s, at %s:%d", func, trim_filename (file), line);
1341debfc3dSmrg }
135