In this third instalment the diagnostic machinery -- when faced with the virtual location of a token resulting from macro expansion -- uses the new linemap APIs to unwind the stack of macro expansions that led to that token and emits a [hopefully] more useful message than what we have today. diagnostic_report_current_module has been slightly changed to use the location given by client code instead of the global input_location variable. This results in more precise diagnostic locations in general but then the patch adjusts some C++ tests which output changed as a result of this. Three new regression tests have been added. The mandatory screenshot goes like this: [dodji@adjoa gcc]$ cat -n test.c 1 #define OPERATE(OPRD1, OPRT, OPRD2) \ 2 OPRD1 OPRT OPRD2; 3 4 #define SHIFTL(A,B) \ 5 OPERATE (A,<<,B) 6 7 #define MULT(A) \ 8 SHIFTL (A,1) 9 10 void 11 g () 12 { 13 MULT (1.0);/* 1.0 << 1; <-- so this is an error. */ 14 } [dodji@adjoa gcc]$ ./cc1 -quiet -ftrack-macro-expansion test.c test.c: In function 'g': test.c:5:14: erreur: invalid operands to binary << (have 'double' and 'int') test.c:2:9: note: in expansion of macro 'OPERATE' test.c:5:3: note: expanded from here test.c:5:14: note: in expansion of macro 'SHIFTL' test.c:8:3: note: expanded from here test.c:8:3: note: in expansion of macro 'MULT2' test.c:13:3: note: expanded from here Co-Authored-By: Dodji Seketeli <dodji@redhat.com> From-SVN: r180083
58 lines
2.3 KiB
C
58 lines
2.3 KiB
C
/* Various declarations for language-independent diagnostics
|
|
subroutines that are only for use in the compilers proper and not
|
|
the driver or other programs.
|
|
Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
|
|
2010, Free Software Foundation, Inc.
|
|
|
|
This file is part of GCC.
|
|
|
|
GCC is free software; you can redistribute it and/or modify it under
|
|
the terms of the GNU General Public License as published by the Free
|
|
Software Foundation; either version 3, or (at your option) any later
|
|
version.
|
|
|
|
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with GCC; see the file COPYING3. If not see
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
#ifndef GCC_TREE_DIAGNOSTIC_H
|
|
#define GCC_TREE_DIAGNOSTIC_H
|
|
|
|
/* TREE_BLOCK if the diagnostic is to be reported in some inline
|
|
function inlined into other function, otherwise NULL. */
|
|
#define diagnostic_abstract_origin(DI) \
|
|
((tree) diagnostic_info_auxiliary_data (DI))
|
|
|
|
/* Function of last diagnostic message; more generally, function such
|
|
that if next diagnostic message is in it then we don't have to
|
|
mention the function name. */
|
|
#define diagnostic_last_function(DC) \
|
|
((tree) diagnostic_context_auxiliary_data (DC))
|
|
|
|
/* True if the last function in which a diagnostic was reported is
|
|
different from the current one. */
|
|
#define diagnostic_last_function_changed(DC, DI) \
|
|
(diagnostic_last_function (DC) != (diagnostic_abstract_origin (DI) \
|
|
? diagnostic_abstract_origin (DI) \
|
|
: current_function_decl))
|
|
|
|
/* Remember the current function as being the last one in which we report
|
|
a diagnostic. */
|
|
#define diagnostic_set_last_function(DC, DI) \
|
|
diagnostic_context_auxiliary_data (DC) \
|
|
= (((DI) && diagnostic_abstract_origin (DI)) \
|
|
? diagnostic_abstract_origin (DI) \
|
|
: current_function_decl)
|
|
|
|
void default_tree_diagnostic_starter (diagnostic_context *, diagnostic_info *);
|
|
extern void diagnostic_report_current_function (diagnostic_context *,
|
|
diagnostic_info *);
|
|
void virt_loc_aware_diagnostic_finalizer (diagnostic_context *,
|
|
diagnostic_info *);
|
|
#endif /* ! GCC_TREE_DIAGNOSTIC_H */
|