AIX supports "FAT" libraries containing 32 bit and 64 bit objects
(similar to Darwin), but commands for manipulating libraries do not
default to accept both 32 bit and 64 bit object files. While updating
the AIX configuration to support building and running GCC as a 64 bit
application, I have encountered some build libraries that hard code
AR=ar instead of testing the environment.
This patch adds AR_CHECK_TOOL(AR, ar) to configure.ac for the two
libraries and updates Makefile.in to accept the substitution.
2020-05-23 David Edelsohn <dje.gcc@gmail.com>
libcpp/ChangeLog:
* Makefile.in (AR): Substitute @AR@.
* configure.ac (CHECK_PROG AR): New.
* configure: Regenerate.
libdecnumber/ChangeLog:
* Makefile.in (AR): Substitute @AR@.
* configure.ac (CHECK_PROG AR): New.
* configure: Regenerate.
_cpp_find_file has 3 bool arguments, at most one of which is ever set.
Ripe for replacing with a 4-state enum. Also, this is C++, so
'typedef struct Foo Foo' is unnecessary.
* internal.h (typedef _cpp_file): Delete, unnecessary in C++.
(enum _cpp_find_file_kind): New.
(_cpp_find_file): Use it, not 3 bools.
* files.c (_cpp_find_file): Use _cpp_find_file_kind enum, not
bools.
(cpp_make_system_header): Break overly long line.
(_cpp_stack_include, _cpp_fake_include)
(_cpp_do_file_change, _cpp_compare_file_date, _cpp_has_header): Adjust.
* init.c (cpp_read_main): Adjust _cpp_find_file call.
This fixes a bunch of poorly formatted decls, marks some getters as
PURE, deletes some C-relevant bool hackery, and finally uses a
passed-in location rather than deducing a closely-related but not
necessarily the same location.
* include/cpplib.h (cpp_get_otions, cpp_get_callbacks)
(cpp_get_deps): Mark as PURE.
* include/line-map.h (get_combined_adhoc_loc)
(get_location_from_adhoc_loc, get_pure_location): Reformat decls.
* internal.h (struct lexer_state): Clarify comment.
* system.h: Remove now-unneeded bool hackery.
* files.c (_cpp_find_file): Store LOC not highest_location.
pr95149 is a false positive static analysis checker. But it
encouranged me to fix raw string lexing, which does contain a
complicated macro and pointers to local variables. The
reimplementation does away with that macro. Part of the complication
is we need to undo some of the fresh line processing -- trigraph notes
and escaped line continuations. But the undone characters need to go
through the raw string processing, as they can legitimately be part of
the prefix marker. however, in this reformulation we only process one
line marker at a time[*], so there's a limited number of undone
characters. We can arrange the buffering to make sure we don't split
such an append sequence, and then simply take the characters from the
append buffer.
The prefix scanner had a switch statement, which I discovered was not
optimized as well as an if of a bunch of explicit comparisons (pr
95208 filed).
Finally I adjusted the failure mode. When we get a bad prefix, we lex
up until the next '"', thus often swallowing the whole raw string.
Previously we'd bail and then the lexer would usually generate stupid
tokens, particularly when meeting the ending '"'.
libcpp/
* lex.c (struct lit_accum): New.
(bufring_append): Replace by lit_accum::append.
(lex_raw_string): Reimplement, using fragments of the old version.
(lex_string): Adjust lex_raw_string call.
gcc/testsuite/
* c-c++-common/raw-string-14.c: Adjust errors.
* c-c++-common/raw-string-16.c: Likewise.
* c-c++-common/raw-string-5.c: Likewise.
This was another latent case of us losing an EOF token, but succeeding
anyway. Since my patch to make us pay more attention to EOFs it came
to light. We also need to keep the EOF if we fall off the end of the
main file. Forced includes look like regular nested includes at this
point.
PR preprocessor/95182
libcpp/
* macro.c (collect_args): Preserve EOFif we fell out of the main
file.
(cpp_get_token_1): Reformat a couple of short lines.
C++20 isn't final quite yet, but all that remains is formalities, so let's
go ahead and change all the references.
I think for the next C++ standard we can just call it C++23 rather than
C++2b, since the committee has been consistent about time-based releases
rather than feature-based.
gcc/c-family/ChangeLog
2020-05-13 Jason Merrill <jason@redhat.com>
* c.opt (std=c++20): Make c++2a the alias.
(std=gnu++20): Likewise.
* c-common.h (cxx_dialect): Change cxx2a to cxx20.
* c-opts.c: Adjust.
* c-cppbuiltin.c: Adjust.
* c-ubsan.c: Adjust.
* c-warn.c: Adjust.
gcc/cp/ChangeLog
2020-05-13 Jason Merrill <jason@redhat.com>
* call.c, class.c, constexpr.c, constraint.cc, decl.c, init.c,
lambda.c, lex.c, method.c, name-lookup.c, parser.c, pt.c, tree.c,
typeck2.c: Change cxx2a to cxx20.
libcpp/ChangeLog
2020-05-13 Jason Merrill <jason@redhat.com>
* include/cpplib.h (enum c_lang): Change CXX2A to CXX20.
* init.c, lex.c: Adjust.
My recent C++ parser change to pay attention to EOF location uncovered
a separate bug. The preprocesor's EOF logic would set the EOF
location to be the beginning of the last line of text in the file --
not the 'line' after that, which contains no characters. Mostly.
This fixes things so that when we attempt to read the last line of the
main file, we don't pop the buffer until the tokenizer has a chance to
create an EOF token with the correct location information. It is then
responsible for popping the buffer. As it happens, raw string literal
tokenizing contained a bug -- it would increment the line number
prematurely, because it cached buffer->cur in a local variable, but
checked buffer->cur before updating it to figure out if it was at end
of file. We fix up that too.
The EOF token intentionally doesn't have a column number -- it's not a
position on a line, it's a non-existant line.
The testsuite churn is just correcting the EOF location diagnostics.
libcpp/
PR preprocessor/95013
* lex.c (lex_raw_string): Process line notes before incrementing.
Correct incrementing condition. Adjust for new
_cpp_get_fresh_line EOF behaviour.
(_cpp_get_fresh_line): Do not pop buffer at EOF, increment line
instead.
(_cpp_lex_direct): Adjust for new _cpp_get_fresh_line behaviour.
(cpp_directive_only_process): Assert we got a fresh line.
* traditional.c (_cpp_read_logical_line_trad): Adjust for new
_cpp_get_fresh_line behaviour.
gcc/testsuite/
* c-c++-common/goacc/pr79428-1.c: Adjust EOF diagnostic location.
* c-c++-common/gomp/pr79428-2.c: Likewise.
* g++.dg/cpp0x/decltype63.C: Likewise.
* g++.dg/cpp0x/gen-attrs-64.C: Likewise.
* g++.dg/cpp0x/pr68726.C: Likewise.
* g++.dg/cpp0x/pr78341.C: Likewise.
* g++.dg/cpp1y/pr65202.C: Likewise.
* g++.dg/cpp1y/pr65340.C: Likewise.
* g++.dg/cpp1y/pr68578.C: Likewise.
* g++.dg/cpp1z/class-deduction44.C: Likewise.
* g++.dg/diagnostic/unclosed-extern-c.C: Likewise.
* g++.dg/diagnostic/unclosed-function.C: Likewise.
* g++.dg/diagnostic/unclosed-namespace.C: Likewise.
* g++.dg/diagnostic/unclosed-struct.C: Likewise.
* g++.dg/ext/pr84598.C: Likewise.
* g++.dg/other/switch4.C: Likewise.
* g++.dg/parse/attr4.C: Likewise.
* g++.dg/parse/cond4.C: Likewise.
* g++.dg/parse/crash10.C: Likewise.
* g++.dg/parse/crash18.C: Likewise.
* g++.dg/parse/crash27.C: Likewise.
* g++.dg/parse/crash34.C: Likewise.
* g++.dg/parse/crash35.C: Likewise.
* g++.dg/parse/crash52.C: Likewise.
* g++.dg/parse/crash59.C: Likewise.
* g++.dg/parse/crash61.C: Likewise.
* g++.dg/parse/crash67.C: Likewise.
* g++.dg/parse/error14.C: Likewise.
* g++.dg/parse/error56.C: Likewise.
* g++.dg/parse/invalid1.C: Likewise.
* g++.dg/parse/parameter-declaration-1.C: Likewise.
* g++.dg/parse/parser-pr28152-2.C: Likewise.
* g++.dg/parse/parser-pr28152.C: Likewise.
* g++.dg/parse/pr68722.C: Likewise.
* g++.dg/pr46852.C: Likewise.
* g++.dg/pr46868.C: Likewise.
* g++.dg/template/crash115.C: Likewise.
* g++.dg/template/crash43.C: Likewise.
* g++.dg/template/crash90.C: Likewise.
* g++.dg/template/error-recovery1.C: Likewise.
* g++.dg/template/error57.C: Likewise.
* g++.old-deja/g++.other/crash31.C: Likewise.
* gcc.dg/empty-source-2.c: Likewise.
* gcc.dg/empty-source-3.c: Likewise.
* gcc.dg/noncompile/pr30552-3.c: Likewise.
* gcc.dg/noncompile/pr35447-1.c: Likewise.
* gcc.dg/pr20245-1.c: Likewise.
* gcc.dg/pr28419.c: Likewise.
* gcc.dg/rtl/truncated-rtl-file.c: Likewise.
* gcc.dg/unclosed-init.c: Likewise.
* obj-c++.dg/property/property-neg-6.mm: Likewise.
* obj-c++.dg/syntax-error-10.mm: Likewise.
* obj-c++.dg/syntax-error-8.mm: Likewise.
* obj-c++.dg/syntax-error-9.mm: Likewise.
Since on Intel CET enabled host, dlopen in Intel CET enabled applications
fails on shared libraries which aren't Intel CET enabled, compile with
-fcf-protection on Intel CET enabled host when jit is enabled to enable
Intel CET on libgccjit.
* Makefile.in (CET_HOST_FLAGS): New.
(COMPILER): Add $(CET_HOST_FLAGS).
* configure.ac: Add GCC_CET_HOST_FLAGS(CET_HOST_FLAGS) and
AC_SUBST(CET_HOST_FLAGS). Clear CET_HOST_FLAGS if jit isn't
enabled.
* aclocal.m4: Regenerated.
* configure: Likewise.
The existing directives-only code (a) punched a hole through the
libcpp interface and (b) didn't support raw string literals. This
reimplements this preprocessing mode. I added a proper callback
interface, and adjusted c-ppoutput to use it. Sadly I cannot get rid
of the libcpp/internal.h include for unrelated reasons.
The new scanner is in lex.x, and works doing some backwards scanning
when it finds a charater of interest. This reduces the number of
cases one has to deal with in forward scanning. It may have different
failure mode than forward scanning on bad tokenization.
Finally, Moved some cpp tests from the c-specific dg.gcc/cpp directory
to the c-c++-common/cpp shared directory,
libcpp/
* directives-only.c: Delete.
* Makefile.in (libcpp_a_OBJS, libcpp_a_SOURCES): Remove it.
* include/cpplib.h (enum CPP_DO_task): New enum.
(cpp_directive_only_preprocess): Declare.
* internal.h (_cpp_dir_only_callbacks): Delete.
(_cpp_preprocess_dir_only): Delete.
* lex.c (do_peek_backslask, do_peek_next, do_peek_prev): New.
(cpp_directives_only_process): New implementation.
gcc/c-family/
Reimplement directives only processing.
* c-ppoutput.c (token_streamer): Ne.
(directives_only_cb): New. Swallow ...
(print_lines_directives_only): ... this.
(scan_translation_unit_directives_only): Reimplment using the
published interface.
gcc/testsuite/
* gcc.dg/cpp/counter-[23].c: Move to c-c+_-common/cpp.
* gcc.dg/cpp/dir-only-*: Likewise.
* c-c++-common/cpp/dir-only-[78].c: New.
I've noticed we claim in cxx-status.html that we implement P1042R1,
but it seems we don't implement any of the changes from there.
The following patch implements just the change that __VA_OPT__ determines
whether to expand to nothing or the enclosed tokens no longer based on
whether there were any tokens passed to __VA_ARGS__, but whether __VA_ARGS__
expands to any tokens (from testing apparently it has to be non-CPP_PADDING
tokens).
I'm afraid I'm completely lost about the padding preservation/removal
changes that are also in the paper, so haven't touched that part.
2020-02-14 Jakub Jelinek <jakub@redhat.com>
Partially implement P1042R1: __VA_OPT__ wording clarifications
PR preprocessor/92319
* macro.c (expand_arg): Move declarations before vaopt_state
definition.
(class vaopt_state): Move enum update_type definition earlier. Remove
m_allowed member, add m_arg and m_update members.
(vaopt_state::vaopt_state): Change last argument from bool any_args
to macro_arg *arg, initialize m_arg and m_update instead of m_allowed.
(vaopt_state::update): When bumping m_state from 1 to 2 and m_update
is ERROR, determine if __VA_ARGS__ expansion has any non-CPP_PADDING
tokens and set m_update to INCLUDE if it has any, DROP otherwise.
Return m_update instead of m_allowed ? INCLUDE : DROP in m_state >= 2.
(replace_args, create_iso_definition): Adjust last argument to
vaopt_state ctor.
* c-c++-common/cpp/va-opt-4.c: New test.
The standard says http://eel.is/c++draft/cpp.cond#7.sentence-2 that
__has_include can't appear at arbitrary places in the source. As we have
not recognized __has_include* outside of preprocessing directives in the
past, accepting it there now would be a regression. The patch does still
allow it in #define if it is then used in preprocessing directives, I guess
that use isn't strictly valid either, but clang seems to accept it.
2020-02-04 Jakub Jelinek <jakub@redhat.com>
* macro.c (builtin_has_include): Diagnose __has_include* use outside
of preprocessing directives.
* c-c++-common/cpp/has-include-1.c: New test.
* c-c++-common/cpp/has-include-next-1.c: New test.
* c-c++-common/gomp/has-include-1.c: New test.
Some of the following testcases ICE, because one of the cpp_get_token
calls in builtin_has_include reads the CPP_EOF token but the caller isn't
aware that CPP_EOF has been reached and will do another cpp_get_token.
get_token_no_padding is something that is use by the
has_attribute/has_builtin callbacks, which will first peek and will not
consume CPP_EOF (but will consume other tokens). The !SEEN_EOL ()
check on the other side doesn't work anymore and isn't really needed,
as we don't consume the EOF. The change adds one further error to the
pr88974.c testcase, if we wanted just one error per __has_include,
we could add some boolean whether we've emitted errors already and
only emit the first one we encounter (not implemented).
2020-02-04 Jakub Jelinek <jakub@redhat.com>
PR preprocessor/93545
* macro.c (cpp_get_token_no_padding): New function.
(builtin_has_include): Use it instead of cpp_get_token. Don't check
SEEN_EOL.
* c-c++-common/cpp/pr88974.c: Expect another diagnostics during error
recovery.
* c-c++-common/cpp/pr93545-1.c: New test.
* c-c++-common/cpp/pr93545-2.c: New test.
* c-c++-common/cpp/pr93545-3.c: New test.
* c-c++-common/cpp/pr93545-4.c: New test.
This commit:
commit e7c26e04b2 (tjteru/master)
Date: Wed Jan 22 14:54:26 2020 +0000
gcc: Add new configure options to allow static libraries to be selected
contains a couple of issues. First I failed to correctly regenerate
all of the configure files it should have done. Second, there was a
mistake in lib-link.m4, one of the conditions didn't use pure sh
syntax, I wrote this:
if x$lib_type = xauto || x$lib_type = xshared; then
When I should have written this:
if test "x$lib_type" = "xauto" || test "x$lib_type" = "xshared"; then
These issues were raised on the mailing list in these messages:
https://gcc.gnu.org/ml/gcc-patches/2020-01/msg01827.htmlhttps://gcc.gnu.org/ml/gcc-patches/2020-01/msg01921.html
config/ChangeLog:
* lib-link.m4 (AC_LIB_LINKFLAGS_BODY): Update shell syntax.
gcc/ChangeLog:
* configure: Regenerate.
intl/ChangeLog:
* configure: Regenerate.
libcpp/ChangeLog:
* configure: Regenerate.
libstdc++-v3/ChangeLog:
* configure: Regenerate.
The clever hack of '#define __has_include __has_include' breaks -dD
and -fdirectives-only, because that emits definitions. This turns
__has_include into a proper builtin macro. Thus it's never emitted
via -dD, and because use outside of directive processing is undefined,
we can just expand it anywhere.
PR preprocessor/93452
* internal.h (struct spec_nodes): Drop n__has_include{,_next}.
* directives.c (lex_macro_node): Don't check __has_include redef.
* expr.c (eval_token): Drop __has_include eval.
(parse_has_include): Move to ...
* macro.c (builtin_has_include): ... here.
(_cpp_builtin_macro_text): Eval __has_include{,_next}.
* include/cpplib.h (enum cpp_builtin_type): Add BT_HAS_INCLUDE{,_NEXT}.
* init.c (builtin_array): Add them.
(cpp_init_builtins): Drop __has_include{,_next} init here ...
* pch.c (cpp_read_state): ... and here.
* traditional.c (enum ls): Drop has_include states ...
(_cpp_scan_out_logical_line): ... and here.
The motivation behind this change is to make it easier for a user to
link against static libraries on a target where dynamic libraries are
the default library type (for example GNU/Linux).
Further, my motivation is really for linking libraries into GDB,
however, the binutils-gdb/config/ directory is a copy of gcc/config/
so changes for GDB need to be approved by the GCC project first.
After making this change in the gcc/config/ directory I've run
autoreconf on all of the configure scripts in the GCC tree and a
couple have been updated, so I'll use one of these to describe what my
change does.
Consider libcpp, this library links against libiconv. Currently if
the user builds on a system with both static and dynamic libiconv
installed then autotools will pick up the dynamic libiconv by
default. This is almost certainly the right thing to do.
However, if the user wants to link against static libiconv then things
are a little harder, they could remove the dynamic libiconv from their
system, but this is probably a bad idea (other things might depend on
that library), or the user can build their own version of libiconv,
install it into a unique prefix, and then configure gcc using the
--with-libiconv-prefix=DIR flag. This works fine, but is somewhat
annoying, the static library available, I just can't get autotools to
use it.
My change then adds a new flag --with-libiconv-type=TYPE, where type
is either auto, static, or shared. The default auto, ensures we keep
the existing behaviour unchanged.
If the user configures with --with-libiconv-type=static then the
configure script will ignore any dynamic libiconv it finds, and will
only look for a static libiconv, if no static libiconv is found then
the configure will continue as though there is no libiconv at all
available.
Similarly a user can specify --with-libiconv-type=shared and force the
use of shared libiconv, any static libiconv will be ignored.
As I've implemented this change within the AC_LIB_LINKFLAGS_BODY macro
then only libraries configured using the AC_LIB_LINKFLAGS or
AC_LIB_HAVE_LINKFLAGS macros will gain the new configure flag.
If this is accepted into GCC then there will be follow on patches for
binutils and GDB to regenerate some configure scripts in those
projects.
For GCC only two configure scripts needed updated after this commit,
libcpp and libstdc++-v3, both of which link against libiconv.
config/ChangeLog:
* lib-link.m4 (AC_LIB_LINKFLAGS_BODY): Add new
--with-libXXX-type=... option. Use this to guide the selection of
either a shared library or a static library.
libcpp/ChangeLog:
* configure: Regenerate.
libstdc++-v3/ChangeLog:
* configure: Regenerate.
I noticed, but ignored this code when addressing p80005, but having
fixed up defined(X) on the modules branch, I could see where it came
from, and it's obviously wrong as we've just pulled out a string
contant from the token.
* expr.c (parse_has_include): Remove bogus controlling macro code.
__has_include is funky in that it is macro-like from the POV of #ifdef and
friends, but lexes its parenthesize argument #include-like. We were
failing the second part of that, because we used a forwarding macro to an
internal name, and hence always lexed the argument in macro-parameter
context. We componded that by not setting the right flag when lexing, so
it didn't even know. Mostly users got lucky.
This reimplements the handline.
1) Remove the forwarding, but declare object-like macros that
expand to themselves. This satisfies the #ifdef requirement
2) Correctly set angled_brackets when lexing the parameter. This tells
the lexer (a) <...> is a header name and (b) "..." is too (not a string).
3) Remove the in__has_include lexer state, just tell find_file that that's
what's happenning, so it doesn't emit an error.
We lose the (undocumented) ability to #undef __has_include. That may well
have been an accident of implementation. There are no tests for it.
We gain __has_include behaviour for all users of the preprocessors -- not
just the C-family ones that defined a forwarding macro.
libcpp/
PR preprocessor/80005
* include/cpplib.h (BT_HAS_ATTRIBUTE): Fix comment.
* internal.h (struct lexer_state): Delete in__has_include field.
(struct spec_nodes): Rename n__has_include{,_next}__ fields.
(_cpp_defined_macro_p): New.
(_cpp_find_file): Add has_include parm.
* directives.c (lex_macro_node): Combine defined,
__has_inline{,_next} checking.
(do_ifdef, do_ifndef): Use _cpp_defined_macro_p.
(_cpp_init_directives): Refactor.
* expr.c (parse_defined): Use _cpp_defined_macro_p.
(eval_token): Adjust parse_has_include calls.
(parse_has_include): Add OP parameter. Reimplement.
* files.c (_cpp_find_file): Add HAS_INCLUDE parm. Use it to
inhibit error message.
(_cpp_stack_include): Adjust _cpp_find_file call.
(_cpp_fake_include, _cpp_compare_file_date): Likewise.
(open_file_failed): Remove in__has_include check.
(_cpp_has_header): Adjust _cpp_find_file call.
* identifiers.c (_cpp_init_hashtable): Don't init
__has_include{,_next} here ...
* init.c (cpp_init_builtins): ... init them here. Define as
macros.
(cpp_read_main_file): Adjust _cpp_find_file call.
* pch.c (cpp_read_state): Adjust __has_include{,_next} access.
* traditional.c (_cpp_scan_out_locgical_line): Likewise.
gcc/c-family/
PR preprocessor/80005
* c-cppbuiltins.c (c_cpp_builtins): Don't define __has_include{,_next}.
gcc/testsuite/
PR preprocessor/80005
* g++.dg/cpp1y/feat-cxx14.C: Adjust.
* g++.dg/cpp1z/feat-cxx17.C: Adjust.
* g++.dg/cpp2a/feat-cxx2a.C: Adjust.
* g++.dg/cpp/pr80005.C: New.
the preprocessor evaluator has a skip_eval counter, but we weren't
checking it after parsing has_include(foo), but before looking for
foo. Resulting in unnecessary io for 'FALSE_COND && has_include <foo>'
PR preprocessor/93306
* expr.c (parse_has_include): Refactor. Check skip_eval before
looking.
This suppresses an array out of bounds warning in mkdeps.c as proposed
by Martin Sebor in the bugzilla.
array subscript 2 is outside array bounds of ‘const char [2]’
Since this warning does occur during bootstrap it currently breaks
werror builds on IBM Z.
The problem can be reproduced also on x86_64 by changing the inlining
threshold using: --param max-inline-insns-auto=80
Bootstrapped and regression tested on x86_64 and IBM Z.
libcpp/ChangeLog:
2020-01-16 Andreas Krebbel <krebbel@linux.ibm.com>
PR tree-optimization/92176
* mkdeps.c (deps_add_default_target): Avoid calling apply_vpath to
suppress an array out of bounds warning.
This patch adds support for associating a "diagnostic_path" with a
diagnostic: a sequence of events predicted by the compiler that leads to
the problem occurring, with their locations in the user's source,
text descriptions, and stack information (for handling interprocedural
paths).
For example, the following (hypothetical) error has a 3-event
intraprocedural path:
test.c: In function 'demo':
test.c:29:5: error: passing NULL as argument 1 to 'PyList_Append' which
requires a non-NULL parameter
29 | PyList_Append(list, item);
| ^~~~~~~~~~~~~~~~~~~~~~~~~
'demo': events 1-3
|
| 25 | list = PyList_New(0);
| | ^~~~~~~~~~~~~
| | |
| | (1) when 'PyList_New' fails, returning NULL
| 26 |
| 27 | for (i = 0; i < count; i++) {
| | ~~~
| | |
| | (2) when 'i < count'
| 28 | item = PyLong_FromLong(random());
| 29 | PyList_Append(list, item);
| | ~~~~~~~~~~~~~~~~~~~~~~~~~
| | |
| | (3) when calling 'PyList_Append', passing NULL from (1) as argument 1
|
The patch adds a new "%@" format code for printing event IDs, so that
in the above, the description of event (3) mentions event (1), showing
the user where the bogus NULL value comes from (the event IDs are
colorized to draw the user's attention to them).
There is a separation between data vs presentation: the above shows how
the diagnostic-printing code has consolidated the path into a single run
of events, since all the events are near each other and within the same
function; more complicated examples (such as interprocedural paths)
might be printed as multiple runs of events.
Examples of how interprocedural paths are printed can be seen in the
test suite (which uses a plugin to exercise the code without relying
on specific warnings using this functionality).
Other output formats include
- JSON,
- printing each event as a separate "note", and
- to not emit paths.
gcc/ChangeLog:
* Makefile.in (OBJS): Add tree-diagnostic-path.o.
* common.opt (fdiagnostics-path-format=): New option.
(diagnostic_path_format): New enum.
(fdiagnostics-show-path-depths): New option.
* coretypes.h (diagnostic_event_id_t): New forward decl.
* diagnostic-color.c (color_dict): Add "path".
* diagnostic-event-id.h: New file.
* diagnostic-format-json.cc (json_from_expanded_location): Make
non-static.
(json_end_diagnostic): Call context->make_json_for_path if it
exists and the diagnostic has a path.
(diagnostic_output_format_init): Clear context->print_path.
* diagnostic-path.h: New file.
* diagnostic-show-locus.c (colorizer::set_range): Special-case
when printing a run of events in a diagnostic_path so that they
all get the same color.
(layout::m_diagnostic_path_p): New field.
(layout::layout): Initialize it.
(layout::print_any_labels): Don't colorize the label text for an
event in a diagnostic_path.
(gcc_rich_location::add_location_if_nearby): Add
"restrict_to_current_line_spans" and "label" params. Pass the
former to layout.maybe_add_location_range; pass the latter
when calling add_range.
* diagnostic.c: Include "diagnostic-path.h".
(diagnostic_initialize): Initialize context->path_format and
context->show_path_depths.
(diagnostic_show_any_path): New function.
(diagnostic_path::interprocedural_p): New function.
(diagnostic_report_diagnostic): Call diagnostic_show_any_path.
(simple_diagnostic_path::num_events): New function.
(simple_diagnostic_path::get_event): New function.
(simple_diagnostic_path::add_event): New function.
(simple_diagnostic_event::simple_diagnostic_event): New ctor.
(simple_diagnostic_event::~simple_diagnostic_event): New dtor.
(debug): New overload taking a diagnostic_path *.
* diagnostic.def (DK_DIAGNOSTIC_PATH): New.
* diagnostic.h (enum diagnostic_path_format): New enum.
(json::value): New forward decl.
(diagnostic_context::path_format): New field.
(diagnostic_context::show_path_depths): New field.
(diagnostic_context::print_path): New callback field.
(diagnostic_context::make_json_for_path): New callback field.
(diagnostic_show_any_path): New decl.
(json_from_expanded_location): New decl.
* doc/invoke.texi (-fdiagnostics-path-format=): New option.
(-fdiagnostics-show-path-depths): New option.
(-fdiagnostics-color): Add "path" to description of default
GCC_COLORS; describe it.
(-fdiagnostics-format=json): Document how diagnostic paths are
represented in the JSON output format.
* gcc-rich-location.h (gcc_rich_location::add_location_if_nearby):
Add optional params "restrict_to_current_line_spans" and "label".
* opts.c (common_handle_option): Handle
OPT_fdiagnostics_path_format_ and
OPT_fdiagnostics_show_path_depths.
* pretty-print.c: Include "diagnostic-event-id.h".
(pp_format): Implement "%@" format code for printing
diagnostic_event_id_t *.
(selftest::test_pp_format): Add tests for "%@".
* selftest-run-tests.c (selftest::run_tests): Call
selftest::tree_diagnostic_path_cc_tests.
* selftest.h (selftest::tree_diagnostic_path_cc_tests): New decl.
* toplev.c (general_init): Initialize global_dc->path_format and
global_dc->show_path_depths.
* tree-diagnostic-path.cc: New file.
* tree-diagnostic.c (maybe_unwind_expanded_macro_loc): Make
non-static. Drop "diagnostic" param in favor of storing the
original value of "where" and re-using it.
(virt_loc_aware_diagnostic_finalizer): Update for dropped param of
maybe_unwind_expanded_macro_loc.
(tree_diagnostics_defaults): Initialize context->print_path and
context->make_json_for_path.
* tree-diagnostic.h (default_tree_diagnostic_path_printer): New
decl.
(default_tree_make_json_for_path): New decl.
(maybe_unwind_expanded_macro_loc): New decl.
gcc/c-family/ChangeLog:
* c-format.c (local_event_ptr_node): New.
(PP_FORMAT_CHAR_TABLE): Add entry for "%@".
(init_dynamic_diag_info): Initialize local_event_ptr_node.
* c-format.h (T_EVENT_PTR): New define.
gcc/testsuite/ChangeLog:
* gcc.dg/format/gcc_diag-10.c (diagnostic_event_id_t): New
typedef.
(test_diag): Add coverage of "%@".
* gcc.dg/plugin/diagnostic-path-format-default.c: New test.
* gcc.dg/plugin/diagnostic-path-format-inline-events-1.c: New test.
* gcc.dg/plugin/diagnostic-path-format-inline-events-2.c: New test.
* gcc.dg/plugin/diagnostic-path-format-inline-events-3.c: New test.
* gcc.dg/plugin/diagnostic-path-format-none.c: New test.
* gcc.dg/plugin/diagnostic-test-paths-1.c: New test.
* gcc.dg/plugin/diagnostic-test-paths-2.c: New test.
* gcc.dg/plugin/diagnostic-test-paths-3.c: New test.
* gcc.dg/plugin/diagnostic-test-paths-4.c: New test.
* gcc.dg/plugin/diagnostic_plugin_test_paths.c: New.
* gcc.dg/plugin/plugin.exp: Add the new plugin and test cases.
libcpp/ChangeLog:
* include/line-map.h (class diagnostic_path): New forward decl.
(rich_location::get_path): New accessor.
(rich_location::set_path): New function.
(rich_location::m_path): New field.
* line-map.c (rich_location::rich_location): Initialize m_path.
From-SVN: r280142
libcpp's label_text class wraps a text buffer, along with a flag to
determine if it "owns" the buffer.
The existing ctor exposed this directly, but I found it difficult
to remember the sense of flag, so this patch hides the ctor, in
favor of static member functions "borrow" and "take", to make
the effect on ownership explicit in the name.
gcc/c-family/ChangeLog:
* c-format.c (range_label_for_format_type_mismatch::get_text):
Replace label_text ctor called with true with label_text::take.
gcc/c/ChangeLog:
* c-objc-common.c (range_label_for_type_mismatch::get_text):
Replace label_text ctor calls.
gcc/cp/ChangeLog:
* error.c (range_label_for_type_mismatch::get_text): Replace
label_text ctor calls with label_text::borrow.
gcc/ChangeLog:
* gcc-rich-location.c
(maybe_range_label_for_tree_type_mismatch::get_text): Replace
label_text ctor call with label_text::borrow.
* gcc-rich-location.h (text_range_label::get_text): Replace
label_text ctor called with false with label_text::borrow.
libcpp/ChangeLog:
* include/line-map.h (label_text::label_text): Make private.
(label_text::borrow): New.
(label_text::take): New.
(label_text::take_or_copy): New.
From-SVN: r279153
contrib/ChangeLog
2019-12-09 Lewis Hyatt <lhyatt@gmail.com>
PR preprocessor/49973
* unicode/from_glibc/unicode_utils.py: Support script from
glibc (commit 464cd3) to extract character widths from Unicode data
files.
* unicode/from_glibc/utf8_gen.py: Likewise.
* unicode/UnicodeData.txt: Unicode v. 12.1.0 data file.
* unicode/EastAsianWidth.txt: Likewise.
* unicode/PropList.txt: Likewise.
* unicode/gen_wcwidth.py: New utility to generate
libcpp/generated_cpp_wcwidth.h with help from the glibc support
scripts and the Unicode data files.
* unicode/unicode-license.txt: Added.
* unicode/README: New explanatory file.
libcpp/ChangeLog
2019-12-09 Lewis Hyatt <lhyatt@gmail.com>
PR preprocessor/49973
* generated_cpp_wcwidth.h: New file generated by
../contrib/unicode/gen_wcwidth.py, supports new cpp_wcwidth function.
* charset.c (compute_next_display_width): New function to help
implement display columns.
(cpp_byte_column_to_display_column): Likewise.
(cpp_display_column_to_byte_column): Likewise.
(cpp_wcwidth): Likewise.
* include/cpplib.h (cpp_byte_column_to_display_column): Declare.
(cpp_display_column_to_byte_column): Declare.
(cpp_wcwidth): Declare.
(cpp_display_width): New function.
gcc/ChangeLog
2019-12-09 Lewis Hyatt <lhyatt@gmail.com>
PR preprocessor/49973
* input.c (location_compute_display_column): New function to help with
multibyte awareness in diagnostics.
(test_cpp_utf8): New self-test.
(input_c_tests): Call the new test.
* input.h (location_compute_display_column): Declare.
* diagnostic-show-locus.c: Pervasive changes to add multibyte awareness
to all classes and functions.
(enum column_unit): New enum.
(class exploc_with_display_col): New class.
(class layout_point): Convert m_column member to array m_columns[2].
(layout_range::contains_point): Add col_unit argument.
(test_layout_range_for_single_point): Pass new argument.
(test_layout_range_for_single_line): Likewise.
(test_layout_range_for_multiple_lines): Likewise.
(line_bounds::convert_to_display_cols): New function.
(layout::get_state_at_point): Add col_unit argument.
(make_range): Use empty filename rather than dummy filename.
(get_line_width_without_trailing_whitespace): Rename to...
(get_line_bytes_without_trailing_whitespace): ...this.
(test_get_line_width_without_trailing_whitespace): Rename to...
(test_get_line_bytes_without_trailing_whitespace): ...this.
(class layout): m_exploc changed to exploc_with_display_col from
plain expanded_location.
(layout::get_linenum_width): New accessor member function.
(layout::get_x_offset_display): Likewise.
(layout::calculate_linenum_width): New subroutine for the constuctor.
(layout::calculate_x_offset_display): Likewise.
(layout::layout): Use the new subroutines. Add multibyte awareness.
(layout::print_source_line): Add multibyte awareness.
(layout::print_line): Likewise.
(layout::print_annotation_line): Likewise.
(line_label::line_label): Likewise.
(layout::print_any_labels): Likewise.
(layout::annotation_line_showed_range_p): Likewise.
(get_printed_columns): Likewise.
(class line_label): Rename m_length to m_display_width.
(get_affected_columns): Rename to...
(get_affected_range): ...this; add col_unit argument and multibyte
awareness.
(class correction): Add m_affected_bytes and m_display_cols
members. Rename m_len to m_byte_length for clarity. Add multibyte
awareness throughout.
(correction::insertion_p): Add multibyte awareness.
(correction::compute_display_cols): New function.
(correction::ensure_terminated): Use new member name m_byte_length.
(line_corrections::add_hint): Add multibyte awareness.
(layout::print_trailing_fixits): Likewise.
(layout::get_x_bound_for_row): Likewise.
(test_one_liner_simple_caret_utf8): New self-test analogous to the one
with _utf8 suffix removed, testing multibyte awareness.
(test_one_liner_caret_and_range_utf8): Likewise.
(test_one_liner_multiple_carets_and_ranges_utf8): Likewise.
(test_one_liner_fixit_insert_before_utf8): Likewise.
(test_one_liner_fixit_insert_after_utf8): Likewise.
(test_one_liner_fixit_remove_utf8): Likewise.
(test_one_liner_fixit_replace_utf8): Likewise.
(test_one_liner_fixit_replace_non_equal_range_utf8): Likewise.
(test_one_liner_fixit_replace_equal_secondary_range_utf8): Likewise.
(test_one_liner_fixit_validation_adhoc_locations_utf8): Likewise.
(test_one_liner_many_fixits_1_utf8): Likewise.
(test_one_liner_many_fixits_2_utf8): Likewise.
(test_one_liner_labels_utf8): Likewise.
(test_diagnostic_show_locus_one_liner_utf8): Likewise.
(test_overlapped_fixit_printing_utf8): Likewise.
(test_overlapped_fixit_printing): Adapt for changes to
get_affected_columns, get_printed_columns and class corrections.
(test_overlapped_fixit_printing_2): Likewise.
(test_linenum_sep): New constant.
(test_left_margin): Likewise.
(test_offset_impl): Helper function for new test.
(test_layout_x_offset_display_utf8): New test.
(diagnostic_show_locus_c_tests): Call new tests.
gcc/testsuite/ChangeLog:
2019-12-09 Lewis Hyatt <lhyatt@gmail.com>
PR preprocessor/49973
* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
(test_show_locus): Tweak so that expected output is the same as
before the diagnostic-show-locus.c changes.
* gcc.dg/cpp/pr66415-1.c: Likewise.
From-SVN: r279137
C2x adds u8'' character constants to C. This patch adds the
corresponding GCC support.
Most of the support was already present for C++ and just needed
enabling for C2x. However, in C2x these constants have type unsigned
char, which required corresponding adjustments in the compiler and the
preprocessor to give them that type for C.
For C, it seems clear to me that having type unsigned char means the
constants are unsigned in the preprocessor (and thus treated as having
type uintmax_t in #if conditionals), so this patch implements that. I
included a conditional in the libcpp change to avoid affecting
signedness for C++, but I'm not sure if in fact these constants should
also be unsigned in the preprocessor for C++ in which case that
!CPP_OPTION (pfile, cplusplus) conditional would not be needed.
Bootstrapped with no regressions on x86_64-pc-linux-gnu.
gcc/c:
* c-parser.c (c_parser_postfix_expression)
(c_parser_check_literal_zero): Handle CPP_UTF8CHAR.
* gimple-parser.c (c_parser_gimple_postfix_expression): Likewise.
gcc/c-family:
* c-lex.c (lex_charconst): Make CPP_UTF8CHAR constants unsigned
char for C.
gcc/testsuite:
* gcc.dg/c11-utf8char-1.c, gcc.dg/c2x-utf8char-1.c,
gcc.dg/c2x-utf8char-2.c, gcc.dg/c2x-utf8char-3.c,
gcc.dg/gnu2x-utf8char-1.c: New tests.
libcpp:
* charset.c (narrow_str_to_charconst): Make CPP_UTF8CHAR constants
unsigned for C.
* init.c (lang_defaults): Set utf8_char_literals for GNUC2X and
STDC2X.
From-SVN: r278265
PR c++/91370 - Implement P1041R4 and P1139R2 - Stronger Unicode reqs
* charset.c (narrow_str_to_charconst): Add TYPE argument. For
CPP_UTF8CHAR diagnose whenever number of chars is > 1, using
CPP_DL_ERROR instead of CPP_DL_WARNING.
(wide_str_to_charconst): For CPP_CHAR16 or CPP_CHAR32, use
CPP_DL_ERROR instead of CPP_DL_WARNING when multiple char16_t
or char32_t chars are needed.
(cpp_interpret_charconst): Adjust narrow_str_to_charconst caller.
* g++.dg/cpp1z/utf8-neg.C: Expect errors rather than -Wmultichar
warnings.
* g++.dg/ext/utf16-4.C: Expect errors rather than warnings.
* g++.dg/ext/utf32-4.C: Likewise.
* g++.dg/cpp2a/ucn2.C: New test.
From-SVN: r277929
There are three major pieces to this support: scalar operator<=>,
synthesis of comparison operators, and rewritten/reversed overload
resolution (e.g. a < b becomes 0 > b <=> a).
Unlike other defaulted functions, where we use synthesized_method_walk to
semi-simulate what the definition of the function will be like, this patch
determines the characteristics of a comparison operator by trying to define
it.
My handling of non-dependent rewritten operators in templates can still use
some work: build_min_non_dep_op_overload can't understand the rewrites and
crashes, so I'm avoiding it for now by clearing *overload. This means we'll
do name lookup again at instantiation time, which can incorrectly mean a
different result. I'll poke at this more in stage 3.
I'm leaving out a fourth section ("strong structural equality") even though
I've implemented it, because it seems likely to change radically tomorrow.
Thanks to Tim van Deurzen and Jakub for implementing lexing of the <=>
operator, and Jonathan for the initial <compare> header.
gcc/cp/
* cp-tree.h (struct lang_decl_fn): Add maybe_deleted bitfield.
(DECL_MAYBE_DELETED): New.
(enum special_function_kind): Add sfk_comparison.
(LOOKUP_REWRITTEN, LOOKUP_REVERSED): New.
* call.c (struct z_candidate): Add rewritten and reversed methods.
(add_builtin_candidate): Handle SPACESHIP_EXPR.
(add_builtin_candidates): Likewise.
(add_candidates): Don't add a reversed candidate if the parms are
the same.
(add_operator_candidates): Split out from build_new_op_1. Handle
rewritten and reversed candidates.
(add_candidate): Swap conversions of reversed candidate.
(build_new_op_1): Swap them back. Build a second operation for
rewritten candidates.
(extract_call_expr): Handle rewritten calls.
(same_fn_or_template): New.
(joust): Handle rewritten and reversed candidates.
* class.c (add_implicitly_declared_members): Add implicit op==.
(classtype_has_op, classtype_has_defaulted_op): New.
* constexpr.c (cxx_eval_binary_expression): Handle SPACESHIP_EXPR.
(cxx_eval_constant_expression, potential_constant_expression_1):
Likewise.
* cp-gimplify.c (genericize_spaceship): New.
(cp_genericize_r): Use it.
* cp-objcp-common.c (cp_common_init_ts): Handle SPACESHIP_EXPR.
* decl.c (finish_function): Handle deleted function.
* decl2.c (grokfield): SET_DECL_FRIEND_CONTEXT on defaulted friend.
(mark_used): Check DECL_MAYBE_DELETED. Remove assumption that
defaulted functions are non-static members.
* error.c (dump_expr): Handle SPACESHIP_EXPR.
* method.c (type_has_trivial_fn): False for sfk_comparison.
(enum comp_cat_tag, struct comp_cat_info_t): New types.
(comp_cat_cache): New array variable.
(lookup_comparison_result, lookup_comparison_category)
(is_cat, cat_tag_for, spaceship_comp_cat)
(spaceship_type, genericize_spaceship)
(common_comparison_type, early_check_defaulted_comparison)
(comp_info, build_comparison_op): New.
(synthesize_method): Handle sfk_comparison. Handle deleted.
(get_defaulted_eh_spec, maybe_explain_implicit_delete)
(explain_implicit_non_constexpr, implicitly_declare_fn)
(defaulted_late_check, defaultable_fn_check): Handle sfk_comparison.
* name-lookup.c (get_std_name_hint): Add comparison categories.
* tree.c (special_function_p): Add sfk_comparison.
* typeck.c (cp_build_binary_op): Handle SPACESHIP_EXPR.
2019-11-05 Tim van Deurzen <tim@kompiler.org>
Add new tree code for the spaceship operator.
gcc/cp/
* cp-tree.def: Add new tree code.
* operators.def: New binary operator.
* parser.c: Add new token and tree code.
libcpp/
* cpplib.h: Add spaceship operator for C++.
* lex.c: Implement conditional lexing of spaceship operator for C++20.
2019-11-05 Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/
* libsupc++/compare: New header.
* libsupc++/Makefile.am (std_HEADERS): Add compare.
* include/std/version: Define __cpp_lib_three_way_comparison.
* include/std/functional: #include <compare>.
From-SVN: r277865
https://gcc.gnu.org/ml/gcc-patches/2019-10/msg01080.html
looking up a line map takes a non-constant line_maps object, which is confusing.
This makes the caching fields mutable, so permits a constant object, as one might expect for a lookup.
* include/line-map.h (struct maps_info_ordinary): Make cache
mutable.
(struct maps_info_macro): Likewise.
(LINEMAPS_CACHE): Remove non-ref accessor. Constify ref accessor.
(LINEMAPS_ORDINARY_CACHE, LINEMAPS_MACRO_CACHE): Likewise.
(LINEMAPS_ORDINARY_MAP_AT, LINEMAPS_MACRO_MAP_AT): Use
LINEMAPS_USED and LINEMAPS_MAP_AT.
(linemap_lookup): Constify line_map arg.
linemap.c (linemap_ordinary_map_lookup, linemap_macro_map_lookup):
Constify line_map arg.
From-SVN: r276994
ISO C2x adds decimal floating point as an optional standard feature.
This patch accordingly makes GCC accept DFP constants (DF, DD, DL, df,
dd, dl suffixes) in strict C2X mode, with a pedwarn-if-pedantic for
older standards and a warning with -Wc11-c2x-compat even in C2x mode
(which in turn requires -Wc11-c2x-compat to be newly passed through to
libcpp).
Bootstrapped with no regressions on x86_64-pc-linux-gnu.
gcc/c-family:
* c.opt (Wc11-c2x-compat): Add CPP(cpp_warn_c11_c2x_compat)
CppReason(CPP_W_C11_C2X_COMPAT).
gcc/testsuite:
* gcc.dg/dfp/c11-constants-1.c, gcc.dg/dfp/c11-constants-2.c,
gcc.dg/dfp/c2x-constants-1.c, gcc.dg/dfp/c2x-constants-2.c: New
tests.
* gcc.dg/dfp/constants-pedantic.c: Use -std=gnu17 explicitly.
Update expected diagnostics.
libcpp:
* include/cpplib.h (struct cpp_options): Add dfp_constants and
cpp_warn_c11_c2x_compat.
(enum cpp_warning_reason): Add CPP_W_C11_C2X_COMPAT.
* init.c (struct lang_flags): Add dfp_constants.
(lang_defaults): Set dfp_constants to 1 for GNUC2X and STDC2X and
0 for other languages.
(cpp_set_lang): Set dfp_constants from language.
(cpp_create_reader): Set cpp_warn_c11_c2x_compat to -1.
* expr.c (interpret_float_suffix): Mention DFP constants as C2X in
comment.
(cpp_classify_number): Do not diagnose DFP constants for languages
setting dfp_constants, unless cpp_warn_c11_c2x_compat.
From-SVN: r276908
As part of adding [[]]-style attributes, C2x adds the token :: for use
in scoped attribute names.
This patch adds corresponding support for that token in C to GCC. The
token is supported both for C2x and for older gnu* standards (on the
basis that extensions are normally supported in older gnu* versions;
people will expect to be able to use [[]] attributes, before C2x is
the default, without needing to use -std=gnu2x).
There are no cases in older C standards where the token : can be
followed by a token starting with : in syntactically valid sources;
the only cases the :: token could break in older standard C thus are
ones involving concatenation of pp-tokens where the result does not
end up as tokens (e.g., gets stringized). In GNU C extensions, the
main case where :: might appear in existing sources is in asm
statements, and the C parser is thus made to handle it like two
consecutive : tokens, which the C++ parser already does. A limited
test of various positionings of :: in asm statements is added to the
testsuite (in particular, to cover the syntax error when :: means too
many colons but a single : would be OK), but existing tests cover a
variety of styles there anyway.
Technically there are cases in Objective-C and OpenMP for which this
also changes how previously valid code is lexed: the objc-selector-arg
syntax allows multiple consecutive : tokens (although I don't think
they are particularly useful there), while OpenMP syntax includes
array section syntax such as [:] which, before :: was a token, could
also be written as [::> (there might be other OpenMP cases potentially
affected, I didn't check all the OpenMP syntax in detail). I don't
think either of those cases affects the basis for supporting the ::
token in all -std=gnu* modes, or that there is any obvious need to
special-case handling of CPP_SCOPE tokens for those constructs the way
there is for asm statements.
cpp_avoid_paste, which determines when spaces need adding between
tokens in preprocessed output where there wouldn't otherwise be
whitespace between them (e.g. if stringized), already inserts space
between : and : unconditionally, rather than only for C++, so no
change is needed there (but a C2x test is added that such space is
indeed inserted).
Bootstrapped with no regressions on x86-64-pc-linux-gnu.
gcc/c:
* c-parser.c (c_parser_asm_statement): Handle CPP_SCOPE like two
CPP_COLON tokens.
gcc/testsuite:
* gcc.dg/asm-scope-1.c, gcc.dg/cpp/c11-scope-1.c,
gcc.dg/cpp/c17-scope-1.c, gcc.dg/cpp/c2x-scope-1.c,
gcc.dg/cpp/c2x-scope-2.c, gcc.dg/cpp/c90-scope-1.c,
gcc.dg/cpp/c94-scope-1.c, gcc.dg/cpp/c99-scope-1.c,
gcc.dg/cpp/gnu11-scope-1.c, gcc.dg/cpp/gnu17-scope-1.c,
gcc.dg/cpp/gnu89-scope-1.c, gcc.dg/cpp/gnu99-scope-1.c: New tests.
libcpp:
* include/cpplib.h (struct cpp_options): Add member scope.
* init.c (struct lang_flags, lang_defaults): Likewise.
(cpp_set_lang): Set scope member of pfile.
* lex.c (_cpp_lex_direct): Test CPP_OPTION (pfile, scope) not
CPP_OPTION (pfile, cplusplus) for creating CPP_SCOPE tokens.
From-SVN: r276434
* charset.c (UCS_LIMIT): New macro.
(ucn_valid_in_identifier): Use it instead of a hardcoded constant.
(_cpp_valid_ucn): Issue a pedantic warning for UCNs larger than
UCS_LIMIT outside of identifiers in C and in C++2a or later.
From-SVN: r276167
libcpp/ChangeLog
2019-09-19 Lewis Hyatt <lhyatt@gmail.com>
PR c/67224
* charset.c (_cpp_valid_utf8): New function to help lex UTF-8 tokens.
* internal.h (_cpp_valid_utf8): Declare.
* lex.c (forms_identifier_p): Use it to recognize UTF-8 identifiers.
(_cpp_lex_direct): Handle UTF-8 in identifiers and CPP_OTHER tokens.
Do all work in "default" case to avoid slowing down typical code paths.
Also handle $ and UCN in the default case for consistency.
gcc/Changelog
2019-09-19 Lewis Hyatt <lhyatt@gmail.com>
PR c/67224
* doc/cpp.texi: Document support for extended characters in
identifiers.
* doc/cppopts.texi: Likewise.
gcc/testsuite/ChangeLog
2019-09-19 Lewis Hyatt <lhyatt@gmail.com>
PR c/67224
* c-c++-common/cpp/ucnid-2011-1-utf8.c: New test.
* g++.dg/cpp/ucnid-1-utf8.C: New test.
* g++.dg/cpp/ucnid-2-utf8.C: New test.
* g++.dg/cpp/ucnid-3-utf8.C: New test.
* g++.dg/cpp/ucnid-4-utf8.C: New test.
* g++.dg/other/ucnid-1-utf8.C: New test.
* gcc.dg/cpp/ucnid-1-utf8.c: New test.
* gcc.dg/cpp/ucnid-10-utf8.c: New test.
* gcc.dg/cpp/ucnid-11-utf8.c: New test.
* gcc.dg/cpp/ucnid-12-utf8.c: New test.
* gcc.dg/cpp/ucnid-13-utf8.c: New test.
* gcc.dg/cpp/ucnid-14-utf8.c: New test.
* gcc.dg/cpp/ucnid-15-utf8.c: New test.
* gcc.dg/cpp/ucnid-2-utf8.c: New test.
* gcc.dg/cpp/ucnid-3-utf8.c: New test.
* gcc.dg/cpp/ucnid-4-utf8.c: New test.
* gcc.dg/cpp/ucnid-6-utf8.c: New test.
* gcc.dg/cpp/ucnid-7-utf8.c: New test.
* gcc.dg/cpp/ucnid-9-utf8.c: New test.
* gcc.dg/ucnid-1-utf8.c: New test.
* gcc.dg/ucnid-10-utf8.c: New test.
* gcc.dg/ucnid-11-utf8.c: New test.
* gcc.dg/ucnid-12-utf8.c: New test.
* gcc.dg/ucnid-13-utf8.c: New test.
* gcc.dg/ucnid-14-utf8.c: New test.
* gcc.dg/ucnid-15-utf8.c: New test.
* gcc.dg/ucnid-16-utf8.c: New test.
* gcc.dg/ucnid-2-utf8.c: New test.
* gcc.dg/ucnid-3-utf8.c: New test.
* gcc.dg/ucnid-4-utf8.c: New test.
* gcc.dg/ucnid-5-utf8.c: New test.
* gcc.dg/ucnid-6-utf8.c: New test.
* gcc.dg/ucnid-7-utf8.c: New test.
* gcc.dg/ucnid-8-utf8.c: New test.
* gcc.dg/ucnid-9-utf8.c: New test.
From-SVN: r275979
https://gcc.gnu.org/ml/gcc-patches/2019-08/msg01971.html
* internal.h (enum include_type): Add IT_MAIN, IT_DIRECTIVE_HWM,
IT_HEADER_HWM.
(_cpp_stack_file): Take include_type, not a bool.
* files.c (_cpp_find_file): Refactor to not hide an if inside a
for conditional.
(should_stack_file): Break apart to ...
(is_known_idempotent_file, has_unique_contents): ... these.
(_cpp_stack_file): Replace IMPORT boolean with include_type enum.
Refactor to use new predicates. Do linemap compensation here ...
(_cpp_stack_include): ... not here.
* init.c (cpp_read_main_file): Pass IT_MAIN to _cpp_stack_file.
From-SVN: r275034
https://gcc.gnu.org/ml/gcc-patches/2019-08/msg01904.html
* directives-only.c (_cpp_preprocess_dir_only): Use false, not
zero for _cpp_handle_directive call.
* directives.c (_cpp_handle_directive): Indented is bool.
* files.c (struct _cpp_file): Make bools 1 bit bitfields.
* internal.h (enum include_type): Reformat and comment.
(struct cpp_buffer): Make flags 1 bit bitfields.
(_cpp_handle_directive): Indented is bool.
From-SVN: r274999
PR c/89410 reports various issues with #line directives with very
large numbers; one of them is an ICE inside diagnostic-show-locus.c
when emitting a diagnostic at line 0xffffffff.
The issue is that the arithmetic in layout::calculate_line_spans to
determine if two line spans are sufficiently close to consolidate
was using the unsigned 32-bit linenum_type, which was overflowing
when comparing the line for the expanded location with those of
the location range (all on line 0xffffffff), leading to it
erroneously adding two spans for the same line, leading to an
assertion failure.
This patch fixes the ICE by generalizing the use of long long in
line-map.h's comparison function for linenum_type into a new
linenum_arith_t typedef, and using it here.
Doing so uncovered a second problem: the loop to print the lines
within the line_span for this case is infinite: looping from
0xfffffff upwards, overflowing to 0, and then never becoming
greater than 0xfffffff. The patch fixes this by using linenum_arith_t
there also.
gcc/ChangeLog:
PR c/89410
* diagnostic-show-locus.c (layout::calculate_line_spans): Use
linenum_arith_t when determining if two adjacent line spans are
close enough to merge.
(diagnostic_show_locus): Use linenum_arith_t when iterating over
lines within each line_span.
gcc/testsuite/ChangeLog:
PR c/89410
* gcc.dg/pr89410-1.c: New test.
* gcc.dg/pr89410-2.c: New test.
libcpp/ChangeLog:
PR c/89410
* include/line-map.h (linenum_arith_t): New typedef.
(compare): Use it.
From-SVN: r269050
PR lto/88147 reports an assertion failure due to a bogus location_t value
when adding a line to a pre-existing line map, when there's a large
difference between the two line numbers.
For some "large differences", this leads to a location_t value that exceeds
LINE_MAP_MAX_LOCATION, in which case linemap_line_start returns 0. This
isn't ideal, but at least should lead to safe degradation of location
information.
However, if the difference is very large, it's possible for the line
number offset (relative to the start of the map) to be sufficiently large
that overflow occurs when left-shifted by the column-bits, and hence
the check against the LINE_MAP_MAX_LOCATION limit fails, leading to
a seemingly-valid location_t value, but encoding the wrong location. This
triggers the assertion failure:
linemap_assert (SOURCE_LINE (map, r) == to_line);
The fix (thanks to Martin) is to check for overflow when determining
whether to reuse an existing map, and to not reuse it if it would occur.
gcc/ChangeLog: David Malcolm <dmalcolm@redhat.com>
PR lto/88147
* input.c (selftest::test_line_offset_overflow): New selftest.
(selftest::input_c_tests): Call it.
libcpp/ChangeLog: Martin Liska <mliska@suse.cz>
PR lto/88147
* line-map.c (linemap_line_start): Don't reuse the existing line
map if the line offset is sufficiently large to cause overflow
when computing location_t values.
From-SVN: r268789
gcc/ChangeLog:
2018-11-27 Mike Gulick <mgulick@mathworks.com>
PR preprocessor/83173
* input.c (dump_location_info): Dump reason and included_from
fields from line_map_ordinary struct. Fix indentation when
location > 5 digits.
* diagnostic-show-locus.c (num_digits, num_digits): Move to
diagnostic.c to allow it to be utilized by input.c.
* diagnostic.c (num_digits, selftest::test_num_digits): Moved
here.
(selftest::diagnostic_c_tests): Run selftest::test_num_digits.
* diagnostic.h (num_digits): Add extern definition.
libcpp/ChangeLog:
2018-11-27 Mike Gulick <mgulick@mathworks.com>
PR preprocessor/83173
* location-example.txt: Update example -fdump-internal-locations
output.
From-SVN: r266520
2018-11-27 Mike Gulick <mgulick@mathworks.com>
PR preprocessor/83173
* files.c (_cpp_stack_include): Check if
line_table->highest_location is past current line before
decrementing.
From-SVN: r266516
This patch updates GCC to use autoconf 2.69 and automake 1.15.1.
(That's not the latest automake version, but it's the one used by
binutils-gdb, with which consistency is desirable, and in any case
seems a useful incremental update that should make a future update to
1.16.1 easier.)
The changes are generally similar to the binutils-gdb ones, and are
copied from there where shared files and directories are involved
(there are some further changes to such shared directories, however,
which I'd expect to apply to binutils-gdb once this patch is in GCC).
Largely, obsolete AC_PREREQ calls are removed, while many
AC_LANG_SOURCE calls are added to avoid warnings from aclocal and
autoconf. Multilib support is no longer included in core automake,
meaning that multilib.am needs copying from automake's contrib
directory into the GCC source tree. Autoconf 2.69 has Go support, so
local copies of that support are removed. I hope the D support will
soon be submitted to upstream autoconf so the local copy of that can
be removed in a future update. Changes to how automake generates
runtest calls mean quotes are removed from RUNTEST definitions in five
lib*/testsuite/Makefile.am files (libatomic, libgomp, libitm,
libphobos, libvtv; some others have RUNTEST definitions without
quotes, which are still OK); libgo and libphobos also get
-Wno-override added to AM_INIT_AUTOMAKE so those overrides of RUNTEST
do not generate automake warnings.
Note that the regeneration did not include regeneration of
fixincludes/config.h.in (attempting such regeneration resulted in all
the USED_FOR_TARGET conditionals disappearing; and I don't see
anything in the fixincludes/ directory that would result in such
conditionals being generated, unlike in the gcc/ directory). Also
note that libvtv/testsuite/other-tests/Makefile.in was not
regenerated; that directory is not listed as a subdirectory for which
Makefile.in gets regenerated by calling "automake" in libvtv/, so I'm
not sure how it's meant to be regenerated.
While I mostly fixed warnings should running aclocal / automake /
autoconf, there were various such warnings from automake in the
libgfortran, libgo, libgomp, liboffloadmic, libsanitizer, libphobos
directories that I did not fix, preferring to leave those to the
relevant subsystem maintainers. Specifically, most of those warnings
were of the following form (example from libgfortran):
Makefile.am:48: warning: source file 'caf/single.c' is in a subdirectory,
Makefile.am:48: but option 'subdir-objects' is disabled
automake: warning: possible forward-incompatibility.
automake: At least a source file is in a subdirectory, but the 'subdir-objects'
automake: automake option hasn't been enabled. For now, the corresponding output
automake: object file(s) will be placed in the top-level directory. However,
automake: this behaviour will change in future Automake versions: they
will
automake: unconditionally cause object files to be placed in the same subdirectory
automake: of the corresponding sources.
automake: You are advised to start using 'subdir-objects' option throughout your
automake: project, to avoid future incompatibilities.
I think it's best for the relevant maintainers to add subdir-objects
and do any other associated Makefile.am changes needed. In some cases
the paths in the warnings involved ../; I don't know if that adds any
extra complications to the use of subdir-objects.
I've tested this with native, cross and Canadian cross builds. The
risk of any OS-specific issues should I hope be rather lower than if a
libtool upgrade were included (we *should* do such an upgrade at some
point, but it's more complicated - it involves identifying all our
local libtool changes to see if any aren't included in the upstream
version we update to, and reverting an upstream libtool patch that's
inappropriate for use in GCC); I think it would be better to get this
update into GCC so that people can test in different configurations
and we can fix any issues found, rather than to try to get more and
more testing done before it goes in.
top level:
2018-10-31 Joseph Myers <joseph@codesourcery.com>
PR bootstrap/82856
* multilib.am: New file. From automake.
Merge from binutils-gdb:
2018-06-19 Simon Marchi <simon.marchi@ericsson.com>
* libtool.m4: Use AC_LANG_SOURCE.
* configure.ac: Remove AC_PREREQ, use AC_LANG_SOURCE.
* ar-lib: New file.
* test-driver: New file.
* configure: Re-generate.
config:
2018-10-31 Joseph Myers <joseph@codesourcery.com>
PR bootstrap/82856
* math.m4, tls.m4: Use AC_LANG_SOURCE.
Merge from binutils-gdb:
2018-06-19 Simon Marchi <simon.marchi@ericsson.com>
* override.m4 (_GCC_AUTOCONF_VERSION): Bump from 2.64 to 2.69.
fixincludes:
2018-10-31 Joseph Myers <joseph@codesourcery.com>
PR bootstrap/82856
* configure.ac: Remove AC_PREREQ.
* aclocal.m4, configure: Regenerate.
gcc:
2018-10-31 Joseph Myers <joseph@codesourcery.com>
PR bootstrap/82856
* configure.ac: Remove AC_PREREQ. Use AC_LANG_SOURCE. Use single
line for second argument of AC_DEFINE_UNQUOTED.
* doc/install.texi (Tools/packages necessary for modifying GCC):
Update to autoconf 2.69 and automake 1.15.1.
* aclocal.m4, config.in, configure: Regenerate.
gnattools:
2018-10-31 Joseph Myers <joseph@codesourcery.com>
PR bootstrap/82856
* configure.ac: Remove AC_PREREQ.
* configure: Regenerate.
gotools:
2018-10-31 Joseph Myers <joseph@codesourcery.com>
PR bootstrap/82856
* config/go.m4: Remove file.
* Makefile.am (ACLOCAL_AMFLAGS): Do not use -I ./config.
* configure.ac: Remove AC_PREREQ. Do not include config/go.m4.
* Makefile.in, aclocal.m4, configure: Regenerate.
intl:
2018-10-31 Joseph Myers <joseph@codesourcery.com>
PR bootstrap/82856
Merge from binutils-gdb:
2018-06-19 Simon Marchi <simon.marchi@ericsson.com>
* configure.ac: Add AC_USE_SYSTEM_EXTENSIONS, remove AC_PREREQ.
* configure: Re-generate.
* config.h.in: Re-generate.
* aclocal.m4: Re-generate.
libada:
2018-10-31 Joseph Myers <joseph@codesourcery.com>
PR bootstrap/82856
* configure.ac: Remove AC_PREREQ.
* configure: Regenerate.
libatomic:
2018-10-31 Joseph Myers <joseph@codesourcery.com>
PR bootstrap/82856
* Makefile.am: Include multilib.am.
* acinclude.m4: Use AC_LANG_SOURCE.
* configure.ac: Remove AC_PREREQ.
* testsuite/Makefile.am (RUNTEST): Remove quotes.
* Makefile.in, aclocal.m4, configure, testsuite/Makefile.in:
Regenerate.
libbacktrace:
2018-10-31 Joseph Myers <joseph@codesourcery.com>
PR bootstrap/82856
* Makefile.am: Include multilib.am.
* configure.ac: Remove AC_PREREQ. Use AC_LANG_SOURCE.
* Makefile.in, aclocal.m4, config.h.in, configure: Regenerate.
libcc1:
2018-10-31 Joseph Myers <joseph@codesourcery.com>
PR bootstrap/82856
* configure.ac: Remove AC_PREREQ.
* Makefile.in, aclocal.m4, configure: Regenerate.
libcpp:
2018-10-31 Joseph Myers <joseph@codesourcery.com>
PR bootstrap/82856
* configure.ac: Remove AC_PREREQ. Use AC_LANG_SOURCE.
* aclocal.m4, config.in, configure: Regenerate.
libdecnumber:
2018-10-31 Joseph Myers <joseph@codesourcery.com>
PR bootstrap/82856
Merge from binutils-gdb:
2018-06-19 Simon Marchi <simon.marchi@ericsson.com>
* configure.ac: Remove AC_PREREQ.
* configure: Re-generate.
* aclocal.m4.
libffi:
2018-10-31 Joseph Myers <joseph@codesourcery.com>
PR bootstrap/82856
* Makefile.am: Include multilib.am.
(AUTOMAKE_OPTIONS): Add info-in-builddir.
(CLEANFILES): Remove doc/libffi.info.
* configure.ac: Remove AC_PREREQ.
* Makefile.in, aclocal.m4, configure, fficonfig.h.in,
include/Makefile.in, man/Makefile.in, testsuite/Makefile.in:
Regenerate.
libgcc:
2018-10-31 Joseph Myers <joseph@codesourcery.com>
PR bootstrap/82856
* configure.ac: Remove AC_PREREQ. Use AC_LANG_SOURCE.
* configure: Regenerate.
libgfortran:
2018-10-31 Joseph Myers <joseph@codesourcery.com>
PR bootstrap/82856
* Makefile.am: Include multilib.am.
* configure.ac: Remove AC_PREREQ.
* Makefile.in, aclocal.m4, config.h.in, configure: Regenerate.
libgo [logically part of this change but omitted from the commit]:
2018-10-31 Joseph Myers <joseph@codesourcery.com>
PR bootstrap/82856
* Makefile.am: Include multilib.am.
* config/go.m4: Remove file.
* config/libtool.m4: Use AC_LANG_SOURCE.
* configure.ac: Remove AC_PREREQ. Use AC_LANG_SOURCE. Use
-Wno-override in AM_INIT_AUTOMAKE call.
* Makefile.in, aclocal.m4, configure, testsuite/Makefile.in:
Regenerate.
libgomp:
2018-10-31 Joseph Myers <joseph@codesourcery.com>
PR bootstrap/82856
* Makefile.am: Include multilib.am
(AUTOMAKE_OPTIONS): Add info-in-builddir.
(CLEANFILES): Remove libgomp.info.
* configure.ac: Remove AC_PREREQ.
* testsuite/Makefile.am (RUNTEST): Remove quotes.
* Makefile.in, aclocal.m4, configure, testsuite/Makefile.in:
Regenerate.
libhsail-rt:
2018-10-31 Joseph Myers <joseph@codesourcery.com>
PR bootstrap/82856
* configure.ac: Remove AC_PREREQ.
* Makefile.in, aclocal.m4, configure: Regenerate.
libiberty:
2018-10-31 Joseph Myers <joseph@codesourcery.com>
PR bootstrap/82856
Merge from binutils-gdb:
2018-06-19 Simon Marchi <simon.marchi@ericsson.com>
* configure.ac: Remove AC_PREREQ.
* configure: Re-generate.
* config.in: Re-generate.
libitm:
2018-10-31 Joseph Myers <joseph@codesourcery.com>
PR bootstrap/82856
* Makefile.am: Include multilib.am.
(AUTOMAKE_OPTIONS): Add info-in-builddir.
(CLEANFILES): Remove libitm.info.
* configure.ac: Remove AC_PREREQ.
* testsuite/Makefile.am (RUNTEST): Remove quotes.
* Makefile.in, aclocal.m4, configure, testsuite/Makefile.in:
Regenerate.
libobjc:
2018-10-31 Joseph Myers <joseph@codesourcery.com>
PR bootstrap/82856
* configure.ac: Remove AC_PREREQ.
* aclocal.m4, config.h.in, configure: Regenerate.
liboffloadmic:
2018-10-31 Joseph Myers <joseph@codesourcery.com>
PR bootstrap/82856
* Makefile.am: Include multilib.am.
* configure.ac: Remove AC_PREREQ.
* plugin/Makefile.am: Include multilib.am.
* plugin/configure.ac: Remove AC_PREREQ.
* Makefile.in, aclocal.m4, configure, plugin/Makefile.in,
plugin/aclocal.m4, plugin/configure: Regenerate.
libphobos:
2018-10-31 Joseph Myers <joseph@codesourcery.com>
PR bootstrap/82856
* Makefile.am: Include multilib.am.
* configure.ac: Remove AC_PREREQ. Use -Wno-override in
AM_INIT_AUTOMAKE call.
* m4/autoconf.m4: Add extra argument to AC_LANG_DEFINE call.
* m4/druntime/os.m4: Use AC_LANG_SOURCE.
* testsuite/Makefile.am (RUNTEST): Remove quotes.
* Makefile.in, aclocal.m4, configure, libdruntime/Makefile.in,
src/Makefile.in, testsuite/Makefile.in: Regenerate.
libquadmath:
2018-10-31 Joseph Myers <joseph@codesourcery.com>
PR bootstrap/82856
* Makefile.am: Include multilib.am.
(AUTOMAKE_OPTIONS): Remove 1.8. Add info-in-builddir.
(all-local): Define outside conditional code.
(CLEANFILES): Remove libquadmath.info.
* configure.ac: Remove AC_PREREQ.
* Makefile.in, aclocal.m4, config.h.in, configure: Regenerate.
libsanitizer:
2018-10-31 Joseph Myers <joseph@codesourcery.com>
PR bootstrap/82856
* Makefile.am: Include multilib.am.
* configure.ac: Remove AC_PREREQ. Use AC_LANG_SOURCE.
* Makefile.in, aclocal.m4, asan/Makefile.in, configure,
interception/Makefile.in, libbacktrace/Makefile.in,
lsan/Makefile.in, sanitizer_common/Makefile.in, tsan/Makefile.in,
ubsan/Makefile.in: Regenerate.
libssp:
2018-10-31 Joseph Myers <joseph@codesourcery.com>
PR bootstrap/82856
* Makefile.am: Include multilib.am.
(AUTOMAKE_OPTIONS): Remove 1.9.5.
* configure.ac: Remove AC_PREREQ. Quote argument to
AC_RUN_IFELSE.
* Makefile.in, aclocal.m4, configure: Regenerate.
libstdc++-v3:
2018-10-31 Joseph Myers <joseph@codesourcery.com>
PR bootstrap/82856
* Makefile.am: Include multilib.am.
* configure.ac: Remove AC_PREREQ.
* Makefile.in, aclocal.m4, configure, doc/Makefile.in,
include/Makefile.in, libsupc++/Makefile.in, po/Makefile.in,
python/Makefile.in, src/Makefile.in, src/c++11/Makefile.in,
src/c++17/Makefile.in, src/c++98/Makefile.in,
src/filesystem/Makefile.in, testsuite/Makefile.in: Regenerate.
libvtv:
2018-10-31 Joseph Myers <joseph@codesourcery.com>
PR bootstrap/82856
* Makefile.am: Include multilib.am.
* configure.ac: Remove AC_PREREQ.
* testsuite/Makefile.am (RUNTEST): Remove quotes.
* Makefile.in, aclocal.m4, configure, testsuite/Makefile.in:
Regenerate.
lto-plugin:
2018-10-31 Joseph Myers <joseph@codesourcery.com>
PR bootstrap/82856
* configure.ac: Remove AC_PREREQ. Use AC_LANG_SOURCE.
* Makefile.in, aclocal.m4, config.h.in, configure: Regenerate.
zlib:
2018-10-31 Joseph Myers <joseph@codesourcery.com>
PR bootstrap/82856
* Makefile.am: Include multilib.am.
Merge from binutils-gdb:
2018-06-19 Simon Marchi <simon.marchi@ericsson.com>
* configure.ac: Modernize AC_INIT call, remove AC_PREREQ.
* Makefile.am (AUTOMAKE_OPTIONS): Remove 1.8, cygnus, add foreign.
* Makefile.in: Re-generate.
* aclocal.m4: Re-generate.
* configure: Re-generate.
From-SVN: r265695
Now new features are starting to be added to a C2X draft (in the C2x
branch of the C standard git repository, no public WG14 document yet),
it's time to add -std=c2x and associated options to GCC for use in
enabling C2X features.
This patch adds the expected set of options: -std=c2x, -std=gnu2x,
-Wc11-c2x-compat. A first C2X feature is added (the only one so far
in the repository that's obviously relevant to GCC): support (as in
C++) for the string constant to be omitted in _Static_assert. This
feature is duly also supported as an extension in earlier standard
modes (diagnosed with -pedantic, unless -Wno-c11-c2x-compat is given,
or with -Wc11-c2x-compat even in C2X mode).
Bootstrapped with no regressions on x86_64-pc-linux-gnu.
gcc/
* doc/cpp.texi (__STDC_VERSION__): Document C2X handling.
* doc/invoke.texi (-std=c2x, -std=gnu2x): Document new options.
* doc/standards.texi (C Language): Document C2X.
* dwarf2out.c (highest_c_language), config/rl78/rl78.c
(rl78_option_override): Handle "GNU C2X" language name.
gcc/c/
* c-errors.c (pedwarn_c11): New function.
* c-parser.c (disable_extension_diagnostics): Save
warn_c11_c2x_compat and set it to 0.
(restore_extension_diagnostics): Restore warn_c11_c2x_compat.
(c_parser_static_assert_declaration_no_semi): Handle
_Static_assert without string constant.
* c-tree.h (pedwarn_c11): New prototype.
gcc/c-family/
* c-common.c (flag_isoc2x): New variable.
* c-common.h (clk_c): Update comment to reference C2X.
(flag_isoc99, flag_isoc11): Update comments to reference future
standard versions in general.
(flag_isoc2x): Declare.
* c-opts.c (set_std_c2x): New function.
(c_common_handle_option): Handle -std=c2x and -std=gnu2x.
(set_std_c89, set_std_c99, set_std_c11, set_std_c17): Set
flag_isoc2x to 0.
* c.opt (Wc11-c2x-compat, std=c2x, std=gnu2x): New options.
gcc/testsuite/
* gcc.dg/c11-static-assert-7.c, gcc.dg/c11-static-assert-8.c,
gcc.dg/c11-static-assert-9.c, gcc.dg/c2x-static-assert-1.c,
gcc.dg/c2x-static-assert-2.c, gcc.dg/c99-static-assert-2.c,
gcc.dg/gnu2x-static-assert-1.c: New tests.
* gcc.dg/missing-symbol-3.c: Update expected fix-it text.
libcpp/
* include/cpplib.h (enum c_lang): Add CLK_GNUC2X and CLK_STDC2X.
* init.c (lang_defaults): Add GNUC2X and STDC2X entries.
(cpp_init_builtins): Define __STDC_VERSION__ to 202000L for C2X.
From-SVN: r265251
Consider:
demo.c: In function 'test':
demo.c:5:40: error: macro "LOG_2" requires 3 arguments, but only 2 given
5 | LOG_2 ("loading file: %s\n", filename);
| ^
This patch adds a note showing the definition of the macro in
question, giving:
demo.c: In function 'test':
demo.c:5:40: error: macro "LOG_2" requires 3 arguments, but only 2 given
5 | LOG_2 ("loading file: %s\n", filename);
| ^
In file included from demo.c:1:
logging.h:1: note: macro "LOG_2" defined here
1 | #define LOG_2(FMT, ARG0, ARG1) do { fprintf (stderr, (FMT), (ARG0), (ARG1)); }
|
gcc/testsuite/ChangeLog:
* g++.dg/diagnostic/macro-arg-count.C: Move to...
* c-c++-common/cpp/macro-arg-count-1.c: ...here, generalizing
output for C vs C++. Expect notes showing the definitions of the
macros.
* c-c++-common/cpp/macro-arg-count-2.c: New test, adapted from the
above.
libcpp/ChangeLog:
* macro.c (_cpp_arguments_ok): If the argument count is wrong, add
a note showing the definition of the macro.
From-SVN: r265040
https://gcc.gnu.org/ml/gcc-patches/2018-10/msg00623.html
* include/line-map.h (LINEMAPS_MACRO_LOWEST_LOCATION): Fix
off-by-one error.
* line-map.c (linemap_enter_macro): Use RAII. Clear all of the
macro_locations.
From-SVN: r265037
This patch renames the "error" callback within libcpp
to "diagnostic", and uses the pair of enums in cpplib.h, rather
than passing two different kinds of "int" around.
gcc/c-family/ChangeLog:
* c-common.c (c_option_controlling_cpp_error): Rename to...
(c_option_controlling_cpp_diagnostic): ...this, and convert
"reason" from int to enum.
(c_cpp_error): Rename to...
(c_cpp_diagnostic): ...this, converting level and reason to enums.
* c-common.h (c_cpp_error): Rename to...
(c_cpp_diagnostic): ...this, converting level and reason to enums.
* c-opts.c (c_common_init_options): Update for renaming.
gcc/fortran/ChangeLog:
* cpp.c (gfc_cpp_init_0): Update for renamings.
(cb_cpp_error): Rename to...
(cb_cpp_diagnostic): ...this, converting level and reason to
enums.
gcc/ChangeLog:
* genmatch.c (error_cb): Rename to...
(diagnostic_cb): ...this, converting int params to enums.
(fatal_at): Update for renaming.
(warning_at): Likewise.
(main): Likewise.
* input.c (selftest::ebcdic_execution_charset::apply):
Update for renaming of...
(selftest::ebcdic_execution_charset::on_error): ...this, renaming
to...
(selftest::ebcdic_execution_charset::on_diagnostic): ...this,
converting level and reason to enums.
(class selftest::lexer_error_sink): Rename to...
(class selftest::lexer_test_options): ...this, renaming field
"m_errors" to "m_diagnostics".
(selftest::lexer_test_options::apply): Update for renaming of...
(selftest::lexer_test_options::on_error): ...this, renaming to...
(selftest::lexer_test_options::on_diagnostic): ...this
converting level and reason to enums.
(selftest::test_lexer_string_locations_raw_string_unterminated):
Update for renamings.
* opth-gen.awk (struct cpp_reason_option_codes_t): Use enum for
"reason".
libcpp/ChangeLog:
* charset.c (noop_error_cb): Rename to...
(noop_diagnostic_cb): ...this, converting params to enums.
(cpp_interpret_string_ranges): Update for renaming and enums.
* directives.c (check_eol_1): Convert reason to enum.
(do_diagnostic): Convert code and reason to enum.
(do_error): Use CPP_W_NONE rather than 0.
(do_pragma_dependency): Likewise.
* errors.c (cpp_diagnostic_at): Convert level and reason to enums.
Update for renaming.
(cpp_diagnostic): Convert level and reason to enums.
(cpp_error): Convert level to enum.
(cpp_warning): Convert reason to enums.
(cpp_pedwarning): Likewise.
(cpp_warning_syshdr): Likewise.
(cpp_diagnostic_with_line): Convert level and reason to enums.
Update for renaming.
(cpp_error_with_line): Convert level to enum.
(cpp_warning_with_line): Convert reason to enums.
(cpp_pedwarning_with_line): Likewise.
(cpp_warning_with_line_syshdr): Likewise.
(cpp_error_at): Convert level to enum.
(cpp_errno): Likewise.
(cpp_errno_filename): Likewise.
* include/cpplib.h (enum cpp_diagnostic_level): Name this enum,
and move to before struct cpp_callbacks.
(enum cpp_warning_reason): Likewise.
(cpp_callbacks::diagnostic): Convert params from int to enums.
(cpp_error): Convert int param to enum cpp_diagnostic_level.
(cpp_warning): Convert int param to enum cpp_warning_reason.
(cpp_pedwarning): Likewise.
(cpp_warning_syshdr): Likewise.
(cpp_errno): Convert int param to enum cpp_diagnostic_level.
(cpp_errno_filename): Likewise.
(cpp_error_with_line): Likewise.
(cpp_warning_with_line): Convert int param to enum
cpp_warning_reason.
(cpp_pedwarning_with_line): Likewise.
(cpp_warning_with_line_syshdr): Likewise.
(cpp_error_at): Convert int param to enum cpp_diagnostic_level.
* macro.c (create_iso_definition): Convert int to enum.
(_cpp_create_definition): Likewise.
From-SVN: r264999
This patch updates the pure virtual function range_label::get_text
(and its implementations) so that the index of the range is passed
in, allowing for one label instance to be shared by multiple ranges.
gcc/c-family/ChangeLog:
* c-format.c (range_label_for_format_type_mismatch::get_text):
Update for new param.
gcc/c/ChangeLog:
* c-objc-common.c (range_label_for_type_mismatch::get_text):
Update for new param.
* c-typeck.c (maybe_range_label_for_tree_type_mismatch::get_text):
Likewise.
gcc/cp/ChangeLog:
* error.c (range_label_for_type_mismatch::get_text): Update for
new param.
gcc/ChangeLog:
* diagnostic-show-locus.c (class layout_range): Add field
"m_original_idx".
(layout_range::layout_range): Add "original_idx" param and use it
to initialize new field.
(make_range): Use 0 for original_idx.
(layout::layout): Pass in index to calls to
maybe_add_location_range.
(layout::maybe_add_location_range): Add param "original_idx" and
pass it on to layout_range.
(layout::print_any_labels): Pass on range->m_original_idx to
get_text call.
(gcc_rich_location::add_location_if_nearby): Use 0 for
original_idx.
* gcc-rich-location.h (text_range_label::get_text): Update for new
param.
(range_label_for_type_mismatch::get_text): Likewise.
libcpp/ChangeLog:
* include/line-map.h (range_label::get_text): Add param
"range_idx".
From-SVN: r264376
This patch tweaks maybe_add_include_fixit so that if we're emitting a note
about adding the header file, the note's primary location will be replaced
by that of the fix-it hint, to avoid repeating a location we've already
emitted (or one close to it).
For example, this simplifies:
../x86_64-pc-linux-gnu/libstdc++-v3/include/vector:87:27: error: msg 1
87 | using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
| ^~~~~~
../x86_64-pc-linux-gnu/libstdc++-v3/include/vector:87:22: note: msg 2
73 | # include <debug/vector>
+++ |+#include <vector>
74 | #endif
....
87 | using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
| ^~~
to:
../x86_64-pc-linux-gnu/libstdc++-v3/include/vector:87:27: error: msg 1
87 | using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
| ^~~~~~
../x86_64-pc-linux-gnu/libstdc++-v3/include/vector:74:1: note: msg 2
73 | # include <debug/vector>
+++ |+#include <vector>
74 | #endif
eliminating the repetition of line 87 in the note.
Doing so requires converting show_caret_p to a tri-state, to avoid
meaninglessly printing a caret for the first column in the next line
(and colorizing it):
../x86_64-pc-linux-gnu/libstdc++-v3/include/vector:74:1: note: msg 2
73 | # include <debug/vector>
+++ |+#include <vector>
74 | #endif
| ^
gcc/c-family/ChangeLog:
PR 87091
* c-common.c (c_cpp_error): Update for conversion of show_caret_p
to a tri-state.
(maybe_suggest_missing_token_insertion): Likewise.
(maybe_add_include_fixit): Add param "override_location". If set,
and source-printing is enabled, then override the rich_location's
primary location with that of the insertion point for the fix-it
hint, marking it with SHOW_LINES_WITHOUT_RANGE.
* c-common.h (extern void maybe_add_include_fixit): Add bool
param.
* c-format.c (selftest::test_type_mismatch_range_labels): Update
for conversion of show_caret_p to a tri-state.
* c-warn.c (warn_for_restrict): Likewise.
* known-headers.cc
(suggest_missing_header::~suggest_missing_header): Update call to
maybe_add_include_fixit to suggest overriding the location, as it
is for a note.
gcc/c/ChangeLog:
PR 87091
* c-decl.c (implicitly_declare): Update call to
maybe_add_include_fixit to suggest overriding the location, as it
is for a note.
* c-objc-common.c (c_tree_printer): Update for conversion of
show_caret_p to a tri-state.
gcc/cp/ChangeLog:
PR 87091
* decl.c (grokdeclarator): Update for conversion of show_caret_p
to a tri-state.
* error.c (cp_printer): Likewise.
* name-lookup.c (maybe_suggest_missing_std_header): Update call to
maybe_add_include_fixit to suggest overriding the location, as it
is for a note.
* parser.c (cp_parser_string_literal): Update for conversion of
show_caret_p to a tri-state.
(cp_parser_elaborated_type_specifier): Likewise.
(set_and_check_decl_spec_loc): Likewise.
* pt.c (listify): Update call to maybe_add_include_fixit to not
override the location, as it is for an error.
* rtti.c (typeid_ok_p): Likewise.
gcc/ChangeLog:
PR 87091
* diagnostic-show-locus.c (class layout_range): Update for
conversion of show_caret_p to a tri-state.
(layout_range::layout_range): Likewise.
(make_range): Likewise.
(layout::maybe_add_location_range): Likewise.
(layout::should_print_annotation_line_p): Don't show annotation
lines for ranges that are SHOW_LINES_WITHOUT_RANGE.
(layout::get_state_at_point): Update for conversion of
show_caret_p to a tri-state. Bail out early for
SHOW_LINES_WITHOUT_RANGE, so that such ranges don't affect
underlining or source colorization.
(gcc_rich_location::add_location_if_nearby): Update for conversion
of show_caret_p to a tri-state.
(selftest::test_one_liner_multiple_carets_and_ranges): Likewise.
(selftest::test_one_liner_fixit_replace_equal_secondary_range):
Likewise.
(selftest::test_one_liner_labels): Likewise.
* gcc-rich-location.c (gcc_rich_location::add_expr): Update for
conversion of show_caret_p to a tri-state.
* pretty-print.c (text_info::set_location): Likewise.
* pretty-print.h (text_info::set_location): Likewise.
* substring-locations.c (format_warning_n_va): Likewise.
* tree-diagnostic.c (default_tree_printer): Likewise.
* tree-pretty-print.c (newline_and_indent): Likewise.
gcc/fortran/ChangeLog:
PR 87091
* error.c (gfc_format_decoder): Update for conversion of
show_caret_p to a tri-state.
gcc/testsuite/ChangeLog:
PR 87091
* gcc.dg/empty.h: New file.
* gcc.dg/fixits-pr84852-1.c: Update for move of fix-it hint to
top of file and removal of redundant second printing of warning
location.
* gcc.dg/fixits-pr84852-2.c: Likewise.
* gcc.dg/missing-header-fixit-3.c: Likewise.
* gcc.dg/missing-header-fixit-4.c: New test.
* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c: Update for
conversion of show_caret_p to a tri-state.
libcpp/ChangeLog:
PR 87091
* include/line-map.h (enum range_display_kind): New enum.
(struct location_range): Replace field "m_show_caret_p" with
"m_range_display_kind", converting from bool to the new enum.
(class rich_location): Add example of line insertion fix-it hint.
(rich_location::add_range): Convert param "show_caret_p" from bool
to enum range_display_kind and rename to "range_display_kind",
giving it a default of SHOW_RANGE_WITHOUT_CARET.
(rich_location::set_range): Likewise, albeit without a default.
* line-map.c (rich_location::rich_location): Update for conversion
of show_caret_p to tri-state enum.
(rich_location::add_range): Likewise.
(rich_location::set_range): Likewise.
From-SVN: r263885
With profiledbootstrap and --with-build-config=bootstrap-lto, linemap_add
may create a macro map when we run out of line map space. This patch
changes start_location to UNKNOWN_LOCATION (0) in this case.
Tested with profiledbootstrap and --with-build-config=bootstrap-lto on
Linux/x86-64.
PR bootstrap/86872
* line-map.c (pure_location_p): Return true if linemap_lookup
returns NULL.
(linemap_add): Set start_location to 0 if we run out of line map
space.
From-SVN: r263845
https://gcc.gnu.org/ml/gcc-patches/2018-08/msg01164.html
* include/cpplib.h (NODE_BUILTIN, NODE_MACRO_ARG): Delete.
Renumber others.
(enum node_type): Replace NT_MACRO with NT_USER_MACRO,
NT_BUILTIN_MACRO, NT_MACRO_ARG. Delete NT_ASSERTION.
(NTV_MACRO, NTV_ANSWER, NTV_BUILTIN, NTV_ARGUMENT, NTV_NONE):
Delete.
(CPP_HASHNODE_VALUE_IDX): Delete.
(union _cpp_hashnode_value): GTY tag from enum node_type directly.
(struct cpp_hashnode): Adjust GTY desc for value field.
(cpp_user_macro_p, cpp_builtin_macro_p, cpp_macro_p): Adjust.
* directives.c (undefine_macros): Clear value.anwers, adjust flag
clearing.
(_cpp_test_assertion): No need to check NT_ASSERTION.
(do_assert, do_unassert): Likewise.
* init.c (cpp_init_special_builtins): Set type not flags.
* macro.c (struct macro_arg_saved_data): Add type field.
(cpp_get_token_1): Check type not NT_VOID.
(_cpp_free_definition): Adjust flag clearing. Nullify
value.answers.
(_cpp_save_parameter, _cpp_unsave_parameters): Save and restore
type.
(lex_expansion_token): Check type not flags.
(_cpp_create_definition): Set type to NT_USER_MACRO.
(_cpp_notify_macro_use): Adjust type checking.
* pch.c (write_macdef, count_defs, write_defs, cpp_valid_state)
(save_macros): Adjust node type/flag handling.
* traditional.c (_cpp_scan_out_logical_line): Check type not flags.
From-SVN: r263667
This patch adds the ability to label source ranges within a rich_location,
to be printed by diagnostic_show_locus.
For example:
pr69554-1.c:11:18: error: invalid operands to binary + (have 'const char *' and 'const char *')
11 | return (p + 1) + (q + 1);
| ~~~~~~~ ^ ~~~~~~~
| | |
| | const char *
| const char *
The patch implements labels for various type mismatch errors in the C and
C++ frontends, and in -Wformat. I implemented it wherever accurate location
information was guaranteed (there are other places that could benefit, but
we need better location information in those places).
The labels can be disabled via -fno-diagnostics-show-labels.
Similarly:
param-type-mismatch.C: In function 'int test_1(int, int, float)':
param-type-mismatch.C:11:27: error: invalid conversion from 'int' to 'const char*' [-fpermissive]
11 | return callee_1 (first, second, third);
| ^~~~~~
| |
| int
param-type-mismatch.C:7:43: note: initializing argument 2 of 'int callee_1(int, const char*, float)'
7 | extern int callee_1 (int one, const char *two, float three);
| ~~~~~~~~~~~~^~~
where the first "error" describing the bad argument gets a label
describing the type inline (since it's non-obvious from "second").
The "note" describing the type of the param of the callee *doesn't*
get a label, since that information is explicit there in the
source ("const char *two").
The idea is that in any diagnostic where two aspects of the source aren't
in sync it ought to be easier for the user if we directly show them the
mismatching aspects inline (e.g. types).
As well as type mismatch errors, perhaps labels could also be used for
buffer overflow warnings, for describing the capacity of the destination
buffer vs the size of what's being written:
sprintf (buf, "filename: %s\n", file);
^~~ ~~~~~~~~~~~^~~
| |
capacity: 32 10 + strlen(file) + 2
or somesuch. Another idea might be for macro expansion warnings:
warning: repeated side effects in macro expansion...
x = MIN (p++, q++);
~~~~^~~~~~~~~~
note: ...expanded here as
#define MIN(X,Y) (X<Y?X:Y)
^~~ ~ ~ ~ ~ ~ ~
| | | | | |
| | | | | q++
| | | | p++
| | | q++
| q++ p++
p++
The patch removes some logic from multiline.exp which special-cased
lines ending with a '|' character (thus complicating testing of this
patch). I believe that this was a vestige from experiments I did to
support strippng dg directives from the output; it was present in the
earliest version of multiline.exp I posted:
"[RFC, stage1] Richer source location information for gcc 6 (location ranges etc)"
https://gcc.gnu.org/ml/gcc-patches/2015-03/msg00837.html
and I believe was neved used.
gcc/c-family/ChangeLog:
* c-format.c: Include "selftest-diagnostic.h" and
"gcc-rich-location.h".
(format_warning_at_char): Pass NULL for new label params of
format_warning_va.
(class indirection_suffix): New class.
(class range_label_for_format_type_mismatch): New class.
(format_type_warning): Move logic for generating "*" suffix to
class indirection_suffix. Create "fmt_label" and "param_label"
to show their types, and pass them to the
format_warning_at_substring calls.
(selftest::test_type_mismatch_range_labels): New test.
(selftest::c_format_c_tests): Call it.
gcc/c/ChangeLog:
* c-objc-common.c: Include "gcc-rich-location.h".
(c_tree_printer): Move implemenation of '%T' to...
(print_type): ...this new function.
(range_label_for_type_mismatch::get_text): New function.
* c-typeck.c (convert_for_assignment): Add type labels to the rhs
range for the various ic_argpass cases.
(class maybe_range_label_for_tree_type_mismatch): New class.
(build_binary_op): Use it when calling binary_op_error.
gcc/cp/ChangeLog:
* call.c: Include "gcc-rich-location.h".
(convert_like_real): Add range label for "invalid conversion"
diagnostic.
(perform_implicit_conversion_flags): Add type label to the
"could not convert" error.
* error.c: Include "gcc-rich-location.h".
(range_label_for_type_mismatch::get_text): New function.
* typeck.c (convert_for_assignment): Add type label to
the "cannot convert" error if a location is available.
gcc/ChangeLog:
* common.opt (fdiagnostics-show-labels): New option.
* diagnostic-show-locus.c (class layout_range): Add field
"m_label".
(class layout): Add field "m_show_labels_p".
(layout_range::layout_range): Add param "label" and use it to
initialize m_label.
(make_range): Pass in NULL for new "label" param of layout_range's
ctor.
(layout::layout): Initialize m_show_labels_p.
(layout::maybe_add_location_range): Pass in loc_range->m_label
when constructing layout_range instances.
(struct line_label): New struct.
(layout::print_any_labels): New member function.
(layout::print_line): Call it if label-printing is enabled.
(selftest::test_one_liner_labels): New test.
(selftest::test_diagnostic_show_locus_one_liner): Call it.
* diagnostic.c (diagnostic_initialize): Initialize
context->show_labels_p.
* diagnostic.h (struct diagnostic_context): Add field
"show_labels_p".
* doc/invoke.texi (Diagnostic Message Formatting Options): Add
-fno-diagnostics-show-labels.
* dwarf2out.c (gen_producer_string): Add
OPT_fdiagnostics_show_labels to the ignored options.
* gcc-rich-location.c (gcc_rich_location::add_expr): Add "label"
param.
(gcc_rich_location::maybe_add_expr): Likewise.
* gcc-rich-location.h (gcc_rich_location::gcc_rich_location): Add
label" param, defaulting to NULL.
(gcc_rich_location::add_expr): Add "label" param.
(gcc_rich_location::maybe_add_expr): Likewise.
(class text_range_label): New class.
(class range_label_for_type_mismatch): New class.
* gimple-ssa-sprintf.c (fmtwarn): Pass NULL for new label params
of format_warning_va.
(fmtwarn_n): Likewise for new params of format_warning_n_va.
* lto-wrapper.c (merge_and_complain): Add
OPT_fdiagnostics_show_labels to the "pick one setting" options.
(append_compiler_options): Likewise to the dropped options.
(append_diag_options): Likewise to the passed-on options.
* opts.c (common_handle_option): Handle the new option.
* selftest-diagnostic.c
(test_diagnostic_context::test_diagnostic_context): Enable
show_labels_p.
* substring-locations.c: Include "gcc-rich-location.h".
(format_warning_n_va): Add "fmt_label" and "param_label" params
and use them as appropriate.
(format_warning_va): Add "fmt_label" and "param_label" params,
passing them on to format_warning_n_va.
(format_warning_at_substring): Likewise.
(format_warning_at_substring_n): Likewise.
* substring-locations.h (format_warning_va): Add "fmt_label" and
"param_label" params.
(format_warning_n_va): Likewise.
(format_warning_at_substring): Likewise.
(format_warning_at_substring_n): Likewise.
* toplev.c (general_init): Initialize global_dc->show_labels_p.
gcc/testsuite/ChangeLog:
* g++.dg/diagnostic/aka3.C: New test.
* g++.dg/diagnostic/param-type-mismatch-2.C: Update expected
output to show range labels.
* g++.dg/diagnostic/param-type-mismatch.C: Likewise.
* g++.dg/plugin/plugin.exp (plugin_test_list): Add...
* g++.dg/plugin/show-template-tree-color-labels.C: New test.
* gcc.dg/bad-binary-ops.c: Update expected output to show range
labels. Add an "aka" example.
* gcc.dg/cpp/pr66415-1.c: Update expected output to show range
labels.
* gcc.dg/format/diagnostic-ranges.c: Likewise.
* gcc.dg/format/pr72858.c: Likewise.
* gcc.dg/format/pr78498.c: Likewise.
* gcc.dg/param-type-mismatch.c: Add "-Wpointer-sign" to options.
Update expected output to show range labels. Add examples of
-Wincompatible-pointer-types and -Wpointer-sign for parameters.
* gcc.dg/plugin/diagnostic-test-show-locus-bw-line-numbers.c:
Update expected output to show range labels.
* gcc.dg/plugin/diagnostic-test-show-locus-bw.c: Likewise.
(test_very_wide_line): Adjust so that label is at left-clipping
boundary.
(test_very_wide_line_2): New test.
* gcc.dg/plugin/diagnostic-test-show-locus-color-line-numbers.c:
Update expected output to show range labels.
* gcc.dg/plugin/diagnostic-test-show-locus-color.c: Likewise.
* gcc.dg/plugin/diagnostic-test-show-locus-no-labels.c: New test.
* gcc.dg/plugin/diagnostic_plugin_show_trees.c (show_tree): Update
for new param to gcc_rich_location::add_expr.
* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c (add_range):
Add "label" param.
(test_show_locus): Add examples of labels to various tests. Tweak
the "very wide_line" test case and duplicate it, to cover the
boundary values for clipping of labels against the left-margin.
* gcc.dg/plugin/plugin.exp (plugin_test_list): Add
diagnostic-test-show-locus-no-labels.c.
* gcc.dg/pr69554-1.c: Update expected output to show range labels.
Update line numbers of dg-locus directives.
* gcc.dg/pr69627.c: Update expected output to show range labels.
* lib/multiline.exp (proc _build_multiline_regex): Remove
special-case handling of lines with trailing '|'.
libcpp/ChangeLog:
* include/line-map.h (struct location_range): Add "m_label" field.
(class rich_location): Add description of labels to leading
comment.
(rich_location::rich_location): Add "label" param, defaulting to
NULL.
(rich_location::add_range): Likewise.
(struct label_text): New struct.
(class range_label): New abstract base class.
* line-map.c (rich_location::rich_location): Add "label" param;
use it.
(rich_location::add_range): Likewise.
From-SVN: r263564
libcpp:
2018-07-18 Bernd Edlinger <bernd.edlinger@hotmail.de>
PR 69558
* macro.c (enter_macro_context): Change the location info for builtin
macros and _Pragma from location of the closing parenthesis to location
of the macro expansion point.
testsuite:
2018-07-18 Bernd Edlinger <bernd.edlinger@hotmail.de>
PR 69558
* c-c++-common/cpp/diagnostic-pragma-2.c: New test.
* c-c++-common/pr69558.c: Remove xfail.
* gcc.dg/cpp/builtin-macro-1.c: Adjust test expectations.
* gcc.dg/pr61817-1.c: Likewise.
* gcc.dg/pr61817-2.c: Likewise.
* g++.dg/plugin/pragma_plugin.c: Warn at expansion_point_location.
From-SVN: r262861
* lex.c (_cpp_lex_direct): Use CPP_DL_NOTE instead of CPP_DL_PEDWARN,
CPP_DL_WARNING or CPP_DL_ERROR for note that diagnostics for C++ style
comments is reported only once per file and guard those calls on the
preceding cpp_error returning true.
* gcc.dg/cpp/pr61854-c90.c (foo): Expect a note, rather than error.
* gcc.dg/cpp/pr61854-c94.c (foo): Likewise.
* gcc.dg/cpp/pr61854-4.c (foo): Likewise.
* gcc.dg/cpp/pr61854-8.c: New test.
From-SVN: r262832
PR c/84852 reports an ICE inside diagnostic_show_locus when printing
a diagnostic for a source file with a #line >= 2^31:
#line 7777777777
int foo (void) { return strlen(""); }
where we're attempting to print a fix-it hint at the top of the file
and underline the "strlen" (two "line spans").
The
#line 7777777777
won't fix within the 32-bit linenum_type, and is truncated from
0x1cf977871
to
0xcf977871
i.e. 3482810481 in decimal.
Such a #line is reported by -pedantic and -pedantic-errors, but we
shouldn't ICE.
The ICE is an assertion failure within layout::calculate_line_spans,
where the line spans have not been properly sorted.
The layout_ranges are stored as int, rather than linenum_type,
giving line -812156815 for the error, and line 1 for the fix-it hint.
However, line_span uses linenum_type rather than int.
line_span::comparator compares these values as int, and hence
decides that (linenum_type)3482810481 aka (int)-812156815 is less
than line 1.
This leads to this assertion failing in layout::calculate_line_spans:
1105 gcc_assert (next->m_first_line >= current->m_first_line);
since it isn't the case that 1 >= 3482810481.
The underlying problem is the mix of types for storing line numbers:
in parts of libcpp and diagnostic-show-locus.c we use linenum_type;
in other places (including libcpp's expanded_location) we use int.
I looked at using linenum_type throughout, but doing so turned into
a large patch, so this patch fixes the ICE in a less invasive way
by merely using linenum_type more consistently just within
diagnostic-show-locus.c, and fixing line_span::comparator to properly
handle line numbers (and line number differences) >= 2^31, by using
a new helper function for linenum_type differences, computing the
difference using long long, and using the sign of the difference
(as the difference might not fit in the "int" return type imposed
by qsort).
gcc/ChangeLog:
PR c/84852
* diagnostic-show-locus.c (class layout_point): Convert m_line
from int to linenum_type.
(line_span::comparator): Use linenum "compare" function when
comparing line numbers.
(test_line_span): New function.
(layout_range::contains_point): Convert param "row" from int to
linenum_type.
(layout_range::intersects_line_p): Likewise.
(layout::will_show_line_p): Likewise.
(layout::print_source_line): Likewise.
(layout::should_print_annotation_line_p): Likewise.
(layout::print_annotation_line): Likewise.
(layout::print_leading_fixits): Likewise.
(layout::annotation_line_showed_range_p): Likewise.
(struct line_corrections): Likewise for field m_row.
(line_corrections::line_corrections): Likewise for param "row".
(layout::print_trailing_fixits): Likewise.
(layout::get_state_at_point): Likewise.
(layout::get_x_bound_for_row): Likewise.
(layout::print_line): Likewise.
(diagnostic_show_locus): Likewise for locals "last_line" and
"row".
(selftest::diagnostic_show_locus_c_tests): Call test_line_span.
* input.c (selftest::test_linenum_comparisons): New function.
(selftest::input_c_tests): Call it.
* selftest.c (selftest::test_assertions): Test ASSERT_GT,
ASSERT_GT_AT, ASSERT_LT, and ASSERT_LT_AT.
* selftest.h (ASSERT_GT): New macro.
(ASSERT_GT_AT): New macro.
(ASSERT_LT): New macro.
(ASSERT_LT_AT): New macro.
gcc/testsuite/ChangeLog:
PR c/84852
* gcc.dg/fixits-pr84852-1.c: New test.
* gcc.dg/fixits-pr84852-2.c: New test.
libcpp/ChangeLog:
* include/line-map.h (compare): New function on linenum_type.
From-SVN: r258526
gcc/testsuite:
PR preprocessor/84517
* g++.dg/cpp0x/udlit-macros.C: Expect a warning for ""__FILE__.
libcpp:
PR preprocessor/84517
* lex.c (is_macro_not_literal_suffix): New function.
(lex_raw_string, lex_string): Use is_macro_not_literal_suffix to
decide when to issue -Wliteral-suffix warnings.
From-SVN: r258069
PR preprocessor/83708
* macro.c (vaopt_state): Reorder m_last_was_paste before m_state.
(vaopt_state::vaopt_state): Adjust.
(vaopt_state::update_flags): Add BEGIN and END.
(vaopt_state::update): Return them.
(copy_paste_flag): Factor out of replace_args.
(last_token_is): New.
(replace_args): Handle BEGIN and END. Avoid padding there.
(tokens_buff_last_token_ptr): Return NULL if no tokens.
Co-Authored-By: Jakub Jelinek <jakub@redhat.com>
From-SVN: r257696
PR preprocessor/69869
* traditional.c (skip_macro_block_comment): Return bool, true if
the macro block comment is unterminated.
(copy_comment): Use return value from skip_macro_block_comment instead
of always false.
* gcc.dg/cpp/trad/pr69869.c: New test.
From-SVN: r257220
* c-cppbuiltin.c (c_cpp_builtins): Use ggc_strdup for the fp_suffix
argument.
(LAZY_HEX_FP_VALUES_CNT): Define.
(lazy_hex_fp_values): Allow up to LAZY_HEX_FP_VALUES_CNT lazy hex fp
values rather than just 12.
(builtin_define_with_hex_fp_value): Likewise.
* include/cpplib.h (enum cpp_builtin_type): Change BT_LAST_USER from
BT_FIRST_USER + 31 to BT_FIRST_USER + 63.
From-SVN: r257118
This commit adds the -fmacro-prefix-map option that allows remapping of file
names in __FILE__, __BASE_FILE__, and __builtin_FILE(), similar to how
-fdebug-prefix-map allows to do the same for debug information.
Additionally, it adds -ffile-prefix-map which can be used to specify both
mappings with a single option (and, should we need to add more -f*-prefix-map
options in the future, those as well).
libcpp/ChangeLog:
2018-01-18 Boris Kolpackov <boris@codesynthesis.com>
PR other/70268
* include/cpplib.h (cpp_callbacks::remap_filename): New callback.
* libcpp/macro.c (_cpp_builtin_macro_text): Call remap_filename for
__FILE__ and __BASE_FILE__.
gcc/ChangeLog:
2018-01-18 Boris Kolpackov <boris@codesynthesis.com>
PR other/70268
* common.opt: (-ffile-prefix-map): New option.
* opts.c (common_handle_option): Defer it.
* opts-global.c (handle_common_deferred_options): Handle it.
* debug.h (remap_debug_filename, add_debug_prefix_map): Move to...
* file-prefix-map.h: New file.
(remap_debug_filename, add_debug_prefix_map): ...here.
(add_macro_prefix_map, add_file_prefix_map, remap_macro_filename): New.
* final.c (debug_prefix_map, add_debug_prefix_map
remap_debug_filename): Move to...
* file-prefix-map.c: New file.
(file_prefix_map, add_prefix_map, remap_filename) ...here and rename,
generalize, get rid of alloca(), use strrchr() instead of strchr().
(add_macro_prefix_map, add_debug_prefix_map, add_file_prefix_map):
Implement in terms of add_prefix_map().
(remap_macro_filename, remap_debug_filename): Implement in term of
remap_filename().
* Makefile.in (OBJS, PLUGIN_HEADERS): Add new files.
* builtins.c (fold_builtin_FILE): Call remap_macro_filename().
* dbxout.c: Include file-prefix-map.h.
* varasm.c: Likewise.
* vmsdbgout.c: Likewise.
* xcoffout.c: Likewise.
* dwarf2out.c: Likewise plus omit new options from DW_AT_producer.
* doc/cppopts.texi (-fmacro-prefix-map): Document.
* doc/invoke.texi (-ffile-prefix-map): Document.
(-fdebug-prefix-map): Update description.
gcc/c-family/ChangeLog:
2018-01-18 Boris Kolpackov <boris@codesynthesis.com>
PR other/70268
* c-family/c.opt (-fmacro-prefix-map): New option.
* c-family/c-opts.c (c_common_handle_option): Handle it.
* c-family/c-lex.c (init_c_lex): Set remap_filename cpp callback.
* c-family/c-ppoutput.c (init_pp_output): Likewise.
gcc/testsuite/ChangeLog:
2018-01-18 Boris Kolpackov <boris@codesynthesis.com>
PR other/70268
* c-c++-common/ffile-prefix-map.c: New test.
* c-c++-common/fmacro-prefix-map.c: New test.
* c-c++-common/cpp/ffile-prefix-map.c: New test.
* c-c++-common/cpp/fmacro-prefix-map.c: New test.
From-SVN: r256847
libcpp/
* expr.c (interpret_float_suffix): Ignore 'i' in C++14 and up.
(interpret_int_suffix): Likewise.
gcc/cp/
* parser.c (cp_parser_userdef_numeric_literal): Be helpful about
'i' in C++14 and up.
From-SVN: r255335
PR c/82050 reports a failed assertion deep within diagnostic_show_locus's
code for printing fix-it hints.
The root cause is a fix-it hint suggesting a textual replacement,
where the affected column numbers straddle the LINE_MAP_MAX_COLUMN_NUMBER
boundary, so that the start of the range has a column number, but the
end of the range doesn't.
The fix is to verify that the column numbers are sane when adding fix-it
hints to a rich_location, rejecting fix-it hints where they are not.
libcpp/ChangeLog:
PR c/82050
* include/line-map.h (LINE_MAP_MAX_COLUMN_NUMBER): Move here.
* line-map.c (LINE_MAP_MAX_COLUMN_NUMBER): ...from here.
(rich_location::maybe_add_fixit): Reject fix-it hints in which
the start column exceeds the next column.
From-SVN: r255214
libcpp/ChangeLog:
2017-03-24 Eric Gallager <egall@gwmail.gwu.edu>
PR preprocessor/81794
* macro.c (check_trad_stringification): Have warning be controlled
by -Wtraditional.
gcc/testsuite/ChangeLog:
2017-09-17 Eric Gallager <egall@gwmail.gwu.edu>
PR preprocessor/81794
* gcc.dg/pragma-diag-7.c: Update to include check for
stringification.
From-SVN: r254981
This patch uses the name_hint/deferred_diagnostic to provide
a message in the C++ frontend if a macro is used before it is defined
e.g.:
test.c:6:24: error: expected ';' at end of member declaration
virtual void clone() const OVERRIDE { }
^~~~~
;
test.c:6:30: error: 'OVERRIDE' does not name a type
virtual void clone() const OVERRIDE { }
^~~~~~~~
test.c:6:30: note: the macro 'OVERRIDE' had not yet been defined
test.c:15:0: note: it was later defined here
#define OVERRIDE override
It's possible to do it from the C++ frontend as tokenization happens
up-front (and hence the macro already exists when the above is parsed);
I attempted to do it from the C frontend, but because the C frontend only
tokenizes on-demand during parsing, the macro isn't known about until
later.
gcc/cp/ChangeLog:
PR c++/72786
* name-lookup.c (class macro_use_before_def): New class.
(lookup_name_fuzzy): Detect macro that were used before being
defined, and report them as such.
gcc/ChangeLog:
PR c++/72786
* spellcheck.h (best_match::blithely_get_best_candidate): New
accessor.
gcc/testsuite/ChangeLog:
PR c++/72786
* g++.dg/spellcheck-macro-ordering-2.C: New test case.
* g++.dg/spellcheck-macro-ordering.C: Add dg-message directives
for macro used-before-defined.
libcpp/ChangeLog:
PR c++/72786
* include/cpplib.h (cpp_macro_definition_location): New decl.
* macro.c (cpp_macro_definition): New function.
From-SVN: r254978
This implements __VA_OPT__, a new preprocessor feature added in C++2A.
The paper can be found here:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0306r4.html
gcc/ChangeLog
* doc/cpp.texi (Variadic Macros): Document __VA_OPT__.
gcc/testsuite/ChangeLog
* c-c++-common/cpp/va-opt-pedantic.c: New file.
* c-c++-common/cpp/va-opt.c: New file.
* c-c++-common/cpp/va-opt-error.c: New file.
libcpp/ChangeLog
* pch.c (cpp_read_state): Set n__VA_OPT__.
* macro.c (vaopt_state): New class.
(_cpp_arguments_ok): Check va_opt flag.
(replace_args, create_iso_definition): Use vaopt_state.
* lex.c (lex_identifier_intern): Possibly issue errors for
__VA_OPT__.
(lex_identifier): Likewise.
(maybe_va_opt_error): New function.
* internal.h (struct lexer_state) <va_args_ok>: Update comment.
(struct spec_nodes) <n__VA_OPT__>: New field.
* init.c (struct lang_flags) <va_opt>: New field.
(lang_defaults): Add entries for C++2A. Update all entries for
va_opt.
(cpp_set_lang): Initialize va_opt.
* include/cpplib.h (struct cpp_options) <va_opt>: New field.
* identifiers.c (_cpp_init_hashtable): Initialize n__VA_OPT__.
From-SVN: r254707
The description of our 1-based column-numbering convention was in
a non-obvious place withn line-map.h; this patch moves it to the top
of that header.
libcpp/ChangeLog:
* include/line-map.h (linenum_type): Move this typedef and the
comment describing column numbering to near the top of the file.
From-SVN: r254703
/libcpp
2017-11-06 Mukesh Kapoor <mukesh.kapoor@oracle.com>
PR c++/80955
* lex.c (lex_string): When checking for a valid macro for the
warning related to -Wliteral-suffix (CPP_W_LITERAL_SUFFIX),
check that the macro name does not start with an underscore
before calling is_macro().
/gcc/testsuite
2017-11-06 Mukesh Kapoor <mukesh.kapoor@oracle.com>
PR c++/80955
* g++.dg/cpp0x/udlit-macros.C: New.
From-SVN: r254443
Adding a fix-it hint currently involves changing e.g.:
error_at (token->location,
"unknown type name %qE; did you mean %qs?",
token->value, hint);
to:
gcc_rich_location richloc (token->location);
richloc.add_fixit_replace (hint);
error_at_rich_loc (&richloc,
"unknown type name %qE; did you mean %qs?",
token->value, hint);
to make the change from taking a location_t to a rich_location *.
This patch renames the "*_at_rich_loc" diagnostic entrypoints to use
the same function names for rich_location * as for location_t,
via overloading, to simplify the above change to just changing from:
error_at (token->location,
"unknown type name %qE; did you mean %qs?",
token->value, hint);
to:
gcc_rich_location richloc (token->location);
richloc.add_fixit_replace (hint);
error_at (&richloc,
"unknown type name %qE; did you mean %qs?",
token->value, hint);
thus saving space (and typing) and usually avoiding the need to reindent
the "error_at" invocation.
With this change, 0 is no longer acceptable as a location_t to these
entrypoints, as e.g.:
../../src/gcc/auto-profile.c:855:37: error: call of overloaded
'inform(int, const char [18])' is ambiguous
inform (0, "Not expected TAG.");
^
In file included from ../../src/gcc/auto-profile.c:35:0:
../../src/gcc/diagnostic-core.h:88:13: note: candidate:
'void inform(location_t, const char*, ...)'
extern void inform (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
^~~~~~
../../src/gcc/diagnostic-core.h:89:13: note: candidate:
'void inform(rich_location*, const char*, ...)'
extern void inform (rich_location *, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
^~~~~~
Such locations now need to be spelled out as UNKNOWN_LOCATION,
rather than 0.
I considered making the API take a rich_location & rather than a
rich_location *, but doing so would mean replacing
diagnostic_set_info
and
diagnostic_set_info_translated
with a constructor for diagnostic_info, which was a more invasive
change. Maybe in the future.
gcc/ChangeLog:
* auto-profile.c (autofdo_source_profile::read): Use
UNKNOWN_LOCATION rather than 0.
* diagnostic-core.h (warning_at_rich_loc): Rename to...
(warning_at): ...this overload.
(warning_at_rich_loc_n): Rename to...
(warning_n): ...this overload.
(error_at_rich_loc): Rename to...
(error_at): ...this overload.
(pedwarn_at_rich_loc): Rename to...
(pedwarn): ...this overload.
(permerror_at_rich_loc): Rename to...
(permerror): ...this overload.
(inform_at_rich_loc): Rename to...
(inform): ...this overload.
* diagnostic.c: (diagnostic_n_impl): Delete location_t-based decl.
(diagnostic_n_impl_richloc): Rename to...
(diagnostic_n_impl): ...this rich_location *-based decl.
(inform_at_rich_loc): Rename to...
(inform): ...this, and add an assertion.
(inform_n): Update for removal of location_t-based diagnostic_n_impl.
(warning_at_rich_loc): Rename to...
(warning_at): ...this, and add an assertion.
(warning_at_rich_loc_n): Rename to...
(warning_n): ...this, and add an assertion.
(warning_n): Update location_t-based implementation for removal of
location_t-based diagnostic_n_impl.
(pedwarn_at_rich_loc): Rename to...
(pedwarn): ...this, and add an assertion.
(permerror_at_rich_loc): Rename to...
(permerror): ...this, and add an assertion.
(error_n): Update for removal of location_t-based diagnostic_n_impl.
(error_at_rich_loc): Rename to...
(error_at): ...this, and add an assertion.
* gcc.c (do_spec_1): Use UNKNOWN_LOCATION rather than 0.
(driver::do_spec_on_infiles): Likewise.
* substring-locations.c (format_warning_va): Update for renaming
of inform_at_rich_loc.
gcc/c-family/ChangeLog:
* c-common.c (binary_op_error): Update for renaming of
error_at_rich_loc.
(c_parse_error): Likewise.
* c-warn.c (warn_logical_not_parentheses): Likewise for
renaming of inform_at_rich_loc.
(warn_for_restrict): Likewise for renaming of
warning_at_rich_loc_n.
gcc/c/ChangeLog:
* c-decl.c (implicit_decl_warning): Update for renaming of
pedwarn_at_rich_loc and warning_at_rich_loc.
(implicitly_declare): Likewise for renaming of inform_at_rich_loc.
(undeclared_variable): Likewise for renaming of error_at_rich_loc.
* c-parser.c (c_parser_declaration_or_fndef): Likewise.
(c_parser_struct_or_union_specifier): Likewise for renaming of
pedwarn_at_rich_loc.
(c_parser_parameter_declaration): Likewise for renaming of
error_at_rich_loc.
* c-typeck.c (build_component_ref): Likewise.
(build_unary_op): Likewise for renaming of inform_at_rich_loc.
(pop_init_level): Likewise for renaming of warning_at_rich_loc.
(set_init_label): Likewise for renaming of error_at_rich_loc.
gcc/cp/ChangeLog:
* class.c (explain_non_literal_class): Use UNKNOWN_LOCATION rather
than 0.
* name-lookup.c (suggest_alternatives_for): Update for renaming of
inform_at_rich_loc.
(maybe_suggest_missing_header): Likewise.
(suggest_alternative_in_explicit_scope): Likewise.
* parser.c (cp_parser_diagnose_invalid_type_name): Likewise for
renaming of error_at_rich_loc.
(cp_parser_string_literal): Likewise.
(cp_parser_nested_name_specifier_opt): Likewise.
(cp_parser_cast_expression): Likewise for renaming of
warning_at_rich_loc.
(cp_parser_decl_specifier_seq): Likewise for renaming of
error_at_rich_loc and warning_at_rich_loc.
(cp_parser_elaborated_type_specifier): Likewise for renaming of
pedwarn_at_rich_loc.
(cp_parser_cv_qualifier_seq_opt): Likewise for renaming of
error_at_rich_loc.
(cp_parser_virt_specifier_seq_opt): Likewise.
(cp_parser_class_specifier_1): Likewise.
(cp_parser_class_head): Likewise.
(cp_parser_member_declaration): Likewise for renaming of
pedwarn_at_rich_loc, warning_at_rich_loc, and error_at_rich_loc.
(cp_parser_enclosed_template_argument_list): Likewise for renaming
of error_at_rich_loc.
(set_and_check_decl_spec_loc): Likewise.
* pt.c (listify): Likewise.
* rtti.c (typeid_ok_p): Likewise.
* semantics.c (process_outer_var_ref): Use UNKNOWN_LOCATION rather
than 0.
* typeck.c (access_failure_info::maybe_suggest_accessor): Update
for renaming of inform_at_rich_loc.
(finish_class_member_access_expr): Likewise for renaming of
error_at_rich_loc.
gcc/objc/ChangeLog:
* objc-gnu-runtime-abi-01.c (objc_gnu_runtime_abi_01_init): Use
UNKNOWN_LOCATION rather than 0.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/diagnostic_plugin_show_trees.c (show_tree): Update
for renaming of error_at_rich_loc and inform_at_rich_loc.
* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
(test_show_locus): Likewise for renaming of warning_at_rich_loc.
libcpp/ChangeLog:
* directives.c (_cpp_handle_directive): Update for renaming of
cpp_error_at_richloc to cpp_error_at.
* errors.c (cpp_diagnostic_at_richloc): Rename to...
(cpp_diagnostic_at): ...this, dropping the location_t-based
implementation.
(cpp_diagnostic): Update for removal of location_t-based
cpp_diagnostic_at.
(cpp_error_at): Likewise.
(cpp_error_at_richloc): Rename to...
(cpp_error_at): ...this, and update for renaming of
cpp_diagnostic_at_richloc.
* include/cpplib.h (cpp_error_at_richloc): Rename to...
(cpp_error_at): ...this.
From-SVN: r254280
C17, a bug-fix version of the C11 standard with DR resolutions
integrated, will soon go to ballot. This patch adds corresponding
options -std=c17, -std=gnu17 (new default version, replacing
-std=gnu11 as the default), -std=iso9899:2017. As a bug-fix version
of the standard, there is no need for flag_isoc17 or any options for
compatibility warnings; however, there is a new __STDC_VERSION__
value, so new cpplib languages CLK_GNUC17 and CLK_STDC17 are added to
support using that new value with the new options. (If the standard
ends up being published in 2018 and being known as C18, option aliases
can be added. Note however that -std=iso9899:199409 corresponds to a
__STDC_VERSION__ value rather than a publication date.)
(There are a couple of DR resolutions needing implementing in GCC, but
that's independent of the new options.)
(I'd propose to add -std=c2x / -std=gnu2x / -Wc11-c2x-compat for the
next major C standard revision once there are actually C2x drafts
being issued with new features included.)
Bootstrapped with no regressions for x86_64-pc-linux-gnu.
gcc:
* doc/invoke.texi (C Dialect Options): Document -std=c17,
-std=iso9899:2017 and -std=gnu17.
* doc/standards.texi (C Language): Document C17 support.
* doc/cpp.texi (Overview): Mention -std=c17.
(Standard Predefined Macros): Document C11 and C17 values of
__STDC_VERSION__. Do not refer to C99 support as incomplete.
* doc/extend.texi (Inline): Do not list individual options for
standards newer than C99.
* dwarf2out.c (highest_c_language, gen_compile_unit_die): Handle
"GNU C17".
* config/rl78/rl78.c (rl78_option_override): Handle "GNU C17"
language name.
gcc/c-family:
* c.opt (std=c17, std=gnu17, std=iso9899:2017): New options.
* c-opts.c (set_std_c17): New function.
(c_common_init_options): Use gnu17 as default C version.
(c_common_handle_option): Handle -std=c17 and -std=gnu17.
gcc/testsuite:
* gcc.dg/c17-version-1.c, gcc.dg/c17-version-2.c: New tests.
libcpp:
* include/cpplib.h (enum c_lang): Add CLK_GNUC17 and CLK_STDC17.
* init.c (lang_defaults): Add GNUC17 and STDC17 data.
(cpp_init_builtins): Handle C17 value of __STDC_VERSION__.
From-SVN: r254216
* c-common.h (cxx_dialect): Add cxx2a as a dialect.
* opt.c: Add options for -std=c++2a and -std=gnu++2a.
* c-opts.c (set_std_cxx2a): New.
(c_common_handle_option): Set options when -std=c++2a is enabled.
(c_common_post_options): Adjust comments.
(set_std_cxx14, set_std_cxx17): Likewise.
* doc/cpp.texi (__cplusplus): Document value for -std=c++2a
or -std=gnu+2a.
* doc/invoke.texi: Document -std=c++2a and -std=gnu++2a.
* lib/target-supports.exp (check_effective_target_c++17): Return
1 also if check_effective_target_c++2a.
(check_effective_target_c++17_down): New.
(check_effective_target_c++2a_only): New.
(check_effective_target_c++2a): New.
* g++.dg/cpp2a/cplusplus.C: New.
* include/cpplib.h (c_lang): Add CXX2A and GNUCXX2A.
* init.c (lang_defaults): Add rows for CXX2A and GNUCXX2A.
(cpp_init_builtins): Set __cplusplus to 201709L for C++2a.
Co-Authored-By: Jakub Jelinek <jakub@redhat.com>
From-SVN: r252850
gcc/testsuite/ChangeLog:
PR c++/79300
* g++.dg/diagnostic/pr79300.C: New test case.
libcpp/ChangeLog:
PR c++/79300
* line-map.c (linemap_macro_loc_to_def_point): Preserve range
information for macro expansions by delaying resolving ad-hoc
locations until within the loop.
From-SVN: r250058
gcc/ChangeLog:
PR c++/79300
* diagnostic-show-locus.c (layout::layout): Use start and finish
spelling location for the start and finish of each range.
* genmatch.c (linemap_client_expand_location_to_spelling_point):
Add unused aspect param.
* input.c (expand_location_1): Add "aspect" param, and use it
to access the correct part of the location.
(expand_location): Pass LOCATION_ASPECT_CARET to new param of
expand_location_1.
(expand_location_to_spelling_point): Likewise.
(linemap_client_expand_location_to_spelling_point): Add "aspect"
param, and pass it to expand_location_1.
gcc/testsuite/ChangeLog:
PR c++/79300
* c-c++-common/Wmisleading-indentation-3.c (fn_14): Update
expected underlining within macro expansion.
* c-c++-common/pr70264.c: Likewise.
* g++.dg/plugin/diagnostic-test-expressions-1.C
(test_within_macro_1): New test.
(test_within_macro_2): Likewise.
(test_within_macro_3): Likewise.
(test_within_macro_4): Likewise.
* gcc.dg/format/diagnostic-ranges.c (test_macro_3): Update
expected underlining within macro expansion.
(test_macro_4): Likewise.
* gcc.dg/plugin/diagnostic-test-expressions-1.c
(test_within_macro_1): New test.
(test_within_macro_2): Likewise.
(test_within_macro_3): Likewise.
(test_within_macro_4): Likewise.
* gcc.dg/spellcheck-fields-2.c (test_macro): Update expected
underlining within macro expansion.
libcpp/ChangeLog:
PR c++/79300
* include/line-map.h (enum location_aspect): New enum.
(linemap_client_expand_location_to_spelling_point): Add
enum location_aspect param.
* line-map.c (rich_location::get_expanded_location): Update for
new param of linemap_client_expand_location_to_spelling_point.
(rich_location::maybe_add_fixit): Likewise.
(fixit_hint::affects_line_p): Likewise.
From-SVN: r250022
* line-map.c (location_adhoc_data_update): Perform addition in
uintptr_t type rather than char * type. Read *data using
ptrdiff_t type instead of int64_t.
(get_combined_adhoc_loc): Change offset type to ptrdiff_t from
int64_t.
From-SVN: r249446
Attempts to apply a removal or replacement fix-it hint to a source
range that covers multiple lines currently lead to nonsensical
results from the printing code in diagnostic-show-locus.c.
We were already filtering them out in edit-context.c (leading
to -fdiagnostics-generate-patch not generating any output for
the whole TU).
Reject attempts to add such fix-it hints within rich_location,
fixing the diagnostic-show-locus.c issue.
gcc/ChangeLog:
* diagnostic-show-locus.c
(selftest::test_fixit_deletion_affecting_newline): New function.
(selftest::diagnostic_show_locus_c_tests): Call it.
libcpp/ChangeLog:
* include/line-map.h (class rich_location): Document that attempts
to delete or replace a range *affecting* multiple lines will fail.
* line-map.c (rich_location::maybe_add_fixit): Implement this
restriction.
From-SVN: r249403
This patch adds a method:
rich_location::fixits_cannot_be_auto_applied
for ensuring that mutually-incompatible fix-its hints don't
lead to insane output from -fdiagnostics-generate-patch.
Fix-it hints within such rich_location instances are printed
as normal by diagnostic_show_locus, but don't affect the output
of -fdiagnostics-generate-patch.
gcc/ChangeLog:
* diagnostic.c (diagnostic_report_diagnostic): Only add fixits
to the edit_context if they can be auto-applied.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/diagnostic-test-show-locus-bw.c
(test_mutually_exclusive_suggestions): New test function.
* gcc.dg/plugin/diagnostic-test-show-locus-generate-patch.c
(test_mutually_exclusive_suggestions): New test function.
* gcc.dg/plugin/diagnostic-test-show-locus-parseable-fixits.c
(test_mutually_exclusive_suggestions): New test function.
* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
(test_show_locus): Add special-case for
"test_mutually_exclusive_suggestions".
libcpp/ChangeLog:
* include/line-map.h
(rich_location::fixits_cannot_be_auto_applied): New method.
(rich_location::fixits_can_be_auto_applied_p): New accessor.
(rich_location::m_fixits_cannot_be_auto_applied): New field.
* line-map.c (rich_location::rich_location): Initialize new field.
From-SVN: r249081
Previously fix-it hints couldn't contain newlines. This is
due to the need to print something user-readable for them
within diagnostic-show-locus, and for handling them within
edit-context for printing diffs and regenerating content.
This patch enables limited support for fix-it hints with newlines,
for suggesting adding new lines.
Such a fix-it hint must have exactly one newline character, at the
end of the content. It must be an insertion at the beginning of
a line (so that e.g. fix-its that split a pre-existing line are
still rejected).
They are printed by diagnostic-show-locus with a '+' in the
left-hand margin, like this:
test.c:42:4: note: suggest adding 'break;' here
+ break;
case 'b':
^~~~~~~~~
and the printer injects "spans" if the insertion location is not
near the primary range of the diagnostic e.g.:
test.c:4:2: note: unrecognized 'putchar'; suggest including '<stdio.h>'
test.c:1:1:
+#include <stdio.h>
test.c:4:2:
putchar (ch);
^~~~~~~
gcc/ChangeLog:
* diagnostic-show-locus.c
(layout::should_print_annotation_line_p): Make private.
(layout::print_annotation_line): Make private.
(layout::annotation_line_showed_range_p): Make private.
(layout::show_ruler): Make private.
(layout::print_source_line): Make private. Pass in line and
line_width, rather than calling location_get_source_line. Drop
returned value.
(layout::print_leading_fixits): New method.
(layout::print_any_fixits): Rename to...
(layout::print_trailing_fixits): ...this, and make private.
Don't print newline fixits.
(diagnostic_show_locus): Move logic for printing one row into...
(layout::print_line): ...this new function. Move the
location_get_source_line call and error-handling from
print_source_line to here. Call print_leading_fixits, and rename
print_any_fixits to print_trailing_fixits.
(selftest::test_fixit_insert_containing_newline): Update now that
newlines are partially supported.
(selftest::test_fixit_insert_containing_newline_2): New test.
(selftest::test_fixit_replace_containing_newline): Update comments.
(selftest::diagnostic_show_locus_c_tests): Call the new test.
* edit-context.c (class added_line): New class.
(class edited_line): Describe newline handling in comment.
(edited_line::actually_edited_p): New method.
(edited_line::print_content): Delete redundant decl.
(edited_line::m_predecessors): New field.
(edited_file::print_content): Call edited_line::print_content.
(edited_file::print_diff): Update to support newlines.
(edited_file::print_diff_hunk): Likewise.
(edited_file::print_run_of_changed_lines): New function.
(edited_file::print_diff_line): Convert to...
(print_diff_line): ...this.
(edited_file::get_effective_line_count): New function.
(edited_line::edited_line): Initialize new field m_predecessors.
(edited_line::~edited_line): Clean up m_predecessors.
(edited_line::apply_fixit): Handle newlines.
(edited_line::get_effective_line_count): New function.
(edited_line::print_content): New function.
(edited_line::print_diff_lines): New function.
(selftest::test_applying_fixits_insert_containing_newline): New
test.
(selftest::test_applying_fixits_replace_containing_newline): New
test.
(selftest::insert_line): New function.
(selftest::test_applying_fixits_multiple_lines): Add example of
inserting a line.
(selftest::edit_context_c_tests): Call the new tests.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/diagnostic-test-show-locus-bw.c
(test_fixit_insert_newline): New function.
* gcc.dg/plugin/diagnostic-test-show-locus-color.c
(test_fixit_insert_newline): New function.
* gcc.dg/plugin/diagnostic-test-show-locus-generate-patch.c
(test_fixit_insert_newline): New function.
* gcc.dg/plugin/diagnostic-test-show-locus-parseable-fixits.c
(test_fixit_insert_newline): New function.
* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
(test_show_locus): Handle test_fixit_insert_newline.
libcpp/ChangeLog:
* include/line-map.h (class rich_location): Update description of
newline handling.
(class fixit_hint): Likewise.
(fixit_hint::ends_with_newline_p): New decl.
* line-map.c (rich_location::maybe_add_fixit): Support newlines
in fix-it hints that are insertions of single lines at the start
of a line. Don't consolidate into such fix-it hints.
(fixit_hint::ends_with_newline_p): New method.
From-SVN: r247522
The original implementation of fix-it hints (r230674) had an abstract
base class "fixit_hint" and three subclasses, representing
each of insertions, replacements, and deletions.
Having multiple classes for fix-it hints was a nuisance, as it required
per-class logic everywhere that the hints were handled.
In r239632 I eliminated the deletion subclass in favor of replacement
with the empty string (two subclasses are easier than three).
This patch eliminates the class hierarchy altogether by implementing
insertion in terms of replacement, by representing replacements via
a half-open interval (so that for an insertion, start == next location,
and we're effectively replacing an empty range at the insertion point
with the new string).
This greatly simplifies the code for handling fix-it hints; for example
it allows removal of a parallel class hierarchy of line_event within
edit-context.c.
It also improves consolidation of hints: we can now consolidate
insertions at the same location, affecting a couple of tests
(selftest::test_one_liner_many_fixits and
gcc.dg/Wmissing-braces-fixits.c).
gcc/ChangeLog:
* diagnostic-show-locus.c (layout::get_expanded_location): Rewrite
to use new fixit_hint representation, using the "replace" logic.
(get_line_span_for_fixit_hint): Likewise.
(layout::print_any_fixits): Likewise.
(selftest::test_one_liner_many_fixits): Rename to...
(selftest::test_one_liner_many_fixits_1): ...this, and update
comment and expected output to reflect that the multiple fix-it
hints are now consolidated into one insertion.
(selftest::test_one_liner_many_fixits_2): New test.
(selftest::test_diagnostic_show_locus_one_liner): Update for
above.
(selftest::test_fixit_consolidation): Update for fix-it API
change.
* diagnostic.c (print_parseable_fixits): Likewise.
* edit-context.c (edited_line::m_line_events): Convert from
auto_vec <line_event *> to auto_vec <line_event>.
(class line_event): Convert from abstract base class to a concrete
class, taking over the role of replace_event.
(class insert_event): Delete.
(class replace_event): Rename to class line_event. Convert to
half-open range.
(edit_context::add_fixits): Reimplement.
(edit_context::apply_insert): Delete.
(edit_context::apply_replace): Rename to...
(edit_context::apply_fixit): ...this. Convert to half-open range.
(edited_file::apply_insert): Delete.
(edited_file::apply_replace): Rename to...
(edited_file::apply_fixit): ...this.
(edited_line::~edited_line): Drop deletion of events.
(edited_line::apply_insert): Delete.
(edited_line::apply_replace): Rename to...
(edited_line::apply_fixit): ...this. Convert to half-open range.
Update for change to type of m_line_events.
* edit-context.h (edit_context::apply_insert): Delete.
(edit_context::apply_replace): Rename to...
(edit_context::apply_fixit): ...this.
gcc/testsuite/ChangeLog:
* gcc.dg/Wmissing-braces-fixits.c: Update expected output to
reflect insertion fix-it hints at the same location now being
consolidated.
libcpp/ChangeLog:
* include/line-map.h (source_range::intersects_line_p): Delete.
(rich_location::add_fixit): Delete.
(rich_location::maybe_add_fixit): New method.
(class fixit_hint): Reimplement in terms of...
(class fixit_replace): ...this.
(class fixit_insert): Delete.
* line-map.c (linemap_position_for_loc_and_offset): Drop overzealous
linemap_assert_fails.
(source_range::intersects_line_p): Rename to...
(fixit_hint::affects_line_p): New function.
(rich_location::add_fixit_insert_before): Reimplement in terms of
maybe_add_fixit, moving validation there.
(rich_location::add_fixit_insert_after): Likewise.
(column_before_p): Delete.
(rich_location::add_fixit_replace): Reimplement in terms of
maybe_add_fixit, moving validation there. Convert closed input range
to half-open range.
(rich_location::add_fixit): Delete.
(rich_location::maybe_add_fixit): New function.
(fixit_insert::fixit_insert): Delete.
(fixit_insert::~fixit_insert): Delete.
(fixit_insert::affects_line_p): Delete.
(fixit_insert::maybe_append_replace): Delete.
(fixit_replace::fixit_replace): Rename to...
(fixit_hint::fixit_hint): ...this, rewriting as necessary.
(fixit_replace::~fixit_replace): Delete.
(fixit_replace::affects_line_p): Delete.
(fixit_replace::maybe_append_replace): Rename to...
(fixit_hint::maybe_append): ...this, rewriting as necessary.
From-SVN: r247445
PR c++/77949 identifies an ICE when the C++ frontend attempts to emit a
fix-it hint inserting a missing semicolon at column 4097 of a source file.
This column value exceeds LINE_MAP_MAX_COLUMN_NUMBER and hence isn't
representable using a location_t.
Attempting to do so leads to these problems, which this patch fixes:
(a) when encountering a column number > LINE_MAP_MAX_COLUMN_NUMBER we
create a new linemap with m_column_and_range_bits == 0, but
linemap_position_for_column doesn't check for this, and hence can emit
a bogus location_t value that's calculated relative to the previous
linemap start, but which will be decoded relative to the new linemap,
leading to very large incorrect line values.
(b) when encountering a column number that can't be represented, and
for which the linemap was pre-existing, the code would hit this assertion:
if (linemap_assert_fails (column < (1u << map->m_column_and_range_bits)))
around a bail-out condition. The patch replaces this assertion with a
simple conditional, to stop the ICE when this occurs, and fixes the
bit count (effective column bits, vs column+range bits)
(c) the C++ frontend wasn't checking for failure of
linemap_position_for_loc_and_offset when considering emitting the fix-it
hint. The patch adds a conditional, so that no fix-it hint is emitted
if the location is bogus.
gcc/cp/ChangeLog:
PR c++/77949
* parser.c (cp_parser_class_specifier_1): Only suggest inserting
a missing semicolon if we have a valid insertion location for
the fix-it hint.
gcc/ChangeLog:
PR c++/77949
* input.c (selftest::test_accessing_ordinary_linemaps): Verify
that we correctly handle column numbers greater than
LINE_MAP_MAX_COLUMN_NUMBER.
gcc/testsuite/ChangeLog:
PR c++/77949
* g++.dg/diagnostic/pr77949.C: New test case.
libcpp/ChangeLog:
PR c++/77949
* line-map.c (linemap_position_for_column): When calling
linemap_start_line, detect if a new linemap was created with
0 column bits, and bail out early if this is the case.
(linemap_position_for_loc_and_offset): Replace overzealous
linemap_assert_fails with a simple conditional; use correct
bit count.
From-SVN: r244292
PR c++/72803 describes an issue where a fix-it hint is to be emitted at
column 512 of a 511-column source line, leading to an ICE.
The root cause is a bug in linemap_line_start, when transitioning from
lines >= 512 in width to narrow lines.
The wide line in the reproducer has a line map with:
m_column_and_range_bits = 15, m_range_bits = 5
giving 10 effective bits for representing columns, so that columns <= 1023
can be represented.
When parsing the following line,
linemap_line_start (..., ..., max_column_hint=0);
is called. This leads to the "add_map" logic, due to this condition:
|| (max_column_hint <= 80 && effective_column_bits >= 10)
i.e. the new line is sufficiently narrower than the old one to
potentially use a new linemap (so as to conserve values within the
location_t space).
It then attempts to avoid allocating a new line map. Part of the logic
to determine if we really need a new line map is this condition:
SOURCE_COLUMN (map, highest) >= (1U << column_bits)
The above condition is incorrect: we need to determine if the highest
column we've handed out will fit within the proposed *effective* column
bits, but "column_bits" here is the column plus the range bits, rather
than just the column bits.
Hence in this case linemap_line_start erroneously decides that we don't
need a new line map, and updates the column bits within the existing
line map, so any location_t values we've already handed out within it
that are offset from the start by
>= (1<<new_column_and_range_bits)
effectively change meaning, leading to incorrect line&column information
when decoding them, and various "interesting" ways for the linemap
code to fail.
The fix is to use the effective column bits in the above conditional.
gcc/ChangeLog:
PR c++/72803
* input.c (selftest::test_accessing_ordinary_linemaps): Verify
that the transition from a max line width >= 1<<10 to narrower
lines works correctly.
gcc/testsuite/ChangeLog:
PR c++/72803
* g++.dg/diagnostic/pr72803.C: New test case.
libcpp/ChangeLog:
PR c++/72803
* line-map.c (linemap_line_start): When determining if the highest
column given out so far will fit into a proposed change to the
current map, use the effective number of column bits, rather than
the total number of column + range bits.
From-SVN: r244199
gcc/ChangeLog:
PR preprocessor/78680
PR preprocessor/78811
* input.c (struct selftest::lexer_test): Add field
m_implicitly_expect_EOF.
(selftest::lexer_error_sink): New class.
(selftest::lexer_error_sink::s_singleton): New global.
(selftest::lexer_test::lexer_test): Initialize new field
"m_implicitly_expect_EOF".
(selftest::lexer_test::~lexer_test): Conditionalize the
check for the EOF token on the new field.
(selftest::test_lexer_string_locations_raw_string_unterminated):
New function.
(selftest::input_c_tests): Call the new test.
libcpp/ChangeLog:
PR preprocessor/78680
PR preprocessor/78811
* lex.c (_cpp_lex_direct): Only determine the end-location of
the token and build a range for non-reserved start locations.
Do not do it for EOF tokens.
From-SVN: r243721
Fix for PR preprocessor/78680
PR preprocessor/78680 identifies a crash when attempting to issue
a -Wformat warning, where the format string includes a string token
split across multiple physical source lines via backslash-continued
lines.
The issue is that libcpp is generating bogus range information for
such tokens.
For example, in:
void fn1() {
__builtin_printf("\
%ld.\n\
2\n"); };
the range of the string token is printed as:
__builtin_printf("\
^~
whereas the range ought to be:
__builtin_printf("\
^~
%ld.\n\
~~~~~~~
2\n"); };
~~~~
The root cause is that the line notes expressing the update
of the buffer in lex.c aren't yet updated when the end-point of
the token is computed
3095 tok_range.m_finish
3096 = linemap_position_for_column (pfile->line_table,
3097 CPP_BUF_COLUMN (buffer, buffer->cur));
so that the physical line is still regarded as that of the start
of the token, and, where CPP_BUF_COLUMN uses (BUF)->line_base,
line_base is still the location of the first physical line in the
and hence the column information is too large (as if it were the
offset in the *logical* line).
(the printed range is somewhat misleading; the actual buggy range
extends beyond the "\ in the line, but within diagnostic-show-locus.c
layout::print_annotation_line only prints up to the xbound set by
layout::print_source_line and so truncates most of the buggy range).
The fix is to ensure that line notes are handled before calculating
the end-point of the token range.
This leads to the range for the string token being correctly
computed, as:
__builtin_printf("\
^~
%ld.\n\
~~~~~~~
2\n"); };
~~~~
and this leads to get_substring_ranges_for_loc failing gracefully,
rather than crashing.
gcc/testsuite/ChangeLog:
PR preprocessor/78680
* gcc.dg/format/pr78680.c: New test case.
* gcc.dg/plugin/diagnostic-test-expressions-1.c
(test_multiline_token): New function.
* gcc.dg/plugin/diagnostic-test-string-literals-1.c
(test_backslash_continued_logical_lines): New function.
libcpp/ChangeLog:
PR preprocessor/78680
* lex.c (_cpp_lex_direct): Ensure line notes are processed before
computing the end-point of the token.
From-SVN: r243567
gcc:
2016-11-23 Paolo Bonzini <bonzini@gnu.org>
* system.h (HAVE_DESIGNATED_INITIALIZERS,
HAVE_DESIGNATED_UNION_INITIALIZERS): Do not use
"defined" in macros.
* doc/cpp.texi (Defined): Mention -Wexpansion-to-defined.
* doc/cppopts.texi (Invocation): Document -Wexpansion-to-defined.
* doc/invoke.texi (Warning Options): Document -Wexpansion-to-defined.
gcc/c-family:
2016-11-23 Paolo Bonzini <bonzini@gnu.org>
* c.opt (Wexpansion-to-defined): New.
gcc/testsuite:
2016-11-23 Paolo Bonzini <bonzini@gnu.org>
* gcc.dg/cpp/defined.c: Mark newly introduced warnings and
adjust for warning->pedwarn change.
* gcc.dg/cpp/defined-syshdr.c,
gcc.dg/cpp/defined-Wexpansion-to-defined.c,
gcc.dg/cpp/defined-Wextra-Wno-expansion-to-defined.c,
gcc.dg/cpp/defined-Wextra.c,
gcc.dg/cpp/defined-Wno-expansion-to-defined.c: New testcases.
libcpp:
2016-11-23 Paolo Bonzini <bonzini@gnu.org>
* include/cpplib.h (struct cpp_options): Add new member
warn_expansion_to_defined.
(CPP_W_EXPANSION_TO_DEFINED): New enum member.
* expr.c (parse_defined): Warn for all uses of "defined"
in macros, and tie warning to CPP_W_EXPANSION_TO_DEFINED.
Make it a pedwarning instead of a warning.
* system.h (HAVE_DESIGNATED_INITIALIZERS): Do not use
"defined" in macros.
From-SVN: r242743
Whilst investigating PR preprocessor/78324 I noticed that the
substring location code currently doesn't handle raw strings
correctly, by not skipping the 'R', opening quote, delimiter
and opening parenthesis.
For example, an attempt to underline chars 4-7 with caret at 6 of
this raw string yields this erroneous output:
__emit_string_literal_range (R"foo(0123456789)foo",
~~^~
With the patch, the correct range/caret is printed:
__emit_string_literal_range (R"foo(0123456789)foo",
~~^~
gcc/ChangeLog:
* input.c (selftest::test_lexer_string_locations_long_line): New
function.
(selftest::test_lexer_string_locations_raw_string_multiline): New
function.
(selftest::input_c_tests): Call the new functions, via
for_each_line_table_case.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/diagnostic-test-string-literals-1.c
(test_raw_string_one_liner): New function.
(test_raw_string_multiline): New function.
libcpp/ChangeLog:
* charset.c (cpp_interpret_string_1): Skip locations from
loc_reader when advancing 'p' when handling raw strings.
From-SVN: r242552
Running "make selftest-valgrind" showed various leaks of the form:
408 bytes in 24 blocks are definitely lost in loss record 572 of 679
at 0x4A0645D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x1B0D057: xmalloc (xmalloc.c:148)
by 0x1ACCAA1: append_file_to_dir(char const*, cpp_dir*) [clone .isra.3] (files.c:1567)
by 0x1ACD56F: _cpp_find_file (files.c:390)
by 0x1ACF8FB: cpp_read_main_file(cpp_reader*, char const*) (init.c:632)
by 0x1AB3D97: selftest::lexer_test::lexer_test(selftest::line_table_case const&, char const*, selftest::lexer_test_options*) (input.c:2014)
by 0x1AB792B: selftest::test_lexer_string_locations_u8(selftest::line_table_case const&) (input.c:2713)
by 0x1ABA22A: selftest::for_each_line_table_case(void (*)(selftest::line_table_case const&)) (input.c:3227)
by 0x1ABA381: selftest::input_c_tests() (input.c:3260)
by 0x1A295F1: selftest::run_tests() (selftest-run-tests.c:62)
by 0xF20DC4: toplev::run_self_tests() (toplev.c:2076)
by 0xF20FCD: toplev::main(int, char**) (toplev.c:2153)
Fix the leak by freeing the file->path in destroy_cpp_file.
However, doing so would lead to a use-after-free in input.c's file cache
since the filenames in this cache are the libcpp file->path buffers.
Hence we need to ensure that any references to the file in the input.c
cache are purged before cleaning up file->path. This is normally done
by the temp_source_file dtor. Hence we need to reorder things to that
the temp_source_file dtor runs before cleaning up the cpp_parser. The
patch does this by introducing a wrapper class around cpp_parser *, so
that the dtor can run after the dtor for temp_source_file.
gcc/ChangeLog:
* input.c (fcache::file_patch): Add comment about lifetime.
(selftest::cpp_reader_ptr): New class.
(selftest::lexer_test): Convert m_parser from cpp_reader *
to a cpp_reader_ptr, and move m_tempfile to after it.
(selftest::lexer_test::lexer_test): Update for above reordering.
(lexer_test::~lexer_test): Move cleanup of m_parser to
cpp_reader_ptr's dtor.
libcpp/ChangeLog:
* files.c (destroy_cpp_file): Free file->path.
From-SVN: r241536
line_maps instances such as the global line_table are
GC-managed, but the htab within location_adhoc_data_map.htab
is not GC-managed.
Previously this was deleted manually by a call to
location_adhoc_data_fini within toplev::main.
However, on adding a call to forcibly_ggc_collect after the
selftests, all of the htabs for the various line_tables
created during the selftests start showing up as leaks
in "make selftest-valgrind", e.g.:
13,536 (1,344 direct, 12,192 indirect) bytes in 12 blocks are definitely lost in loss record 1,065 of 1,086
at 0x4A081D4: calloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x16DB3B0: xcalloc (xmalloc.c:163)
by 0x16D8D34: htab_create_typed_alloc (hashtab.c:358)
by 0x16D8DBD: htab_create_alloc (hashtab.c:286)
by 0x16A2CCC: linemap_init(line_maps*, unsigned int) (line-map.c:353)
by 0x1685605: selftest::line_table_test::line_table_test(selftest::line_table_case const&) (input.c:1624)
by 0x167D09C: selftest::test_applying_fixits_modernize_named_init(selftest::line_table_case const&) (edit-context.c:1430)
by 0x1686827: selftest::for_each_line_table_case(void (*)(selftest::line_table_case const&)) (input.c:3227)
by 0x167F067: selftest::edit_context_c_tests() (edit-context.c:1658)
by 0x1616E67: selftest::run_tests() (selftest-run-tests.c:71)
by 0xC0DB25: toplev::run_self_tests() (toplev.c:2076)
by 0x618EB4: toplev::main(int, char**) (toplev.c:2153)
This patch removes the manual one-time cleanup in favor of
adding a destructor to class line_maps, which cleans up
the non-GC-managed htab.
Doing so improves "make selftest-valgrind" from:
==61118== LEAK SUMMARY:
==61118== definitely lost: 121,248 bytes in 1,515 blocks
==61118== indirectly lost: 974,344 bytes in 959 blocks
==61118== possibly lost: 0 bytes in 0 blocks
==61118== still reachable: 1,332,599 bytes in 3,684 blocks
==61118== suppressed: 0 bytes in 0 blocks
to:
==57182== LEAK SUMMARY:
==57182== definitely lost: 13,840 bytes in 556 blocks
==57182== indirectly lost: 0 bytes in 0 blocks
==57182== possibly lost: 0 bytes in 0 blocks
==57182== still reachable: 1,355,703 bytes in 3,684 blocks
==57182== suppressed: 0 bytes in 0 blocks
gcc/ChangeLog:
* toplev.c (toplev::main): Remove call to
location_adhoc_data_fini.
libcpp/ChangeLog:
* include/line-map.h (line_maps::~line_maps): New dtor.
(location_adhoc_data_fini): Delete decl.
* line-map.c (line_maps::~line_maps): New dtor.
(location_adhoc_data_fini): Delete.
From-SVN: r241533
* common.opt (Wimplicit-fallthrough) Turn into alias to
-Wimplicit-fallthrough=3. Remove EnabledBy.
(Wimplicit-fallthrough=): New option.
* gimplify.c (warn_implicit_fallthrough_r): Use
OPT_Wimplicit_fallthrough_ instead of OPT_Wimplicit_fallthrough.
* doc/invoke.texi (-Wimplicit-fallthrough): Document as alias
to -Wimplicit-fallthrough=3.
(-Wimplicit-fallthrough=): Document.
gcc/c-family/
* c.opt (Wextra): Add as C/C++/ObjC/ObjC++ option.
(Wimplicit-fallthrough=): Enable for these languages by -Wextra.
* c-opts.c (sanitize_cpp_opts): Initialize
cpp_opts->cpp_warn_implicit_fallthrough.
gcc/testsuite/
* c-c++-common/Wimplicit-fallthrough-25.c: New test.
* c-c++-common/Wimplicit-fallthrough-26.c: New test.
* c-c++-common/Wimplicit-fallthrough-27.c: New test.
* c-c++-common/Wimplicit-fallthrough-28.c: New test.
* c-c++-common/Wimplicit-fallthrough-29.c: New test.
* c-c++-common/Wimplicit-fallthrough-30.c: New test.
* c-c++-common/Wimplicit-fallthrough-31.c: New test.
* c-c++-common/Wimplicit-fallthrough-32.c: New test.
* c-c++-common/Wimplicit-fallthrough-33.c: New test.
libcpp/
* include/cpplib.h (struct cpp_options): Add
cpp_warn_implicit_fallthrough.
* init.c (cpp_create_reader): Initialize it to 0.
* lex.c (fallthrough_comment_p): Handle different
cpp_warn_implicit_fallthrough levels. Whitespace fixes.
From-SVN: r241013
* c-lex.c (c_lex_with_flags) <case CPP_COMMENT>: For CPP_COMMENT
token with PREV_FALLTHROUGH, skip all following CPP_PADDING and
CPP_COMMENT tokens and set add_flags to PREV_FALLTHROUGH afterwards.
* doc/invoke.texi (-Wimplicit-fallthrough): Document the accepted
FALLTHRU comment styles.
* lex.c (fallthrough_comment_p): Fix off-by-one size comparison
errors, cleanup.
(_cpp_lex_direct): Allow arbitrary comments in between
fallthrough_comment_p comment and following token.
* c-c++-common/Wimplicit-fallthrough-23.c: New test.
* c-c++-common/Wimplicit-fallthrough-24.c: New test.
From-SVN: r240884
libcpp/ChangeLog:
2016-10-04 Kelvin Nilsen <kelvin@gcc.gnu.org>
PR target/77847
* lex.c (search_line_fast): Add a FALLTHROUGH comment to correct
compiler error in the version of this function that is
conditionally compiled when GCC_VERSION >= 4005 and both
__ALTIVEC__ and __BIG_ENDIAN__ symbols are defined.
From-SVN: r240783
substring_loc::get_location currently fails for the final terminator
character in a STRING_CST from the C frontend, so that format_warning_va
falls back to using the location of the string as a whole.
This patch tweaks things [1] so that we use the final closing quote
as the location of the terminator character, as requested in
PR preprocessor/77672.
[1] specifically, cpp_interpret_string_1.
gcc/ChangeLog:
PR preprocessor/77672
* input.c (selftest::test_lexer_string_locations_simple): Update
test to expect location information of the terminator character
at the location of the final closing quote.
(selftest::test_lexer_string_locations_hex): Likewise.
(selftest::test_lexer_string_locations_oct): Likewise.
(selftest::test_lexer_string_locations_letter_escape_1): Likewise.
(selftest::test_lexer_string_locations_letter_escape_2): Likewise.
(selftest::test_lexer_string_locations_ucn4): Likewise.
(selftest::test_lexer_string_locations_ucn8): Likewise.
(selftest::test_lexer_string_locations_u8): Likewise.
(selftest::test_lexer_string_locations_utf8_source): Likewise.
(selftest::test_lexer_string_locations_concatenation_1): Likewise.
(selftest::test_lexer_string_locations_concatenation_2): Likewise.
(selftest::test_lexer_string_locations_concatenation_3): Likewise.
(selftest::test_lexer_string_locations_macro): Likewise.
(selftest::test_lexer_string_locations_long_line): Likewise.
gcc/testsuite/ChangeLog:
PR preprocessor/77672
* gcc.dg/plugin/diagnostic-test-string-literals-1.c
(test_terminator_location): New function.
libcpp/ChangeLog:
PR preprocessor/77672
* charset.c (cpp_interpret_string_1): Add a source_range for the
NUL-terminator, using the location of the trailing quote of the
final string.
From-SVN: r240434
I hope to implement newline support within fix-it hints at some point,
but currently it's not supported, and leads to misleading diagnostic
output, so for now, fail gracefully.
gcc/ChangeLog:
* diagnostic-show-locus.c
(selftest::test_fixit_insert_containing_newline): New function.
(selftest::test_fixit_replace_containing_newline): New function.
(selftest::diagnostic_show_locus_c_tests): Call the above.
libcpp/ChangeLog:
* include/line-map.h (class rich_location): Note that newlines
aren't supported in fix-it text.
* line-map.c (rich_location::add_fixit_insert_before): Reject
attempts to add fix-its containing newlines.
(rich_location::add_fixit_replace): Likewise.
From-SVN: r240169
The API for adding "insert text" fix-it hints was unclear
about exactly where the text should be inserted relative
to the given insertion point.
This patch clarifies things by renaming the pertinent methods from
richloc.add_fixit_insert
to
richloc.add_fixit_insert_before
and adding:
richloc.add_fixit_insert_after
The latter allows us to consolidate some failure-handling into
class rich_location, rather than having to have every such diagnostic
check for it.
The patch also adds a description of how fix-it hints work to the
comment for class rich_location within libcpp/include/line-map.h.
gcc/c-family/ChangeLog:
* c-common.c (warn_logical_not_parentheses): Replace
rich_location::add_fixit_insert calls with add_fixit_insert_before
and add_fixit_insert_after, eliminating the "next_loc" calculation.
gcc/c/ChangeLog:
* c-parser.c (c_parser_declaration_or_fndef): Update for renaming
of add_fixit_insert to add_fixit_insert_before.
gcc/cp/ChangeLog:
* parser.c (cp_parser_class_specifier_1): Update for renaming of
add_fixit_insert to add_fixit_insert_before.
(cp_parser_class_head): Likewise.
gcc/ChangeLog:
* diagnostic-show-locus.c (selftest::test_one_liner_fixit_insert):
Rename to...
(selftest::test_one_liner_fixit_insert_before): ...this, and update
for renaming of add_fixit_insert to add_fixit_insert_before.
(selftest::test_one_liner_fixit_insert_after): New function.
(selftest::test_one_liner_fixit_validation_adhoc_locations):
Update for renaming of add_fixit_insert to
add_fixit_insert_before.
(selftest::test_one_liner_many_fixits): Likewise.
(selftest::test_diagnostic_show_locus_one_liner): Update for
renaming, call new test function.
(selftest::test_diagnostic_show_locus_fixit_lines): Update for
renaming of add_fixit_insert to add_fixit_insert_before.
(selftest::test_fixit_consolidation): Likewise.
* diagnostic.c (selftest::test_print_parseable_fixits_insert):
Likewise.
* edit-context.c (selftest::test_applying_fixits_insert): Rename
to...
(selftest::test_applying_fixits_insert_before): ...this.
(selftest::test_applying_fixits_insert): Update for renaming of
add_fixit_insert to add_fixit_insert_before.
(selftest::test_applying_fixits_insert_after): New function.
(selftest::test_applying_fixits_insert_after_at_line_end): New
function.
(selftest::test_applying_fixits_insert_after_failure): New
function.
(selftest::test_applying_fixits_multiple): Update for renaming of
add_fixit_insert to add_fixit_insert_before.
(selftest::change_line): Likewise.
(selftest::test_applying_fixits_unreadable_file): Likewise.
(selftest::test_applying_fixits_line_out_of_range): Likewise.
(selftest::test_applying_fixits_column_validation): Likewise.
(selftest::test_applying_fixits_column_validation): Likewise.
(selftest::edit_context_c_tests): Update for renamed test
function; call new test functions.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
(test_show_locus): Replace rich_location::add_fixit_insert calls
with add_fixit_insert_before and add_fixit_insert_after.
libcpp/ChangeLog:
* include/line-map.h (class rich_location): Add description of
fix-it hints to leading comment.
(rich_location::add_fixit_insert): Rename both overloaded methods
to..
(rich_location::add_fixit_insert_before): ...this, updating their
comments.
(rich_location::add_fixit_insert_after): Two new overloaded
methods.
(rich_location::stop_supporting_fixits): New method.
* line-map.c (rich_location::add_fixit_insert): Rename both
overloaded methods to..
(rich_location::add_fixit_insert_before): ...this, updating their
comments.
(rich_location::add_fixit_insert_after): Two new methods.
(rich_location::reject_impossible_fixit): Split out
failure-handling into...
(rich_location::stop_supporting_fixits): New method.
From-SVN: r240115
The diagnostic_show_locus implementation determines the set
of line spans that need printing based on the ranges within the
rich_location (in layout::calculate_line_spans).
Currently this doesn't take into account fix-it hints, and hence
we fail to print fix-it hints that are on lines outside of
those ranges.
This patch updates the implementation to take fix-it hints into
account when calculating the pertinent line spans, so that such fix-it
hints do get printed. It also adds some validation, to ensure that
we don't attempt to print fix-its hints affecting a different source
file.
gcc/ChangeLog:
* diagnostic-show-locus.c (class layout): Add field m_fixit_hints.
(layout_range::intersects_line_p): New method.
(test_range_contains_point_for_single_point): Rename to...
(test_layout_range_for_single_point): ...this, and add testing
for layout_range::intersects_line_p.
(test_range_contains_point_for_single_line): Rename to...
(test_layout_range_for_single_line): ...this, and add testing
for layout_range::intersects_line_p.
(test_range_contains_point_for_multiple_lines): Rename to...
(test_layout_range_for_multiple_lines): ...this, and add testing
for layout_range::intersects_line_p.
(layout::layout): Populate m_fixit_hints.
(layout::get_expanded_location): Handle the case of a line-span
for a fix-it hint.
(layout::validate_fixit_hint_p): New method.
(get_line_span_for_fixit_hint): New function.
(layout::calculate_line_spans): Add spans for fixit-hints.
(layout::should_print_annotation_line_p): New method.
(layout::print_any_fixits): Drop param "richloc", instead using
validated fixits in m_fixit_hints. Add "const" to hint pointers.
(diagnostic_show_locus): Avoid printing blank annotation lines.
(selftest::test_diagnostic_context::test_diagnostic_context):
Initialize show_column and start_span.
(selftest::test_diagnostic_context::start_span_cb): New static
function.
(selftest::test_diagnostic_show_locus_fixit_lines): New function.
(selftest::diagnostic_show_locus_c_tests): Update for function
renamings. Call test_diagnostic_show_locus_fixit_lines.
libcpp/ChangeLog:
* include/line-map.h (class fixit_remove): Remove stray decl.
(fixit_hint::affects_line_p): Make const.
(fixit_insert::affects_line_p): Likewise.
(fixit_replace::affects_line_p): Likewise.
* line-map.c (fixit_insert::affects_line_p): Likewise.
(fixit_replace::affects_line_p): Likewise.
From-SVN: r239906
This patch eliminates the hard-coded limits within rich_location
(up to 3 ranges, up to 2 fixits). The common case is still
handled by embedding the values inside rich_location - it only
uses dynamic allocation if these limits are exceeded, so
creation of rich_location instances on the stack should still
be fast. This is implemented via a new container class,
semi_embedded_vec <T, N>.
gcc/ChangeLog:
* diagnostic-show-locus.c (colorizer::begin_state): Support more
than 3 ranges per diagnostic by alternating between color 1 and
color 2.
(layout::layout): Replace use of rich_location::MAX_RANGES
with richloc->get_num_locations ().
(layout::calculate_line_spans): Replace use of
rich_location::MAX_RANGES with m_layout_ranges.length ().
(layout::print_annotation_line): Handle arbitrary numbers of
ranges in caret-printing by defaulting to '^'.
(selftest::test_one_liner_many_fixits): New function.
(test_diagnostic_show_locus_one_liner): Call it.
* diagnostic.c (diagnostic_initialize): Update for renaming
of rich_location::MAX_RANGES to
rich_location::STATICALLY_ALLOCATED_RANGES.
* diagnostic.h (struct diagnostic_context): Likewise.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/diagnostic-test-show-locus-bw.c
(test_many_nested_locations): New function.
* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
(test_show_locus): Handle "test_many_nested_locations".
libcpp/ChangeLog:
* include/line-map.h (class semi_embedded_vec): New class.
(semi_embedded_vec<T, NUM_EMBEDDED>::semi_embedded_vec): New ctor.
(semi_embedded_vec<T, NUM_EMBEDDED>::~semi_embedded_vec): New
dtor.
(semi_embedded_vec<T, NUM_EMBEDDED>::operator[]): New methods.
(semi_embedded_vec<T, NUM_EMBEDDED>::push): New method.
(semi_embedded_vec<T, NUM_EMBEDDED>::truncate): New method.
(rich_location::get_num_locations): Reimplement in terms of
m_ranges.
(rich_location::get_range): Make non-inline.
(rich_location::get_num_fixit_hints): Reimplement in terms of
m_fixit_hints.
(rich_location::add_fixit): New function.
(rich_location::MAX_RANGES): Rename to...
(rich_location::STATICALLY_ALLOCATED_RANGES): ...this.
(rich_location::MAX_FIXIT_HINTS): Rename to...
(rich_location::STATICALLY_ALLOCATED_RANGES): ...this, and make
private.
(rich_location::m_num_ranges): Eliminate in favor of...
(rich_location::m_ranges): ...this, converting from a fixed-size
array to a semi_embedded_vec.
(rich_location::m_num_fixit_hints): Eliminate in favor of...
(rich_location::m_fixit_hints): ...this, converting from a
fixed-size array to a semi_embedded_vec.
* line-map.c (rich_location::rich_location): Update for above
changes.
(rich_location::~rich_location): Likewise.
(rich_location::get_loc): Likewise.
(rich_location::get_range): New methods.
(rich_location::add_range): Update for above changes.
(rich_location::set_range): Likewise.
(rich_location::add_fixit_insert): Likewise.
(rich_location::add_fixit_replace): Likewise.
(rich_location::get_last_fixit_hint): Likewise.
(rich_location::reject_impossible_fixit): Likewise.
(rich_location::add_fixit): New method.
From-SVN: r239879
Adding a fix-it hint to a diagnostic usually follows one of these
patterns:
(a) an insertion fix-its, with the insertion at the primary caret location
(b) a removals/replacements, affecting the range of the primary location
(other cases are possible, e.g. multiple fix-its, and affecting other
locations, but these are the common ones)
Given these common cases, this patch adds overloads of the rich_location
methods for adding fix-it hints, so that the location information can
be omitted if it matches that of the primary location within the
rich_location.
Similarly when adding "remove" and "replace" fix-it hints to a diagnostic,
it's tedious to have to extract the source_range from a location_t
(aka source_location). To make this more convenient, this patch
adds overload of the rich_location::add_fixit_remove/replace methods,
accepting a source_location directly.
The patch updates the various in-tree users of fix-it hints to use
the new simpler API where appropriate. I didn't touch the case where
there are multiple fix-its in one rich_location, as it seems better to
be more explicit about locations for this case (adding a pair of parens
in warn_logical_not_parentheses).
The above makes the gcc_rich_location::add_fixit_misspelled_id overload
taking a const char * rather redundant, so I eliminated it.
gcc/c/ChangeLog:
* c-decl.c (implicit_decl_warning): Use add_fixit_replace
rather than add_fixit_misspelled_id.
(undeclared_variable): Likewise.
* c-parser.c (c_parser_declaration_or_fndef): Likewise. Remove
now-redundant "here" params from add_fixit_insert method calls.
(c_parser_parameter_declaration): Likewise.
* c-typeck.c (build_component_ref): Remove now-redundant range
param from add_fixit_replace method calls.
gcc/cp/ChangeLog:
* name-lookup.c (suggest_alternatives_for): Use add_fixit_replace
rather than add_fixit_misspelled_id.
* parser.c (cp_parser_diagnose_invalid_type_name): Likewise.
gcc/ChangeLog:
* diagnostic-show-locus.c (test_one_liner_fixit_insert): Remove
redundant location param.
(test_one_liner_fixit_remove): Likewise.
(test_one_liner_fixit_replace): Likewise.
(test_one_liner_fixit_replace_equal_secondary_range): Likewise.
* gcc-rich-location.c
(gcc_rich_location::add_fixit_misspelled_id): Eliminate call to
get_range_from_loc. Drop overload taking a const char *.
* gcc-rich-location.h
(gcc_rich_location::add_fixit_misspelled_id): Drop overload taking
a const char *.
libcpp/ChangeLog:
* include/line-map.h (rich_location::add_fixit_insert): Add
comments. Add overload omitting the source_location param.
(rich_location::add_fixit_remove): Add comments. Add overloads
omitting the range, and accepting a source_location.
(rich_location::add_fixit_replace): Likewise.
* line-map.c (rich_location::add_fixit_insert): Add comments. Add
overload omitting the source_location param.
(rich_location::add_fixit_remove): Add comments. Add overloads
omitting the range, and accepting a source_location.
(rich_location::add_fixit_replace): Likewise.
From-SVN: r239861
Currently the fix-it validator rejects ad-hoc locations.
Fix this by calling get_pure_location on the input locations to
add_fixit_insert/replace. Doing so requires moving get_pure_location
from gcc to libcpp.
gcc/ChangeLog:
* diagnostic-show-locus.c
(selftest::test_one_liner_fixit_validation_adhoc_locations): New
function.
(selftest::test_diagnostic_show_locus_one_liner): Call it.
* input.c (get_pure_location): Move to libcpp/line-map.c.
* input.h (get_pure_location): Convert decl to an inline function
calling implementation in libcpp.
libcpp/ChangeLog:
* include/line-map.h (get_pure_location): New decl.
* line-map.c (get_pure_location): Move here, from gcc/input.c, adding
a line_maps * param.
(rich_location::add_fixit_insert): Call get_pure_location on "where".
(rich_location::add_fixit_replace): Call get_pure_location on the
end-points.
From-SVN: r239843
The first aspect of this patch is to add some checking of fix-it hints.
The idea is to put this checking within the rich_location machinery,
rather than requiring every diagnostic to implement it for itself.
The fixits within a rich_location are "atomic": all must be valid for
any to be applicable.
We reject any fixits involving locations above
LINE_MAP_MAX_LOCATION_WITH_COLS.
There's no guarantee that it's sane to modify a macro, so we reject
any fix-its that touch them.
For example, note the attempt to provide a fix-it for the definition
of the macro FIELD:
spellcheck-fields-2.c: In function ‘test_macro’:
spellcheck-fields-2.c:26:15: error: ‘union u’ has no member named ‘colour’; did you mean ‘color’?
#define FIELD colour
^
color
spellcheck-fields-2.c:27:15: note: in expansion of macro ‘FIELD’
return ptr->FIELD;
^~~~~
After this patch, the fixit is not displayed:
spellcheck-fields-2.c: In function ‘test_macro’:
spellcheck-fields-2.c:26:15: error: ‘union u’ has no member named ‘colour’; did you mean ‘color’?
#define FIELD colour
^
spellcheck-fields-2.c:27:15: note: in expansion of macro ‘FIELD’
return ptr->FIELD;
^~~~~
We might want some way for a diagnostic to opt-in to fix-its that
affect macros, but for now it's simplest to reject them.
The other aspect of this patch is fix-it consolidation: in some cases
neighboring fix-its can be merged. For example, in a diagnostic to
modernize old-style struct initializers from:
struct s example = {
- foo: 1,
+ .foo = 1,
};
one approach would be to replace the "foo" with ".foo" and the ":"
with " =". This would give two "replace" fix-its:
foo: 1,
--- FIXIT 1
.foo
- FIXIT 2
=
This patch allows them to be consolidated into a single "replace" fix-it:
foo: 1,
----
.foo =
gcc/ChangeLog:
* diagnostic-show-locus.c
(selftest::test_fixit_consolidation): New function.
(selftest::diagnostic_show_locus_c_tests): Call it.
* gcc-rich-location.h (gcc_rich_location): Eliminate unused
constructor based on source_range.
gcc/testsuite/ChangeLog:
* gcc.dg/spellcheck-fields-2.c (test): Move
dg-begin/end-multiline-output within function body.
(test_macro): New function.
libcpp/ChangeLog:
* include/line-map.h (rich_location): Eliminate unimplemented
constructor based on source_range.
(rich_location::get_last_fixit_hint): New method.
(rich_location::reject_impossible_fixit): New method.
(rich_location): Add fields m_line_table and
m_seen_impossible_fixit.
(fixit_hint::maybe_append_replace): New pure virtual function.
(fixit_insert::maybe_append_replace): New function.
(fixit_replace::maybe_append_replace): New function.
* line-map.c (rich_location::rich_location): Initialize
m_line_table and m_seen_impossible_fixit.
(rich_location::add_fixit_insert): Call
reject_impossible_fixit and bail out if true.
(column_before_p): New function.
(rich_location::add_fixit_replace): Call reject_impossible_fixit
and bail out if true. Attempt to consolidate with neighboring
fixits.
(rich_location::get_last_fixit_hint): New method.
(rich_location::reject_impossible_fixit): New method.
(fixit_insert::maybe_append_replace): New method.
(fixit_replace::maybe_append_replace): New method.
From-SVN: r239789
This patch eliminates class fixit_remove, reimplementing
rich_location::add_fixit_remove in terms of replacement with the
empty string. Deleting the removal subclass simplifies
fixit-handling code, as we only have two concrete fixit_hint
subclasses to deal with, rather than three.
The patch also fixes some problems in diagnostic-show-locus.c for
situations where a replacement fix-it has a different range to the
range of the diagnostic, by unifying the drawing of the two kinds of
fixits. For example, this:
foo = bar.field;
^
m_field
becomes:
foo = bar.field;
^
-----
m_field
showing the range to be replaced.
gcc/ChangeLog:
* diagnostic-show-locus.c
(layout::annotation_line_showed_range_p): New method.
(layout::print_any_fixits): Remove case fixit_hint::REMOVE.
Reimplement case fixit_hint::REPLACE to cover removals, and
replacements where the range of the replacement isn't one
of the ranges in the rich_location.
(test_one_liner_fixit_replace): Likewise.
(selftest::test_one_liner_fixit_replace_non_equal_range): New
function.
(selftest::test_one_liner_fixit_replace_equal_secondary_range):
New function.
(selftest::test_diagnostic_show_locus_one_liner): Call the new
functions.
* diagnostic.c (print_parseable_fixits): Remove case
fixit_hint::REMOVE.
libcpp/ChangeLog:
* include/line-map.h (fixit_hint::kind): Delete REPLACE.
(class fixit_remove): Delete.
* line-map.c (rich_location::add_fixit_remove): Reimplement
by calling add_fixit_replace with an empty string.
(fixit_remove::fixit_remove): Delete.
(fixit_remove::affects_line_p): Delete.
From-SVN: r239632
ISO/IEC TS 18661-3:2015 defines C bindings to IEEE interchange and
extended types, in the form of _FloatN and _FloatNx type names with
corresponding fN/FN and fNx/FNx constant suffixes and FLTN_* / FLTNX_*
<float.h> macros. This patch implements support for this feature in
GCC.
The _FloatN types, for N = 16, 32, 64 or >= 128 and a multiple of 32,
are types encoded according to the corresponding IEEE interchange
format (endianness unspecified; may use either the NaN conventions
recommended in IEEE 754-2008, or the MIPS NaN conventions, since the
choice of convention is only an IEEE recommendation, not a
requirement). The _FloatNx types, for N = 32, 64 and 128, are IEEE
"extended" types: types extending a narrower format with range and
precision at least as big as those specified in IEEE 754 for each
extended type (and with unspecified representation, but still
following IEEE semantics for their values and operations - and with
the set of values being determined by the precision and the maximum
exponent, which means that while Intel "extended" is suitable for
_Float64x, m68k "extended" is not). These types are always distinct
from and not compatible with each other and the standard floating
types float, double, long double; thus, double, _Float64 and _Float32x
may all have the same ABI, but they are three still distinct types.
The type names may be used with _Complex to construct corresponding
complex types (unlike __float128, which acts more like a typedef name
than a keyword - thus, this patch may be considered to fix PR
c/32187). The new suffixes can be combined with GNU "i" and "j"
suffixes for constants of complex types (e.g. 1.0if128, 2.0f64i).
The set of types supported is implementation-defined. In this GCC
patch, _Float32 is SFmode if that is suitable; _Float32x and _Float64
are DFmode if that is suitable; _Float128 is TFmode if that is
suitable; _Float64x is XFmode if that is suitable, and otherwise
TFmode if that is suitable. There is a target hook to override the
choices if necessary. "Suitable" means both conforming to the
requirements of that type, and supported as a scalar type including in
libgcc. The ABI is whatever the back end does for scalars of that
mode (but note that _Float32 is passed without promotion in variable
arguments, unlike float). All the existing issues with exceptions and
rounding modes for existing types apply equally to the new type names.
No GCC port supports a floating-point format suitable for _Float128x.
Although there is HFmode support for ARM and AArch64, use of that for
_Float16 is not enabled. Supporting _Float16 would require additional
work on the excess precision aspects of TS 18661-3: there are new
values of FLT_EVAL_METHOD, which are not currently supported in GCC,
and FLT_EVAL_METHOD == 0 now means that operations and constants on
types narrower than float are evaluated to the range and precision of
float. Implementing that, so that _Float16 gets evaluated with excess
range and precision, would involve changes to the excess precision
infrastructure so that the _Float16 case is enabled by default, unlike
the x87 case which is only enabled for -fexcess-precision=standard.
Other differences between _Float16 and __fp16 would also need to be
disentangled.
GCC has some prior support for nonstandard floating-point types in the
form of __float80 and __float128. Where these were previously types
distinct from long double, they are made by this patch into aliases
for _Float64x / _Float128 if those types have the required properties.
In principle the set of possible _FloatN types is infinite. This
patch hardcodes the four such types for N <= 128, but with as much
code as possible using loops over types to minimize the number of
places with such hardcoding. I don't think it's likely any further
such types will be of use in future (or indeed that formats suitable
for _Float128x will actually be implemented). There is a corner case
that all _FloatN, for N >= 128 and a multiple of 32, should be treated
as keywords even when the corresponding type is not supported; I
intend to deal with that in a followup patch.
Tests are added for various functionality of the new types, mostly
using type-generic headers. The tests use dg-add-options to pass any
extra options needed to enable the types; this is wired up to use the
same options as for __float128 on powerpc to enable _Float128 and
_Float64x, and effective-target keywords for runtime support do the
same hardware test as for __float128 to make sure the VSX instructions
generated by those options are supported. (Corresponding additions
would be needed for _Float16 on ARM as well if that were enabled with
-mfp16-format=ieee required to use it rather than unconditionally
available. Of course, -mfp16-format=alternative enables use of a
format which is not compatible with the requirements of the _Float16
type.)
C++ note: no support for the new types or constant suffixes is added
for C++. C++ decimal floating-point support was very different from
the C support, using class types, and the same may well apply to any
future C++ bindings for IEEE interchange and extended types. There is
a case, however, for supporting at least *f128 constants in C++, so
that code using __float128 can use the newer style for constants
throughout rather than needing to use the older *q constants in C++.
Also, if built-in functions are added that may provide a way in which
the types could leak into C++ code.
Fortran note: the float128_type_node used in the Fortran front end is
renamed to gfc_float128_type_node, since the semantics are different:
in particular, if long double has binary128 format, then the new
language-independent float128_type_node is a distinct type that also
has binary128 format, but the Fortran node is expected to be NULL in
that case. Likewise, Fortran's complex_float128_type_node is renamed
to gfc_complex_float128_type_node.
PowerPC note: the back end had an inconsistency that if TFmode was
binary128, *q constants were TFmode instead of KFmode but __float128
was KFmode. This patch follows the same logic as for *q constants, so
that _Float128 prefers TFmode (and __float128 becomes an alias for
_Float128).
ARM note: __fp16 is promoted to double (by convert_arguments) when
passed without a prototype / in variable arguments. But this is only
about the argument promotion; it is not handled as promoting in
c-common.c:self_promoting_args_p / c-typeck.c:c_type_promotes_to,
meaning that a K&R function definition for an argument of type __fp16
corresponds to a prototype with an argument of that type, not to one
with an argument of type double, whereas a float argument in a K&R
function definition corresponds to a double prototype argument - and
the same functions are also what's involved in making va_arg give a
warning and generate a call to abort when called with type float.
This is preserved by this patch, while arranging for _Float16 not to
be promoted when passed without a prototype / in variable arguments
(the promotion of float being considered a legacy feature, not applied
to any new types in C99 or later).
TS 18661-3 extends the set of decimal floating-point types similarly,
and adds new constant suffixes for the existing types, but this patch
does not do anything regarding that extension.
This patch does nothing regarding built-in functions, although
type-generic functions such as __builtin_isinf work for the new types
and associated tests are included. There are at least two levels of
built-in function support possible for these types. The minimal
level, implemented in
<https://gcc.gnu.org/ml/gcc-patches/2016-06/msg01702.html> (which
needs updating to use dg-add-options), adds built-in functions similar
to those x86 has for __float128: __builtin_inf* __builtin_huge_val*,
__builtin_nan*, __builtin_nans*, __builtin_fabs*, __builtin_copysign*.
That would be sufficient for glibc to use the *f128 names for built-in
functions by default with *q used only for backwards compatibility
when using older GCC versions. That would also allow c_cpp_builtins's
flag_building_libgcc code, defining __LIBGCC_%s_FUNC_EXT__, to use
such suffixes rather than the present code hardcoding logic about
target-specific constant suffixes and how those relate to function
suffixes.
Full built-in function support would cover the full range of built-in
functions for existing floating-point types, adding variants for all
the new types, except for a few obsolescent functions and
non-type-generic variants of type-generic functions. Some but not all
references to such functions in GCC use macros such as CASE_FLT_FN to
be type-generic; a fair amount of work would be needed to identify all
places to update. Adding all those functions would enable
optimizations (for constant arguments and otherwise) for TS 18661-3
functions, but it would also substantially expand the enum listing
built-in functions (and we've had problems with the size of that enum
in the past), and increase the amount of built-in function
initialization to do - I don't know what the startup cost involved in
built-in function initialization is, but it would be something to
consider when adding such a large set of functions.
There are also a range of optimizations, in match.pd and elsewhere,
that only operate on the three standard floating-point types. Ideally
those would be made generic to all floating-point types, but this
patch does nothing in that regard. Special care would be needed
regarding making sure library functions to which calls are generated
actually exist. For example, if sqrt is called on an argument of type
_Float32, and the result converted to _Float32, this is equivalent to
doing a square root operation directly on _Float32. But if the user's
libm does not have the sqrtf32 function, or the name is not reserved
because __STDC_WANT_IEC_60559_TYPES_EXT__ was not defined before
including <math.h>, you can only do that optimization if you convert
to a call to sqrtf instead.
DECIMAL_DIG now relates to all supported floating-point formats, not
just float, double and long double; I've raised the question with WG14
of how this relates to the formula for DECIMAL_DIG in C11 not
considering this. TS 18661-3 says it also covers non-arithmetic
formats only supported by library conversion functions; this patch
does not add any target hooks to allow for the case where there are
such formats wider than any supported for arithmetic types (where
e.g. libc supports conversions involving the binary128 representation,
but the _Float128 type is not supported).
GCC provides its own <tgmath.h> for some targets. No attempt is made
to adapt this to handle the new types.
Nothing is done regarding debug info for the new types (see the
"Debugger support for __float128 type?" thread on gcc@, Sep/Oct 2015).
No __SIZEOF_*__ macros are added for the new types.
Nothing is done with do_warn_double_promotion.
Nothing is done to include the new types in those determining
max_align_t, although properly it should be sufficiently aligned for
any of those types.
The logic for usual arithmetic conversions in c_common_type relies on
TYPE_PRECISION for floating-point types, which is less than ideal
(doesn't necessarily correspond to whether one type's values are
subset of another); looking in more detail at the formats might be
better. But since I included code in build_common_tree_nodes to work
around rs6000 KFmode having precision 113 not 128, I think it should
work. Ideally one might have errors in generic code for the case
where the two types do not have one type's values a subset of the
other (which is undefined behavior). But the only case where this can
actually occur is mixing IBM long double with binary128 on powerpc,
and rs6000_invalid_binary_op deals with that at present. TS 18661-3
does not fully specify the type resulting from the usual arithmetic
conversions in the case where two _FloatNx types have the same set of
values; I arranged the code to prefer the greater value of N in that
case.
The __FP_FAST_FMA* macros are not extended to cover the new types,
since there are no corresponding built-in functions (if built-in
fmafN, fmafNx are added, the macros should be extended, and the new
macros documented). Also, only a limited set of modes is handled in
mode_has_fma.
Diagnostics relating to the use of the new types with -pedantic do not
try to distinguish them from purely nonstandard types such as __int128
and constant suffixes such as *q.
If you use an unsupported _FloatN / _FloatNx type you get a warning
about the type defaulting to int after the warning about the type not
being supported. That's less than ideal, but it's also a pre-existing
condition if you use __int128 on a 32-bit system where it's
unsupported.
Bootstrapped with no regressions on x86_64-pc-linux-gnu. Other
back-end changes minimally tested by building cc1 for ia64-linux-gnu,
powerpc64le-linux-gnu, pdp11-none (the last failed for unrelated
reasons).
PR c/32187
gcc:
* tree-core.h (TI_COMPLEX_FLOAT16_TYPE)
(TI_COMPLEX_FLOATN_NX_TYPE_FIRST, TI_COMPLEX_FLOAT32_TYPE)
(TI_COMPLEX_FLOAT64_TYPE, TI_COMPLEX_FLOAT128_TYPE)
(TI_COMPLEX_FLOAT32X_TYPE, TI_COMPLEX_FLOAT64X_TYPE)
(TI_COMPLEX_FLOAT128X_TYPE, TI_FLOAT16_TYPE, TI_FLOATN_TYPE_FIRST)
(TI_FLOATN_NX_TYPE_FIRST, TI_FLOAT32_TYPE, TI_FLOAT64_TYPE)
(TI_FLOAT128_TYPE, TI_FLOATN_TYPE_LAST, TI_FLOAT32X_TYPE)
(TI_FLOATNX_TYPE_FIRST, TI_FLOAT64X_TYPE, TI_FLOAT128X_TYPE)
(TI_FLOATNX_TYPE_LAST, TI_FLOATN_NX_TYPE_LAST): New enum
tree_index values.
(NUM_FLOATN_TYPES, NUM_FLOATNX_TYPES, NUM_FLOATN_NX_TYPES): New
macros.
(struct floatn_type_info): New structure type.
(floatn_nx_types): New variable declaration.
* tree.h (FLOATN_TYPE_NODE, FLOATN_NX_TYPE_NODE)
(FLOATNX_TYPE_NODE, float128_type_node, float64x_type_node)
(COMPLEX_FLOATN_NX_TYPE_NODE): New macros.
* tree.c (floatn_nx_types): New variable.
(build_common_tree_nodes): Initialize _FloatN, _FloatNx and
corresponding complex types.
* target.def (floatn_mode): New hook.
* targhooks.c: Include "real.h".
(default_floatn_mode): New function.
* targhooks.h (default_floatn_mode): New prototype.
* doc/extend.texi (Floating Types): Document _FloatN and _FloatNx
types.
* doc/sourcebuild.texi (float@var{n}, float@var{n}x): Document new
effective-target and dg-add-options keywords.
(float@var{n}_runtime, float@var{n}x_runtime, floatn_nx_runtime):
Document new effective-target keywords.
* doc/tm.texi.in (TARGET_FLOATN_MODE): New @hook.
* doc/tm.texi: Regenerate.
* ginclude/float.h (LDBL_DECIMAL_DIG): Define to
__LDBL_DECIMAL_DIG__, not __DECIMAL_DIG__.
[__STDC_WANT_IEC_60559_TYPES_EXT__]: Define macros from TS
18661-3.
* real.h (struct real_format): Add field ieee_bits.
* real.c (ieee_single_format, mips_single_format)
(motorola_single_format, spu_single_format, ieee_double_format)
(mips_double_format, motorola_double_format)
(ieee_extended_motorola_format, ieee_extended_intel_96_format)
(ieee_extended_intel_128_format)
(ieee_extended_intel_96_round_53_format, ibm_extended_format)
(mips_extended_format, ieee_quad_format, mips_quad_format)
(vax_f_format, vax_d_format, vax_g_format, decimal_single_format)
(decimal_double_format, decimal_quad_format, ieee_half_format)
(arm_half_format, real_internal_format: Initialize ieee_bits
field.
* config/i386/i386.c (ix86_init_builtin_types): Do not initialize
float128_type_node. Set float80_type_node to float64x_type_node
if appropriate and long_double_type_node not appropriate.
* config/ia64/ia64.c (ia64_init_builtins): Likewise.
* config/pdp11/pdp11.c (pdp11_f_format, pdp11_d_format):
Initialize ieee_bits field.
* config/rs6000/rs6000.c (TARGET_FLOATN_MODE): New macro.
(rs6000_init_builtins): Set ieee128_float_type_node to
float128_type_node.
(rs6000_floatn_mode): New function.
gcc/c:
* c-tree.h (cts_floatn_nx): New enum c_typespec_keyword value.
(struct c_declspecs): Add field floatn_nx_idx.
* c-decl.c (declspecs_add_type, finish_declspecs): Handle _FloatN
and _FloatNx type specifiers.
* c-parser.c (c_keyword_starts_typename, c_token_starts_declspecs)
(c_parser_declspecs, c_parser_attribute_any_word)
(c_parser_objc_selector): Use CASE_RID_FLOATN_NX.
* c-typeck.c (c_common_type): Handle _FloatN and _FloatNx types.
(convert_arguments): Avoid promoting _FloatN and _FloatNx types
narrower than double.
gcc/c-family:
* c-common.h (RID_FLOAT16, RID_FLOATN_NX_FIRST, RID_FLOAT32)
(RID_FLOAT64, RID_FLOAT128, RID_FLOAT32X, RID_FLOAT64X)
(RID_FLOAT128X): New enum rid values.
(CASE_RID_FLOATN_NX): New macro.
* c-common.c (c_common_reswords): Add _FloatN and _FloatNx
keywords.
(c_common_type_for_mode): Check for _FloatN and _FloatNx and
corresponding complex types.
(c_common_nodes_and_builtins): For non-C++, register _FloatN and
_FloatNx and corresponding complex types.
(keyword_begins_type_specifier): Use CASE_RID_FLOATN_NX.
* c-cppbuiltin.c (builtin_define_float_constants): Check _FloatN
and _FloatNx types for the widest type for determining
DECIMAL_DIG. Define __LDBL_DECIMAL_DIG__ as well as
__DECIMAL_DIG__ for long double. Handle FMA_SUFFIX being NULL.
(c_cpp_builtins): Call builtin_define_float_constants for _FloatN
and _FloatNx types.
* c-lex.c (interpret_float): Handle _FloatN and _FloatNx
constants.
* c-pretty-print.c (pp_c_floating_constant): Handle _FloatN and
_FloatNx types.
gcc/fortran:
* trans-types.h (float128_type_node): Rename to
gfc_float128_type_node.
(complex_float128_type_node): Rename to
gfc_complex_float128_type_node.
* iso-c-binding.def, trans-intrinsic.c, trans-types.c: All users
changed.
gcc/testsuite:
* lib/target-supports.exp (check_effective_target_float16)
(check_effective_target_float32, check_effective_target_float64)
(check_effective_target_float128, check_effective_target_float32x)
(check_effective_target_float64x)
(check_effective_target_float128x)
(check_effective_target_float16_runtime)
(check_effective_target_float32_runtime)
(check_effective_target_float64_runtime)
(check_effective_target_float128_runtime)
(check_effective_target_float32x_runtime)
(check_effective_target_float64x_runtime)
(check_effective_target_float128x_runtime)
(check_effective_target_floatn_nx_runtime)
(add_options_for_float16, add_options_for_float32)
(add_options_for_float64, add_options_for_float128)
(add_options_for_float32x, add_options_for_float64x)
(add_options_for_float128x): New procedures.
* gcc.dg/dfp/floatn.c, gcc.dg/float128-typeof.c,
gcc.dg/float128x-typeof.c, gcc.dg/float16-typeof.c,
gcc.dg/float32-typeof.c, gcc.dg/float32x-typeof.c,
gcc.dg/float64-typeof.c, gcc.dg/float64x-typeof.c,
gcc.dg/floatn-arithconv.c, gcc.dg/floatn-errs.c,
gcc.dg/floatn-typeof.h, gcc.dg/torture/float128-basic.c,
gcc.dg/torture/float128-complex.c,
gcc.dg/torture/float128-floath.c, gcc.dg/torture/float128-tg.c,
gcc.dg/torture/float128x-basic.c,
gcc.dg/torture/float128x-complex.c,
gcc.dg/torture/float128x-floath.c, gcc.dg/torture/float128x-tg.c,
gcc.dg/torture/float16-basic.c, gcc.dg/torture/float16-complex.c,
gcc.dg/torture/float16-floath.c, gcc.dg/torture/float16-tg.c,
gcc.dg/torture/float32-basic.c, gcc.dg/torture/float32-complex.c,
gcc.dg/torture/float32-floath.c, gcc.dg/torture/float32-tg.c,
gcc.dg/torture/float32x-basic.c,
gcc.dg/torture/float32x-complex.c,
gcc.dg/torture/float32x-floath.c, gcc.dg/torture/float32x-tg.c,
gcc.dg/torture/float64-basic.c, gcc.dg/torture/float64-complex.c,
gcc.dg/torture/float64-floath.c, gcc.dg/torture/float64-tg.c,
gcc.dg/torture/float64x-basic.c,
gcc.dg/torture/float64x-complex.c,
gcc.dg/torture/float64x-floath.c, gcc.dg/torture/float64x-tg.c,
gcc.dg/torture/floatn-basic.h, gcc.dg/torture/floatn-complex.h,
gcc.dg/torture/floatn-convert.c, gcc.dg/torture/floatn-floath.h,
gcc.dg/torture/floatn-tg.h,
gcc.dg/torture/fp-int-convert-float128-ieee-timode.c,
gcc.dg/torture/fp-int-convert-float128-ieee.c,
gcc.dg/torture/fp-int-convert-float128x-timode.c,
gcc.dg/torture/fp-int-convert-float128x.c,
gcc.dg/torture/fp-int-convert-float16-timode.c,
gcc.dg/torture/fp-int-convert-float16.c,
gcc.dg/torture/fp-int-convert-float32-timode.c,
gcc.dg/torture/fp-int-convert-float32.c,
gcc.dg/torture/fp-int-convert-float32x-timode.c,
gcc.dg/torture/fp-int-convert-float32x.c,
gcc.dg/torture/fp-int-convert-float64-timode.c,
gcc.dg/torture/fp-int-convert-float64.c,
gcc.dg/torture/fp-int-convert-float64x-timode.c,
gcc.dg/torture/fp-int-convert-float64x.c: New tests.
* gcc.dg/torture/fp-int-convert.h (TEST_I_F): Add argument for
maximum exponent of floating-point type. Use it in testing
whether 0x8...0 fits in the floating-point type. Always treat -1
(signed 0xf...f) as fitting in the floating-point type.
(M_OK1): New macro.
* gcc.dg/torture/fp-int-convert-double.c,
gcc.dg/torture/fp-int-convert-float.c,
gcc.dg/torture/fp-int-convert-float128-timode.c,
gcc.dg/torture/fp-int-convert-float128.c,
gcc.dg/torture/fp-int-convert-float80-timode.c,
gcc.dg/torture/fp-int-convert-float80.c,
gcc.dg/torture/fp-int-convert-long-double.c,
gcc.dg/torture/fp-int-convert-timode.c: Update calls to TEST_I_F.
libcpp:
* include/cpplib.h (CPP_N_FLOATN, CPP_N_FLOATNX)
(CPP_N_WIDTH_FLOATN_NX, CPP_FLOATN_SHIFT, CPP_FLOATN_MAX): New
macros.
* expr.c (interpret_float_suffix): Handle fN, fNx, FN and FNx
suffixes.
From-SVN: r239625
This patch allows the preprocessor to offer suggestions for misspelled
directives, taking us from e.g.:
test.c:5:2: error: invalid preprocessing directive #endfi
#endfi
^~~~~
to:
test.c:5:2: error: invalid preprocessing directive #endfi; did you mean #endif?
#endfi
^~~~~
endif
gcc/c-family/ChangeLog:
* c-common.c: Include "spellcheck.h".
(cb_get_suggestion): New function.
* c-common.h (cb_get_suggestion): New decl.
* c-lex.c (init_c_lex): Initialize cb->get_suggestion to
cb_get_suggestion.
gcc/testsuite/ChangeLog:
* gcc.dg/cpp/misspelled-directive-1.c: New testcase.
* gcc.dg/cpp/misspelled-directive-2.c: New testcase.
libcpp/ChangeLog:
* directives.c (directive_names): New array.
(_cpp_handle_directive): Offer spelling suggestions for misspelled
directives.
* errors.c (cpp_diagnostic_at_richloc): New function.
(cpp_error_at_richloc): New function.
* include/cpplib.h (struct cpp_callbacks): Add field
"get_suggestion".
(cpp_error_at_richloc): New decl.
From-SVN: r239585
libcpp/ChangeLog:
PR bootstrap/72823
* charset.c (_cpp_valid_ucn): Replace overzealous assert with one
that allows for char_range to be non-NULL when loc_reader is NULL.
From-SVN: r239211
gcc/c-family/ChangeLog:
* c-common.c: Include "substring-locations.h".
(get_cpp_ttype_from_string_type): New function.
(g_string_concat_db): New global.
(substring_loc::get_range): New method.
* c-common.h (g_string_concat_db): New declaration.
(class substring_loc): New class.
* c-lex.c (lex_string): When concatenating strings, capture the
locations of all tokens using a new obstack, and record the
concatenation locations within g_string_concat_db.
* c-opts.c (c_common_init_options): Construct g_string_concat_db
on the ggc-heap.
gcc/ChangeLog:
* input.c (string_concat::string_concat): New constructor.
(string_concat_db::string_concat_db): New constructor.
(string_concat_db::record_string_concatenation): New method.
(string_concat_db::get_string_concatenation): New method.
(string_concat_db::get_key_loc): New method.
(class auto_cpp_string_vec): New class.
(get_substring_ranges_for_loc): New function.
(get_source_range_for_substring): New function.
(get_num_source_ranges_for_substring): New function.
(class selftest::lexer_test_options): New class.
(struct selftest::lexer_test): New struct.
(class selftest::ebcdic_execution_charset): New class.
(selftest::ebcdic_execution_charset::s_singleton): New variable.
(selftest::lexer_test::lexer_test): New constructor.
(selftest::lexer_test::~lexer_test): New destructor.
(selftest::lexer_test::get_token): New method.
(selftest::assert_char_at_range): New function.
(ASSERT_CHAR_AT_RANGE): New macro.
(selftest::assert_num_substring_ranges): New function.
(ASSERT_NUM_SUBSTRING_RANGES): New macro.
(selftest::assert_has_no_substring_ranges): New function.
(ASSERT_HAS_NO_SUBSTRING_RANGES): New macro.
(selftest::test_lexer_string_locations_simple): New function.
(selftest::test_lexer_string_locations_ebcdic): New function.
(selftest::test_lexer_string_locations_hex): New function.
(selftest::test_lexer_string_locations_oct): New function.
(selftest::test_lexer_string_locations_letter_escape_1): New function.
(selftest::test_lexer_string_locations_letter_escape_2): New function.
(selftest::test_lexer_string_locations_ucn4): New function.
(selftest::test_lexer_string_locations_ucn8): New function.
(selftest::uint32_from_big_endian): New function.
(selftest::test_lexer_string_locations_wide_string): New function.
(selftest::uint16_from_big_endian): New function.
(selftest::test_lexer_string_locations_string16): New function.
(selftest::test_lexer_string_locations_string32): New function.
(selftest::test_lexer_string_locations_u8): New function.
(selftest::test_lexer_string_locations_utf8_source): New function.
(selftest::test_lexer_string_locations_concatenation_1): New
function.
(selftest::test_lexer_string_locations_concatenation_2): New
function.
(selftest::test_lexer_string_locations_concatenation_3): New
function.
(selftest::test_lexer_string_locations_macro): New function.
(selftest::test_lexer_string_locations_stringified_macro_argument):
New function.
(selftest::test_lexer_string_locations_non_string): New function.
(selftest::test_lexer_string_locations_long_line): New function.
(selftest::test_lexer_char_constants): New function.
(selftest::input_c_tests): Call the new test functions once per
case within the line_table test matrix.
* input.h (struct string_concat): New struct.
(struct location_hash): New struct.
(class string_concat_db): New class.
* substring-locations.h: New header.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/diagnostic-test-string-literals-1.c: New file.
* gcc.dg/plugin/diagnostic-test-string-literals-2.c: New file.
* gcc.dg/plugin/diagnostic_plugin_test_string_literals.c: New file.
* gcc.dg/plugin/plugin.exp (plugin_test_list): Add the above new files.
libcpp/ChangeLog:
* charset.c (cpp_substring_ranges::cpp_substring_ranges): New
constructor.
(cpp_substring_ranges::~cpp_substring_ranges): New destructor.
(cpp_substring_ranges::add_range): New method.
(cpp_substring_ranges::add_n_ranges): New method.
(_cpp_valid_ucn): Add "char_range" and "loc_reader" params; if
they are non-NULL, read position information from *loc_reader
and update char_range->m_finish accordingly.
(convert_ucn): Add "char_range", "loc_reader", and "ranges"
params. If loc_reader is non-NULL, read location information from
it, and update *ranges accordingly, using char_range.
Conditionalize the conversion into tbuf on tbuf being non-NULL.
(convert_hex): Likewise, conditionalizing the call to
emit_numeric_escape on tbuf.
(convert_oct): Likewise.
(convert_escape): Add params "loc_reader" and "ranges". If
loc_reader is non-NULL, read location information from it, and
update *ranges accordingly. Conditionalize the conversion into
tbuf on tbuf being non-NULL.
(cpp_interpret_string): Rename to...
(cpp_interpret_string_1): ...this, adding params "loc_readers" and
"out". Use "to" to conditionalize the initialization and usage of
"tbuf", such as running the converter. If "loc_readers" is
non-NULL, use the instances within it, reading location
information from them, and passing them to convert_escape; likewise
write to "out" if loc_readers is non-NULL. Check for leading
quote and issue an error if it is not present. Update boundary
check from "== limit" to ">= limit" to protect against erroneous
location values to calls that are not parsing string literals.
(cpp_interpret_string): Reimplement in terms to
cpp_interpret_string_1.
(noop_error_cb): New function.
(cpp_interpret_string_ranges): New function.
(cpp_string_location_reader::cpp_string_location_reader): New
constructor.
(cpp_string_location_reader::get_next): New method.
* include/cpplib.h (class cpp_string_location_reader): New class.
(class cpp_substring_ranges): New class.
(cpp_interpret_string_ranges): New prototype.
* internal.h (_cpp_valid_ucn): Add params "char_range" and
"loc_reader".
* lex.c (forms_identifier_p): Pass NULL for new params to
_cpp_valid_ucn.
From-SVN: r239175
For some reason I added make_location and some related functions to
tree.h/c, rather than to input.h/c. Move them there, so we can use them
without requiring tree, and add some selftest coverage.
gcc/ChangeLog:
* input.c (get_pure_location): Move here from tree.c.
(make_location): Likewise. Add header comment.
(selftest::test_accessing_ordinary_linemaps): Verify
pure_location_p, make_location, get_location_from_adhoc_loc and
get_range_from_loc.
* input.h (get_pure_location): Move declaration here from tree.h.
(get_finish): Likewise for inline function.
(make_location): Likewise for declaration.
* tree.c (get_pure_location): Move to input.c.
(make_location): Likewise.
* tree.h (get_pure_location): Move declaration to tree.h.
(get_finish): Likewise for inline function.
(make_location): Likewise for declaration.
libcpp/ChangeLog:
* include/line-map.h (source_location): Fix line numbers in
comment.
From-SVN: r238792
This patch adds explicit testing of lexing a source file,
generalizing this (and the test of ordinary line maps) over
a 2-dimensional test matrix covering:
(1) line_table->default_range_bits: some frontends use a non-zero value
and others use zero
(2) the fallback modes within line-map.c: there are various threshold
values for source_location/location_t beyond line-map.c changes
behavior (disabling of the range-packing optimization, disabling
of column-tracking). We exercise these by starting the line_table
at interesting values at or near these thresholds.
This helps ensures that location data works in all of these states,
and that (I hope) we don't have lingering bugs relating to the
transition between line_table states.
gcc/ChangeLog:
* input.c: Include cpplib.h.
(selftest::temp_source_file): New class.
(selftest::temp_source_file::temp_source_file): New ctor.
(selftest::temp_source_file::~temp_source_file): New dtor.
(selftest::should_have_column_data_p): New function.
(selftest::test_should_have_column_data_p): New function.
(selftest::temp_line_table): New class.
(selftest::temp_line_table::temp_line_table): New ctor.
(selftest::temp_line_table::~temp_line_table): New dtor.
(selftest::test_accessing_ordinary_linemaps): Add case_ param; use
it to create a temp_line_table.
(selftest::assert_loceq): Only verify LOCATION_COLUMN for
locations that are known to have column data.
(selftest::line_table_case): New struct.
(selftest::test_reading_source_line): Move tempfile handling
to class temp_source_file.
(ASSERT_TOKEN_AS_TEXT_EQ): New macro.
(selftest::assert_token_loc_eq): New function.
(ASSERT_TOKEN_LOC_EQ): New macro.
(selftest::test_lexer): New function.
(selftest::boundary_locations): New array.
(selftest::input_c_tests): Call test_should_have_column_data_p.
Loop over a test matrix of interesting values of location and
default_range_bits, calling test_lexer on each case in the matrix.
Move call to test_accessing_ordinary_linemaps into the matrix.
* selftest.h (ASSERT_EQ): Reimplement in terms of...
(ASSERT_EQ_AT): New macro.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/location_overflow_plugin.c (plugin_init): Avoid
hardcoding the values of LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES
and LINE_MAP_MAX_LOCATION_WITH_COLS.
libcpp/ChangeLog:
* include/line-map.h (LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES):
Move here from line-map.c.
(LINE_MAP_MAX_LOCATION_WITH_COLS): Likewise.
* line-map.c (LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES): Move from
here to line-map.h.
(LINE_MAP_MAX_LOCATION_WITH_COLS): Likewise.
From-SVN: r238213
This patch tweaks the error message location for missing header files.
Previously these read:
test.c:1:17: fatal error: 404.h: No such file or directory
#include "404.h"
^
compilation terminated.
With this patch, the pertinent string is underlined:
test.c:1:10: fatal error: 404.h: No such file or directory
#include "404.h"
^~~~~~~
compilation terminated.
gcc/testsuite/ChangeLog:
* c-c++-common/missing-header-1.c: New test case.
* c-c++-common/missing-header-2.c: New test case.
* c-c++-common/missing-header-3.c: New test case.
* c-c++-common/missing-header-4.c: New test case.
libcpp/ChangeLog:
* directives.c (do_include_common): Pass on "location" to
_cpp_stack_include.
* errors.c (cpp_diagnostic): Reimplement in terms of...
(cpp_diagnostic_at): New function.
(cpp_error_at): New function.
(cpp_errno_filename): Add "loc" param and use it by using
cpp_error_at rather than cpp_error.
* files.c (find_file_in_dir): Add "loc" param and pass it to
open_file_failed.
(_cpp_find_file): Add "loc" param. Use it to convert calls to
cpp_error to cpp_error_at, and pass it to find_file_in_dir and
open_file_failed.
(read_file_guts): Add "loc" param. Use it to convert calls to
cpp_error to cpp_error_at. Pass it to cpp_errno_filename.
(read_file): Add "loc" param. Pass it to open_file_failed and
read_file_guts.
(should_stack_file): Add "loc" param. Pass it to read_file.
(_cpp_stack_file): Add "loc" param. Pass it to should_stack_file.
(_cpp_stack_include): Add "loc" param. Pass it to
_cpp_find_file and _cpp_stack_file.
(open_file_failed): Add "loc" param. Pass it to
cpp_errno_filename.
(_cpp_fake_include): Add 0 as a source_location in call to
_cpp_find_file.
(_cpp_compare_file_date): Likewise.
(cpp_push_include): Likewise for call to _cpp_stack_include.
(cpp_push_default_include): Likewise.
(_cpp_save_file_entries): Likewise for call to open_file_failed.
(_cpp_has_header): Likewise for call to _cpp_find_file.
* include/cpplib.h (cpp_errno_filename): Add source_location
param.
(cpp_error_at): New declaration.
* init.c (cpp_read_main_file): Add 0 as a source_location in calls
to _cpp_find_file and _cpp_stack_file.
* internal.h (_cpp_find_file): Add source_location param.
(_cpp_stack_file): Likewise.
(_cpp_stack_include): Likewise.
From-SVN: r237715
* c-common.c (get_source_date_epoch): Use int64_t instead of long long.
* gcov-tool.c (profile_rewrite): Use int64_t instead of long long.
(do_rewrite): likewise.
* line-map.c (location_adhoc_data_update): Use int64_t instead of
long long.
(get_combined_adhoc_loc): Likewise.
From-SVN: r237676
gcc/c-family/ChangeLog:
2016-05-13 Eduard Sanou <dhole@openmailbox.org>
* c-common.c (get_source_date_epoch): Rename to
cb_get_source_date_epoch.
* c-common.c (cb_get_source_date_epoch): Use a single generic erorr
message when the parsing fails. Use error_at instead of fatal_error.
* c-common.h (get_source_date_epoch): Rename to
cb_get_source_date_epoch.
* c-common.h (cb_get_source_date_epoch): Prototype.
* c-common.h (MAX_SOURCE_DATE_EPOCH): Define.
* c-common.h (c_omp_region_type): Remove trailing comma.
* c-lex.c (init_c_lex): Set cb->get_source_date_epoch callback.
* c-lex.c (c_lex_with_flags): Remove initialization of
pfile->source_date_epoch.
gcc/ChangeLog:
2016-05-13 Eduard Sanou <dhole@openmailbox.org>
* doc/cppenv.texi: Note that the `%s` in `date` is a non-standard
extension.
* gcc.c (driver_handle_option): Call set_source_date_epoch_envvar.
* gcc.c (set_source_date_epoch_envvar): New function, sets
the SOURCE_DATE_EPOCH environment variable to the current time.
gcc/testsuite/ChangeLog:
2016-05-13 Eduard Sanou <dhole@openmailbox.org>
* gcc.dg/cpp/source_date_epoch-1.c: New file, test the proper
behaviour of the macros __DATE__ and __TIME__ when SOURCE_DATE_EPOCH
env var is set.
* gcc.dg/cpp/source_date_epoch-2.c: New file, test the error output
when parsing the SOURCE_DATE_EPOCH env var, and make sure it is only
shown once.
* lib/gcc-dg.exp (dg-set-compiler-env-var): New function, set env vars
during compilation.
* lib/gcc-dg.exp (restore-compiler-env-var): New function, restore env
vars set by dg-set-compiler-env-var.
libcpp/ChangeLog:
2016-05-13 Eduard Sanou <dhole@openmailbox.org>
* include/cpplib.h (cpp_callbacks): Add get_source_date_epoch
callback.
* include/cpplib.h (cpp_init_source_date_epoch): Remove prototype.
* init.c (cpp_init_source_date_epoch): Remove function.
* init.c (cpp_create_reader): Initialize pfile->source_date_epoch.
* internal.h (cpp_reader): Extend comment about source_date_epoch.
* macro.c (_cpp_builtin_macro_text): Use get_source_date_epoch
callback only once, read pfile->source_date_epoch on future passes.
Check that get_source_date_epoch callback is not NULL.
From-SVN: r237001
gcc/c-family/ChangeLog:
2016-04-28 Eduard Sanou <dhole@openmailbox.org>
Matthias Klose <doko@debian.org>
* c-common.c (get_source_date_epoch): New function, gets the environment
variable SOURCE_DATE_EPOCH and parses it as long long with error
handling.
* c-common.h (get_source_date_epoch): Prototype.
* c-lex.c (c_lex_with_flags): set parse_in->source_date_epoch.
gcc/ChangeLog:
2016-04-28 Eduard Sanou <dhole@openmailbox.org>
Matthias Klose <doko@debian.org>
* doc/cppenv.texi: Document SOURCE_DATE_EPOCH environment variable.
libcpp/ChangeLog:
2016-04-28 Eduard Sanou <dhole@openmailbox.org>
Matthias Klose <doko@debian.org>
* include/cpplib.h (cpp_init_source_date_epoch): Prototype.
* init.c (cpp_init_source_date_epoch): New function.
* internal.h: Added source_date_epoch variable to struct
cpp_reader to store a reproducible date.
* macro.c (_cpp_builtin_macro_text): Set pfile->date timestamp from
pfile->source_date_epoch instead of localtime if source_date_epoch is
set, to be used for __DATE__ and __TIME__ macros to help reproducible
builds.
Co-Authored-By: Matthias Klose <doko@debian.org>
From-SVN: r235550
PR preprocessor/61817
PR preprocessor/69391
* internal.h (_cpp_builtin_macro_text): Update decl.
* macro.c (_cpp_builtin_macro_text): Accept location for __LINE__.
(builtin_macro): Accept a second location for __LINE__.
(enter_macro_context): Compute both virtual and real expansion
locations for the macro.
* gcc.dg/pr61817-1.c: New test.
* gcc.dg/pr61817-2.c: New test.
* gcc.dg/pr69391-1.c: New test.
* gcc.dg/pr69391-2.c: New test.
From-SVN: r234794
PR lto/69650
* directives.c (do_linemarker): Test for file left but not entered
here.
* line-map.c (linemap_add): Not here.
PR lto/69650
* gcc.dg/pr69650.c: New test.
From-SVN: r234481
PR target/70296
* include/cpplib.h (cpp_fun_like_macro_p): New prototype.
* macro.c (cpp_fun_like_macro_p): New function.
* config/rs6000/rs6000-c.c (rs6000_macro_to_expand): If IDENT is
function-like macro, peek following token(s) if it is followed
by CPP_OPEN_PAREN token with optional padding in between, and
if not, don't treat it like a macro.
* gcc.target/powerpc/altivec-36.c: New test.
From-SVN: r234371
* libcpp/expr.c (cpp_classify_number): Hex floats are new in C++1z.
* libcpp/init.c (lang_defaults): Likewise.
* gcc/c-family/c-cppbuiltin.c (c_cpp_builtins): Set __cpp_hex_float.
From-SVN: r234213
diagnostic_show_locus can sometimes do the wrong thing when handling
expressions built up from macros.
PR c++/70105 (currently marked as a P3 regression) has an example of
a diagnostic where over 500 lines of irrelevant source are printed,
and underlined, giving >1000 lines of useless spew to stderr.
This patch adds extra sanitization to diagnostic-show-locus.c, so that
we only attempt to print underlines and secondary locations if such
locations are "sufficiently sane" relative to the primary location
of a diagnostic.
This "sufficiently sane" condition is implemented by a new helper
function compatible_locations_p, which requires such locations to
have the same macro expansion hierarchy as the primary location,
using linemap_macro_map_loc_unwind_toward_spelling, effectively
mimicing the expansion performed by LRK_SPELLING_LOCATION.
This may be too strong a condition, but it effectively fixes
PR c++/70105, without removing any underlines in my testing.
Successfully bootstrapped®rtested in combination with the previous
patch on x86_64-pc-linux-gnu; adds 15 new PASS results to g++.sum
and 4 new PASS results to gcc.sum.
gcc/ChangeLog:
PR c/68473
PR c++/70105
* diagnostic-show-locus.c (compatible_locations_p): New function.
(layout::layout): Sanitize ranges using compatible_locations_p.
gcc/testsuite/ChangeLog:
PR c/68473
PR c++/70105
* g++.dg/diagnostic/pr70105.C: New test.
* gcc.dg/plugin/diagnostic-test-expressions-1.c (foo): New decl.
(test_multiple_ordinary_maps): New test function.
libcpp/ChangeLog:
PR c/68473
PR c++/70105
* line-map.c (linemap_macro_map_loc_unwind_toward_spelling): Move
decl...
* include/line-map.h
(linemap_macro_map_loc_unwind_toward_spelling): ...here,
converting from static to extern.
From-SVN: r234088
gcc/ChangeLog:
PR c/68473
PR c++/70105
* diagnostic-show-locus.c (layout_range::layout_range): Replace
location_range param with three const expanded_locations * and a
bool.
(layout::layout): Replace call to
rich_location::lazily_expand_location with get_expanded_location.
Extract the range and perform location expansion here, passing
the results to the layout_range ctor.
* diagnostic.c (source_range::debug): Delete.
* diagnostic.h (diagnostic_expand_location): Reimplement in terms
of rich_location::get_expanded_location.
* gcc-rich-location.c (get_range_for_expr): Delete.
(gcc_rich_location::add_expr): Reimplement to avoid the
rich_location::add_range overload that took a location_range,
passing a location_t instead.
gcc/testsuite/ChangeLog:
PR c/68473
PR c++/70105
* gcc.dg/plugin/diagnostic_plugin_show_trees.c (show_tree):
Drop range information from call to inform_at_rich_loc.
* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c (add_range):
New.
(test_show_locus): Replace calls to rich_location::add_range with
calls to add_range. Rewrite the tests that used the now-defunct
rich_location ctor taking a source_range. Simplify other tests
by replacing calls to COMBINE_LOCATION_DATA with calls to
make_location.
libcpp/ChangeLog:
PR c/68473
PR c++/70105
* include/line-map.h (source_range::debug): Delete.
(struct location_range): Update comment. Replace
expanded_location fields "m_start", "m_finish", and "m_caret" with
a source_location field: "m_loc".
(class rich_location): Reword comment.
(rich_location::get_loc): Reimplement in terms of a new overloaded
variant which takes an unsigned int.
(rich_location::get_loc_addr): Delete.
(rich_location::add_range): Drop params "start" and "finish" in
favor of param "loc". Drop overloaded variants taking a
source_range or location_range *.
(rich_location::lazily_expand_location): Delete in favor of...
(rich_location::get_expanded_location): New decl.
(rich_location::m_loc): Delete field.
(rich_location::m_column_override): New field.
* line-map.c (rich_location::rich_location): Drop name of
line_maps * param. Update initializations for deletion of field
"m_loc" and addition of field "m_column_override". Reimplement
body as a call to add_range. Delete overloaded variant taking a
source_range.
(rich_location::get_loc): New function.
(rich_location::lazily_expand_location): Delete in favor of...
(rich_location::get_expanded_location): New function.
(rich_location::override_column): Reimplement.
(rich_location::add_range): Drop params "start" and "finish" in
favor of param "loc". Eliminate location expansion in favor of
simply storing loc. Drop overloaded variants taking a
source_range or location_range *.
(rich_location::set_range): Eliminate location expansion.
From-SVN: r234087
gcc/testsuite/ChangeLog:
PR preprocessor/69985
* gcc.dg/cpp/pr69985.c: New test case.
libcpp/ChangeLog:
PR preprocessor/69985
(linemap_position_for_loc_and_offset): Rename param from "offset"
to "column_offset". Right-shift the column_offset by m_range_bits
of the pertinent ordinary map whenever offsetting a
source_location. For clarity, offset the column by the column
offset, rather than the other way around.
From-SVN: r233836