This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] location_tize diagnostics
- From: Nathan Sidwell <nathan at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sat, 28 Jun 2003 16:36:50 +0100
- Subject: [PATCH] location_tize diagnostics
- Organization: Codesourcery LLC
This one replaces the file and lineno paramters of the diagnostic
machinery with a location_t. The testcase change is fixing a latent bug
where we'd issue locations like '<internal>:12', where 12 was the
current source line!
built & tested on i686-pc-linux-gnu, ok?
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
The voices in my head said this was stupid too
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk
2003-06-28 Nathan Sidwell <nathan@codesourcery.com>
* diagnostic.h (diagnostic_set_info): Replace file and lineno
parameters with a location_t.
* diagnostic.c (diagnostic_set_info): Replace file and lineno
parameters with a location_t.
(inform, warning, pedwarn, error, sorry, fatal_error,
internal_error, warning_with_decl, pedwarn_with_decl,
error_with_decl): Adjust.
* c-error.c (pedwarn_c99): Adjust.
* c-format.c (status_warning): Adjust.
* rtl-error.c (fileand_line_for_asm): Rename to ...
(location_for_asm): Return a location_t.
(diagnostic_for_asm): Adjust.
* cp/cp-tree.h (cp_line_of, cp_file_of): Remove.
* error.c (cp_line_of, cp_file_of): Merge into ...
(location_of): ... here. Make static, return a location_t.
(cp_error_at, cp_warning_at, cp_pedwarn_at): Adjust.
* testsuite/g++.old-deja/g++.robertl/eb133.C: Set expected line
number.
* testsuite/g++.old-deja/g++.robertl/eb133a.C: Likewise.
* testsuite/g++.old-deja/g++.robertl/eb133b.C: Likewise.
Index: diagnostic.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/diagnostic.c,v
retrieving revision 1.118
diff -c -3 -p -r1.118 diagnostic.c
*** diagnostic.c 23 Jun 2003 15:27:35 -0000 1.118
--- diagnostic.c 28 Jun 2003 15:18:58 -0000
*************** text_specifies_location (text_info *text
*** 786,804 ****
void
diagnostic_set_info (diagnostic_info *diagnostic, const char *msgid,
! va_list *args, const char *file, int line,
diagnostic_t kind)
{
diagnostic->message.err_no = errno;
diagnostic->message.args_ptr = args;
diagnostic->message.format_spec = _(msgid);
/* If the diagnostic message doesn't specify a location,
! use FILE and LINE. */
if (!text_specifies_location (&diagnostic->message, &diagnostic->location))
! {
! diagnostic->location.file = file;
! diagnostic->location.line = line;
! }
diagnostic->kind = kind;
}
--- 786,801 ----
void
diagnostic_set_info (diagnostic_info *diagnostic, const char *msgid,
! va_list *args, location_t location,
diagnostic_t kind)
{
diagnostic->message.err_no = errno;
diagnostic->message.args_ptr = args;
diagnostic->message.format_spec = _(msgid);
/* If the diagnostic message doesn't specify a location,
! use LOCATION. */
if (!text_specifies_location (&diagnostic->message, &diagnostic->location))
! diagnostic->location = location;
diagnostic->kind = kind;
}
*************** inform (const char *msgid, ...)
*** 1159,1166 ****
va_list ap;
va_start (ap, msgid);
! diagnostic_set_info (&diagnostic, msgid, &ap, input_filename, input_line,
! DK_NOTE);
report_diagnostic (&diagnostic);
va_end (ap);
}
--- 1156,1162 ----
va_list ap;
va_start (ap, msgid);
! diagnostic_set_info (&diagnostic, msgid, &ap, input_location, DK_NOTE);
report_diagnostic (&diagnostic);
va_end (ap);
}
*************** warning (const char *msgid, ...)
*** 1174,1181 ****
va_list ap;
va_start (ap, msgid);
! diagnostic_set_info (&diagnostic, msgid, &ap, input_filename, input_line,
! DK_WARNING);
report_diagnostic (&diagnostic);
va_end (ap);
}
--- 1170,1176 ----
va_list ap;
va_start (ap, msgid);
! diagnostic_set_info (&diagnostic, msgid, &ap, input_location, DK_WARNING);
report_diagnostic (&diagnostic);
va_end (ap);
}
*************** pedwarn (const char *msgid, ...)
*** 1195,1202 ****
va_list ap;
va_start (ap, msgid);
! diagnostic_set_info (&diagnostic, msgid, &ap, input_filename, input_line,
! pedantic_error_kind ());
report_diagnostic (&diagnostic);
va_end (ap);
}
--- 1190,1197 ----
va_list ap;
va_start (ap, msgid);
! diagnostic_set_info (&diagnostic, msgid, &ap, input_location,
! pedantic_error_kind ());
report_diagnostic (&diagnostic);
va_end (ap);
}
*************** error (const char *msgid, ...)
*** 1210,1217 ****
va_list ap;
va_start (ap, msgid);
! diagnostic_set_info (&diagnostic, msgid, &ap, input_filename, input_line,
! DK_ERROR);
report_diagnostic (&diagnostic);
va_end (ap);
}
--- 1205,1211 ----
va_list ap;
va_start (ap, msgid);
! diagnostic_set_info (&diagnostic, msgid, &ap, input_location, DK_ERROR);
report_diagnostic (&diagnostic);
va_end (ap);
}
*************** sorry (const char *msgid, ...)
*** 1226,1233 ****
va_list ap;
va_start (ap, msgid);
! diagnostic_set_info (&diagnostic, msgid, &ap, input_filename, input_line,
! DK_SORRY);
report_diagnostic (&diagnostic);
va_end (ap);
}
--- 1220,1226 ----
va_list ap;
va_start (ap, msgid);
! diagnostic_set_info (&diagnostic, msgid, &ap, input_location, DK_SORRY);
report_diagnostic (&diagnostic);
va_end (ap);
}
*************** fatal_error (const char *msgid, ...)
*** 1242,1249 ****
va_list ap;
va_start (ap, msgid);
! diagnostic_set_info (&diagnostic, msgid, &ap, input_filename, input_line,
! DK_FATAL);
report_diagnostic (&diagnostic);
va_end (ap);
--- 1235,1241 ----
va_list ap;
va_start (ap, msgid);
! diagnostic_set_info (&diagnostic, msgid, &ap, input_location, DK_FATAL);
report_diagnostic (&diagnostic);
va_end (ap);
*************** internal_error (const char *msgid, ...)
*** 1262,1269 ****
va_list ap;
va_start (ap, msgid);
! diagnostic_set_info (&diagnostic, msgid, &ap, input_filename, input_line,
! DK_ICE);
report_diagnostic (&diagnostic);
va_end (ap);
--- 1254,1260 ----
va_list ap;
va_start (ap, msgid);
! diagnostic_set_info (&diagnostic, msgid, &ap, input_location, DK_ICE);
report_diagnostic (&diagnostic);
va_end (ap);
*************** warning_with_decl (tree decl, const char
*** 1288,1295 ****
return;
diagnostic_set_info (&diagnostic, msgid, &ap,
! DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl),
! DK_WARNING);
diagnostic_for_decl (global_dc, &diagnostic, decl);
va_end (ap);
}
--- 1279,1285 ----
return;
diagnostic_set_info (&diagnostic, msgid, &ap,
! DECL_SOURCE_LOCATION (decl), DK_WARNING);
diagnostic_for_decl (global_dc, &diagnostic, decl);
va_end (ap);
}
*************** pedwarn_with_decl (tree decl, const char
*** 1308,1315 ****
return;
diagnostic_set_info (&diagnostic, msgid, &ap,
! DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl),
! pedantic_error_kind ());
diagnostic_for_decl (global_dc, &diagnostic, decl);
va_end (ap);
--- 1298,1304 ----
return;
diagnostic_set_info (&diagnostic, msgid, &ap,
! DECL_SOURCE_LOCATION (decl), pedantic_error_kind ());
diagnostic_for_decl (global_dc, &diagnostic, decl);
va_end (ap);
*************** error_with_decl (tree decl, const char *
*** 1323,1330 ****
va_start (ap, msgid);
diagnostic_set_info (&diagnostic, msgid, &ap,
! DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl),
! DK_ERROR);
diagnostic_for_decl (global_dc, &diagnostic, decl);
va_end (ap);
}
--- 1312,1318 ----
va_start (ap, msgid);
diagnostic_set_info (&diagnostic, msgid, &ap,
! DECL_SOURCE_LOCATION (decl), DK_ERROR);
diagnostic_for_decl (global_dc, &diagnostic, decl);
va_end (ap);
}
Index: diagnostic.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/diagnostic.h,v
retrieving revision 1.60
diff -c -3 -p -r1.60 diagnostic.h
*** diagnostic.h 22 Jun 2003 08:05:39 -0000 1.60
--- diagnostic.h 28 Jun 2003 15:18:59 -0000
*************** extern void diagnostic_flush_buffer (dia
*** 298,304 ****
extern void diagnostic_report_diagnostic (diagnostic_context *,
diagnostic_info *);
extern void diagnostic_set_info (diagnostic_info *, const char *, va_list *,
! const char *, int, diagnostic_t);
extern char *diagnostic_build_prefix (diagnostic_info *);
/* Pure text formatting support functions. */
--- 298,304 ----
extern void diagnostic_report_diagnostic (diagnostic_context *,
diagnostic_info *);
extern void diagnostic_set_info (diagnostic_info *, const char *, va_list *,
! location_t, diagnostic_t);
extern char *diagnostic_build_prefix (diagnostic_info *);
/* Pure text formatting support functions. */
Index: rtl-error.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/rtl-error.c,v
retrieving revision 1.10
diff -c -3 -p -r1.10 rtl-error.c
*** rtl-error.c 16 Jun 2003 11:30:21 -0000 1.10
--- rtl-error.c 28 Jun 2003 15:18:59 -0000
*************** Boston, MA 02111-1307, USA. */
*** 33,52 ****
#include "intl.h"
#include "diagnostic.h"
! static void file_and_line_for_asm PARAMS ((rtx, const char **, int *));
static void diagnostic_for_asm PARAMS ((rtx, const char *, va_list *,
diagnostic_t));
! /* Figure file and line of the given INSN. */
! static void
! file_and_line_for_asm (insn, pfile, pline)
rtx insn;
- const char **pfile;
- int *pline;
{
rtx body = PATTERN (insn);
rtx asmop;
!
/* Find the (or one of the) ASM_OPERANDS in the insn. */
if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
asmop = SET_SRC (body);
--- 33,51 ----
#include "intl.h"
#include "diagnostic.h"
! static location_t location_for_asm PARAMS ((rtx));
static void diagnostic_for_asm PARAMS ((rtx, const char *, va_list *,
diagnostic_t));
! /* Figure the location of the given INSN. */
! static location_t
! location_for_asm (insn)
rtx insn;
{
rtx body = PATTERN (insn);
rtx asmop;
! location_t loc;
!
/* Find the (or one of the) ASM_OPERANDS in the insn. */
if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
asmop = SET_SRC (body);
*************** file_and_line_for_asm (insn, pfile, plin
*** 63,76 ****
if (asmop)
{
! *pfile = ASM_OPERANDS_SOURCE_FILE (asmop);
! *pline = ASM_OPERANDS_SOURCE_LINE (asmop);
}
else
! {
! *pfile = input_filename;
! *pline = input_line;
! }
}
/* Report a diagnostic MESSAGE (an errror or a WARNING) at the line number
--- 62,73 ----
if (asmop)
{
! loc.file = ASM_OPERANDS_SOURCE_FILE (asmop);
! loc.line = ASM_OPERANDS_SOURCE_LINE (asmop);
}
else
! loc = input_location;
! return loc;
}
/* Report a diagnostic MESSAGE (an errror or a WARNING) at the line number
*************** diagnostic_for_asm (insn, msg, args_ptr,
*** 84,93 ****
diagnostic_t kind;
{
diagnostic_info diagnostic;
!
! diagnostic_set_info (&diagnostic, msg, args_ptr, NULL, 0, kind);
! file_and_line_for_asm (insn, &diagnostic.location.file,
! &diagnostic.location.line);
report_diagnostic (&diagnostic);
}
--- 81,89 ----
diagnostic_t kind;
{
diagnostic_info diagnostic;
!
! diagnostic_set_info (&diagnostic, msg, args_ptr,
! location_for_asm (insn), kind);
report_diagnostic (&diagnostic);
}
Index: c-errors.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-errors.c,v
retrieving revision 1.9
diff -c -3 -p -r1.9 c-errors.c
*** c-errors.c 17 May 2003 22:21:25 -0000 1.9
--- c-errors.c 28 Jun 2003 15:19:00 -0000
*************** pedwarn_c99 (const char *msgid, ...)
*** 38,44 ****
va_list ap;
va_start (ap, msgid);
! diagnostic_set_info (&diagnostic, msgid, &ap, input_filename, input_line,
flag_isoc99 ? pedantic_error_kind () : DK_WARNING);
report_diagnostic (&diagnostic);
va_end (ap);
--- 38,44 ----
va_list ap;
va_start (ap, msgid);
! diagnostic_set_info (&diagnostic, msgid, &ap, input_location,
flag_isoc99 ? pedantic_error_kind () : DK_WARNING);
report_diagnostic (&diagnostic);
va_end (ap);
Index: c-format.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-format.c,v
retrieving revision 1.42
diff -c -3 -p -r1.42 c-format.c
*** c-format.c 28 Jun 2003 00:30:26 -0000 1.42
--- c-format.c 28 Jun 2003 15:19:06 -0000
*************** status_warning (int *status, const char
*** 1004,1010 ****
{
/* This duplicates the warning function behavior. */
diagnostic_set_info (&diagnostic, _(msgid), &ap,
! input_filename, input_line, DK_WARNING);
report_diagnostic (&diagnostic);
}
--- 1004,1010 ----
{
/* This duplicates the warning function behavior. */
diagnostic_set_info (&diagnostic, _(msgid), &ap,
! input_location, DK_WARNING);
report_diagnostic (&diagnostic);
}
Index: cp/cp-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-tree.h,v
retrieving revision 1.860
diff -c -3 -p -r1.860 cp-tree.h
*** cp/cp-tree.h 26 Jun 2003 00:06:58 -0000 1.860
--- cp/cp-tree.h 28 Jun 2003 15:19:18 -0000
*************** extern const char *decl_as_string (tree
*** 3820,3827 ****
extern const char *expr_as_string (tree, int);
extern const char *context_as_string (tree, int);
extern const char *lang_decl_name (tree, int);
- extern const char *cp_file_of (tree);
- extern int cp_line_of (tree);
extern const char *language_to_string (enum languages, int);
extern void print_instantiation_context (void);
--- 3820,3825 ----
Index: cp/error.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/error.c,v
retrieving revision 1.208
diff -c -3 -p -r1.208 error.c
*** cp/error.c 21 May 2003 01:39:38 -0000 1.208
--- cp/error.c 28 Jun 2003 15:19:22 -0000
*************** static bool cp_printer (output_buffer *,
*** 113,118 ****
--- 113,119 ----
static void print_non_consecutive_character (output_buffer *, int);
static void print_integer (output_buffer *, HOST_WIDE_INT);
static tree locate_error (const char *, va_list);
+ static location_t location_of (tree);
void
init_error (void)
*************** lang_decl_name (tree decl, int v)
*** 2121,2160 ****
return output_finalize_message (scratch_buffer);
}
! const char *
! cp_file_of (tree t)
{
if (TREE_CODE (t) == PARM_DECL && DECL_CONTEXT (t))
! return DECL_SOURCE_FILE (DECL_CONTEXT (t));
else if (TYPE_P (t))
! return DECL_SOURCE_FILE (TYPE_MAIN_DECL (t));
! else if (TREE_CODE (t) == OVERLOAD)
! return DECL_SOURCE_FILE (OVL_FUNCTION (t));
! else
! return DECL_SOURCE_FILE (t);
! }
!
! int
! cp_line_of (tree t)
! {
! int line = 0;
! if (TREE_CODE (t) == PARM_DECL && DECL_CONTEXT (t))
! line = DECL_SOURCE_LINE (DECL_CONTEXT (t));
! if (TREE_CODE (t) == TYPE_DECL && DECL_ARTIFICIAL (t)
! && TYPE_MAIN_DECL (TREE_TYPE (t)))
! t = TREE_TYPE (t);
!
! if (TYPE_P (t))
! line = DECL_SOURCE_LINE (TYPE_MAIN_DECL (t));
else if (TREE_CODE (t) == OVERLOAD)
! line = DECL_SOURCE_LINE (OVL_FUNCTION (t));
! else
! line = DECL_SOURCE_LINE (t);
!
! if (line == 0)
! return input_line;
!
! return line;
}
/* Now the interfaces from error et al to dump_type et al. Each takes an
--- 2122,2138 ----
return output_finalize_message (scratch_buffer);
}
! static location_t
! location_of (tree t)
{
if (TREE_CODE (t) == PARM_DECL && DECL_CONTEXT (t))
! t = DECL_CONTEXT (t);
else if (TYPE_P (t))
! t = TYPE_MAIN_DECL (t);
else if (TREE_CODE (t) == OVERLOAD)
! t = OVL_FUNCTION (t);
!
! return DECL_SOURCE_LOCATION (t);
}
/* Now the interfaces from error et al to dump_type et al. Each takes an
*************** cp_error_at (const char *msgid, ...)
*** 2612,2618 ****
va_start (ap, msgid);
diagnostic_set_info (&diagnostic, msgid, &ap,
! cp_file_of (here), cp_line_of (here), DK_ERROR);
report_diagnostic (&diagnostic);
va_end (ap);
}
--- 2590,2596 ----
va_start (ap, msgid);
diagnostic_set_info (&diagnostic, msgid, &ap,
! location_of (here), DK_ERROR);
report_diagnostic (&diagnostic);
va_end (ap);
}
*************** cp_warning_at (const char *msgid, ...)
*** 2630,2636 ****
va_start (ap, msgid);
diagnostic_set_info (&diagnostic, msgid, &ap,
! cp_file_of (here), cp_line_of (here), DK_WARNING);
report_diagnostic (&diagnostic);
va_end (ap);
}
--- 2608,2614 ----
va_start (ap, msgid);
diagnostic_set_info (&diagnostic, msgid, &ap,
! location_of (here), DK_WARNING);
report_diagnostic (&diagnostic);
va_end (ap);
}
*************** cp_pedwarn_at (const char *msgid, ...)
*** 2648,2655 ****
va_start (ap, msgid);
diagnostic_set_info (&diagnostic, msgid, &ap,
! cp_file_of (here), cp_line_of (here),
! pedantic_error_kind());
report_diagnostic (&diagnostic);
va_end (ap);
}
--- 2626,2632 ----
va_start (ap, msgid);
diagnostic_set_info (&diagnostic, msgid, &ap,
! location_of (here), pedantic_error_kind());
report_diagnostic (&diagnostic);
va_end (ap);
}
Index: testsuite/g++.old-deja/g++.robertl/eb133a.C
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.old-deja/g++.robertl/eb133a.C,v
retrieving revision 1.2
diff -c -3 -p -r1.2 eb133a.C
*** testsuite/g++.old-deja/g++.robertl/eb133a.C 1 May 2003 02:02:58 -0000 1.2
--- testsuite/g++.old-deja/g++.robertl/eb133a.C 28 Jun 2003 15:19:22 -0000
***************
*** 3,8 ****
--- 3,10 ----
// From: Klaus-Georg Adams <Klaus-Georg.Adams@chemie.uni-karlsruhe.de>
// Reported against EGCS snaps 98/06/28.
+ // { dg-error "forward declaration" "" { target *-*-* } 0 }
+
int main()
{
try {
Index: testsuite/g++.old-deja/g++.robertl/eb133b.C
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.old-deja/g++.robertl/eb133b.C,v
retrieving revision 1.2
diff -c -3 -p -r1.2 eb133b.C
*** testsuite/g++.old-deja/g++.robertl/eb133b.C 1 May 2003 02:02:58 -0000 1.2
--- testsuite/g++.old-deja/g++.robertl/eb133b.C 28 Jun 2003 15:19:22 -0000
***************
*** 3,15 ****
// From: Klaus-Georg Adams <Klaus-Georg.Adams@chemie.uni-karlsruhe.de>
// Reported against EGCS snaps 98/06/28.
using namespace std;
int main()
{
try {
}
! catch (bad_alloc) { // { dg-error "" } parse error
return 1;
}
return 0;
--- 3,17 ----
// From: Klaus-Georg Adams <Klaus-Georg.Adams@chemie.uni-karlsruhe.de>
// Reported against EGCS snaps 98/06/28.
+ // { dg-error "forward declaration" "" { target *-*-* } 0 }
+
using namespace std;
int main()
{
try {
}
! catch (bad_alloc) { // { dg-error "invalid use" }
return 1;
}
return 0;
Index: testsuite/g++.old-deja/g++.robertl/eb133.C
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.old-deja/g++.robertl/eb133.C,v
retrieving revision 1.6
diff -c -3 -p -r1.6 eb133.C
*** testsuite/g++.old-deja/g++.robertl/eb133.C 1 May 2003 02:02:58 -0000 1.6
--- testsuite/g++.old-deja/g++.robertl/eb133.C 28 Jun 2003 15:19:22 -0000
***************
*** 3,18 ****
// From: Klaus-Georg Adams <Klaus-Georg.Adams@chemie.uni-karlsruhe.de>
// Reported against EGCS snaps 98/06/28.
using namespace std;
int main()
{
try {
}
! catch (bad_alloc) { // { dg-error "" } parse error
return 1;
}
return 0;
}
-
--- 3,19 ----
// From: Klaus-Georg Adams <Klaus-Georg.Adams@chemie.uni-karlsruhe.de>
// Reported against EGCS snaps 98/06/28.
+ // { dg-error "forward declaration" "" { target *-*-* } 0 }
+
using namespace std;
int main()
{
try {
}
! catch (bad_alloc) { // { dg-error "invalid use" }
return 1;
}
return 0;
}