1*38fd1498Szrj /* RTL specific diagnostic subroutines for GCC
2*38fd1498Szrj Copyright (C) 2001-2018 Free Software Foundation, Inc.
3*38fd1498Szrj Contributed by Gabriel Dos Reis <gdr@codesourcery.com>
4*38fd1498Szrj
5*38fd1498Szrj This file is part of GCC.
6*38fd1498Szrj
7*38fd1498Szrj GCC is free software; you can redistribute it and/or modify
8*38fd1498Szrj it under the terms of the GNU General Public License as published by
9*38fd1498Szrj the Free Software Foundation; either version 3, or (at your option)
10*38fd1498Szrj any later version.
11*38fd1498Szrj
12*38fd1498Szrj GCC is distributed in the hope that it will be useful,
13*38fd1498Szrj but WITHOUT ANY WARRANTY; without even the implied warranty of
14*38fd1498Szrj MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15*38fd1498Szrj GNU General Public License for more details.
16*38fd1498Szrj
17*38fd1498Szrj You should have received a copy of the GNU General Public License
18*38fd1498Szrj along with GCC; see the file COPYING3. If not see
19*38fd1498Szrj <http://www.gnu.org/licenses/>. */
20*38fd1498Szrj
21*38fd1498Szrj #include "config.h"
22*38fd1498Szrj #include "system.h"
23*38fd1498Szrj #include "coretypes.h"
24*38fd1498Szrj #include "tm.h"
25*38fd1498Szrj #include "rtl-error.h"
26*38fd1498Szrj #include "diagnostic.h"
27*38fd1498Szrj #include "intl.h"
28*38fd1498Szrj
29*38fd1498Szrj static location_t location_for_asm (const rtx_insn *);
30*38fd1498Szrj static void diagnostic_for_asm (const rtx_insn *, const char *, va_list *,
31*38fd1498Szrj diagnostic_t) ATTRIBUTE_GCC_DIAG(2,0);
32*38fd1498Szrj
33*38fd1498Szrj /* Figure the location of the given INSN. */
34*38fd1498Szrj static location_t
location_for_asm(const rtx_insn * insn)35*38fd1498Szrj location_for_asm (const rtx_insn *insn)
36*38fd1498Szrj {
37*38fd1498Szrj rtx body = PATTERN (insn);
38*38fd1498Szrj rtx asmop;
39*38fd1498Szrj location_t loc;
40*38fd1498Szrj
41*38fd1498Szrj /* Find the (or one of the) ASM_OPERANDS in the insn. */
42*38fd1498Szrj if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
43*38fd1498Szrj asmop = SET_SRC (body);
44*38fd1498Szrj else if (GET_CODE (body) == ASM_OPERANDS)
45*38fd1498Szrj asmop = body;
46*38fd1498Szrj else if (GET_CODE (body) == PARALLEL
47*38fd1498Szrj && GET_CODE (XVECEXP (body, 0, 0)) == SET)
48*38fd1498Szrj asmop = SET_SRC (XVECEXP (body, 0, 0));
49*38fd1498Szrj else if (GET_CODE (body) == PARALLEL
50*38fd1498Szrj && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
51*38fd1498Szrj asmop = XVECEXP (body, 0, 0);
52*38fd1498Szrj else
53*38fd1498Szrj asmop = NULL;
54*38fd1498Szrj
55*38fd1498Szrj if (asmop)
56*38fd1498Szrj loc = ASM_OPERANDS_SOURCE_LOCATION (asmop);
57*38fd1498Szrj else
58*38fd1498Szrj loc = input_location;
59*38fd1498Szrj return loc;
60*38fd1498Szrj }
61*38fd1498Szrj
62*38fd1498Szrj /* Report a diagnostic MESSAGE (an error or a WARNING) at the line number
63*38fd1498Szrj of the insn INSN. This is used only when INSN is an `asm' with operands,
64*38fd1498Szrj and each ASM_OPERANDS records its own source file and line. */
65*38fd1498Szrj static void
diagnostic_for_asm(const rtx_insn * insn,const char * msg,va_list * args_ptr,diagnostic_t kind)66*38fd1498Szrj diagnostic_for_asm (const rtx_insn *insn, const char *msg, va_list *args_ptr,
67*38fd1498Szrj diagnostic_t kind)
68*38fd1498Szrj {
69*38fd1498Szrj diagnostic_info diagnostic;
70*38fd1498Szrj rich_location richloc (line_table, location_for_asm (insn));
71*38fd1498Szrj
72*38fd1498Szrj diagnostic_set_info (&diagnostic, msg, args_ptr,
73*38fd1498Szrj &richloc, kind);
74*38fd1498Szrj diagnostic_report_diagnostic (global_dc, &diagnostic);
75*38fd1498Szrj }
76*38fd1498Szrj
77*38fd1498Szrj void
error_for_asm(const rtx_insn * insn,const char * gmsgid,...)78*38fd1498Szrj error_for_asm (const rtx_insn *insn, const char *gmsgid, ...)
79*38fd1498Szrj {
80*38fd1498Szrj va_list ap;
81*38fd1498Szrj
82*38fd1498Szrj va_start (ap, gmsgid);
83*38fd1498Szrj diagnostic_for_asm (insn, gmsgid, &ap, DK_ERROR);
84*38fd1498Szrj va_end (ap);
85*38fd1498Szrj }
86*38fd1498Szrj
87*38fd1498Szrj void
warning_for_asm(const rtx_insn * insn,const char * gmsgid,...)88*38fd1498Szrj warning_for_asm (const rtx_insn *insn, const char *gmsgid, ...)
89*38fd1498Szrj {
90*38fd1498Szrj va_list ap;
91*38fd1498Szrj
92*38fd1498Szrj va_start (ap, gmsgid);
93*38fd1498Szrj diagnostic_for_asm (insn, gmsgid, &ap, DK_WARNING);
94*38fd1498Szrj va_end (ap);
95*38fd1498Szrj }
96*38fd1498Szrj
97*38fd1498Szrj void
_fatal_insn(const char * msgid,const_rtx insn,const char * file,int line,const char * function)98*38fd1498Szrj _fatal_insn (const char *msgid, const_rtx insn, const char *file, int line,
99*38fd1498Szrj const char *function)
100*38fd1498Szrj {
101*38fd1498Szrj error ("%s", _(msgid));
102*38fd1498Szrj
103*38fd1498Szrj /* The above incremented error_count, but isn't an error that we want to
104*38fd1498Szrj count, so reset it here. */
105*38fd1498Szrj errorcount--;
106*38fd1498Szrj
107*38fd1498Szrj debug_rtx (insn);
108*38fd1498Szrj fancy_abort (file, line, function);
109*38fd1498Szrj }
110*38fd1498Szrj
111*38fd1498Szrj void
_fatal_insn_not_found(const_rtx insn,const char * file,int line,const char * function)112*38fd1498Szrj _fatal_insn_not_found (const_rtx insn, const char *file, int line,
113*38fd1498Szrj const char *function)
114*38fd1498Szrj {
115*38fd1498Szrj if (INSN_CODE (insn) < 0)
116*38fd1498Szrj _fatal_insn ("unrecognizable insn:", insn, file, line, function);
117*38fd1498Szrj else
118*38fd1498Szrj _fatal_insn ("insn does not satisfy its constraints:",
119*38fd1498Szrj insn, file, line, function);
120*38fd1498Szrj }
121