aboutsummaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authorThomas Schwinge <tschwinge@baylibre.com>2024-03-10 23:22:34 +0100
committerThomas Schwinge <tschwinge@baylibre.com>2024-03-10 23:22:34 +0100
commit2157ebb067bee3cb37c4d9df5a1f3248018f4326 (patch)
tree6715952bca39edf6a201e94e0444c7460d76f1db /libcpp
parentbcc6fe58251b317127ec9c3291a798da7459d377 (diff)
parent985d6480fe52a5b109960117ba6a876dd875157e (diff)
downloadgcc-2157ebb067bee3cb37c4d9df5a1f3248018f4326.zip
gcc-2157ebb067bee3cb37c4d9df5a1f3248018f4326.tar.gz
gcc-2157ebb067bee3cb37c4d9df5a1f3248018f4326.tar.bz2
Merge commit '4f01ae3761ca1f8dd7a33b833ae30624f047ac9c^' into HEAD
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/ChangeLog19
-rw-r--r--libcpp/charset.cc7
-rw-r--r--libcpp/directives.cc13
-rw-r--r--libcpp/internal.h2
-rw-r--r--libcpp/macro.cc12
-rw-r--r--libcpp/pch.cc2
6 files changed, 46 insertions, 9 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index 8bbd1ac..48acad7 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,22 @@
+2023-06-20 Lewis Hyatt <lhyatt@gmail.com>
+
+ PR c++/66290
+ * macro.cc (_cpp_create_definition): Add location argument.
+ * internal.h (_cpp_create_definition): Adjust prototype.
+ * directives.cc (do_define): Pass new location argument to
+ _cpp_create_definition.
+ (do_undef): Stop passing inferior location to cpp_warning_with_line;
+ the default from cpp_warning is better.
+ (cpp_pop_definition): Pass new location argument to
+ _cpp_create_definition.
+ * pch.cc (cpp_read_state): Likewise.
+
+2023-06-19 Ben Boeckel <ben.boeckel@kitware.com>
+
+ * charset.cc: Reject encodings of codepoints above 0x10FFFF.
+ UTF-16 does not support such codepoints and therefore all
+ Unicode rejects such values.
+
2023-06-15 Marek Polacek <polacek@redhat.com>
* configure.ac (--enable-host-shared): Don't set PICFLAG here.
diff --git a/libcpp/charset.cc b/libcpp/charset.cc
index 5a2229c..e38e0f2 100644
--- a/libcpp/charset.cc
+++ b/libcpp/charset.cc
@@ -1922,6 +1922,13 @@ cpp_valid_utf8_p (const char *buffer, size_t num_bytes)
int err = one_utf8_to_cppchar (&iter, &bytesleft, &cp);
if (err)
return false;
+
+ /* Additionally, Unicode declares that all codepoints above 0010FFFF are
+ invalid because they cannot be represented in UTF-16.
+
+ Reject such values.*/
+ if (cp >= UCS_LIMIT)
+ return false;
}
/* No problems encountered. */
return true;
diff --git a/libcpp/directives.cc b/libcpp/directives.cc
index 1fdd73e..ee5419d 100644
--- a/libcpp/directives.cc
+++ b/libcpp/directives.cc
@@ -655,6 +655,10 @@ do_define (cpp_reader *pfile)
if (node)
{
+ /* This is a better location than pfile->directive_line to store
+ as the macro location. */
+ const location_t name_loc = cpp_diagnostic_get_current_location (pfile);
+
/* If we have been requested to expand comments into macros,
then re-enable saving of comments. */
pfile->state.save_comments =
@@ -663,7 +667,7 @@ do_define (cpp_reader *pfile)
if (pfile->cb.before_define)
pfile->cb.before_define (pfile);
- if (_cpp_create_definition (pfile, node))
+ if (_cpp_create_definition (pfile, node, name_loc))
if (pfile->cb.define)
pfile->cb.define (pfile, pfile->directive_line, node);
@@ -694,9 +698,8 @@ do_undef (cpp_reader *pfile)
"undefining \"%s\"", NODE_NAME (node));
else if (cpp_builtin_macro_p (node)
&& CPP_OPTION (pfile, warn_builtin_macro_redefined))
- cpp_warning_with_line (pfile, CPP_W_BUILTIN_MACRO_REDEFINED,
- pfile->directive_line, 0,
- "undefining \"%s\"", NODE_NAME (node));
+ cpp_warning (pfile, CPP_W_BUILTIN_MACRO_REDEFINED,
+ "undefining \"%s\"", NODE_NAME (node));
if (node->value.macro
&& CPP_OPTION (pfile, warn_unused_macros))
@@ -2642,7 +2645,7 @@ cpp_pop_definition (cpp_reader *pfile, struct def_pragma_macro *c)
{
_cpp_clean_line (pfile);
nbuf->sysp = 1;
- if (!_cpp_create_definition (pfile, h))
+ if (!_cpp_create_definition (pfile, h, 0))
abort ();
_cpp_pop_buffer (pfile);
}
diff --git a/libcpp/internal.h b/libcpp/internal.h
index 9724676..8b74d10 100644
--- a/libcpp/internal.h
+++ b/libcpp/internal.h
@@ -686,7 +686,7 @@ inline bool _cpp_maybe_notify_macro_use (cpp_reader *pfile, cpp_hashnode *node,
}
extern cpp_macro *_cpp_new_macro (cpp_reader *, cpp_macro_kind, void *);
extern void _cpp_free_definition (cpp_hashnode *);
-extern bool _cpp_create_definition (cpp_reader *, cpp_hashnode *);
+extern bool _cpp_create_definition (cpp_reader *, cpp_hashnode *, location_t);
extern void _cpp_pop_context (cpp_reader *);
extern void _cpp_push_text_context (cpp_reader *, cpp_hashnode *,
const unsigned char *, size_t);
diff --git a/libcpp/macro.cc b/libcpp/macro.cc
index d4238d4..dada8fe 100644
--- a/libcpp/macro.cc
+++ b/libcpp/macro.cc
@@ -3819,7 +3819,8 @@ _cpp_new_macro (cpp_reader *pfile, cpp_macro_kind kind, void *placement)
/* Parse a macro and save its expansion. Returns nonzero on success. */
bool
-_cpp_create_definition (cpp_reader *pfile, cpp_hashnode *node)
+_cpp_create_definition (cpp_reader *pfile, cpp_hashnode *node,
+ location_t name_loc)
{
cpp_macro *macro;
@@ -3831,6 +3832,13 @@ _cpp_create_definition (cpp_reader *pfile, cpp_hashnode *node)
if (!macro)
return false;
+ /* _cpp_new_macro () has set macro->line to pfile->directive_line, which
+ denotes the line containing the #define with no column information. If
+ provided, change to name_loc, which will be the token src_loc for the
+ macro name, including the location and range information. */
+ if (name_loc)
+ macro->line = name_loc;
+
if (cpp_macro_p (node))
{
if (CPP_OPTION (pfile, warn_unused_macros))
@@ -3844,7 +3852,7 @@ _cpp_create_definition (cpp_reader *pfile, cpp_hashnode *node)
bool warned =
cpp_pedwarning_with_line (pfile, reason,
- pfile->directive_line, 0,
+ macro->line, 0,
"\"%s\" redefined", NODE_NAME (node));
if (warned && cpp_user_macro_p (node))
diff --git a/libcpp/pch.cc b/libcpp/pch.cc
index 595afef..a9f4ff1 100644
--- a/libcpp/pch.cc
+++ b/libcpp/pch.cc
@@ -838,7 +838,7 @@ cpp_read_state (cpp_reader *r, const char *name, FILE *f,
!= NULL)
{
_cpp_clean_line (r);
- if (!_cpp_create_definition (r, h))
+ if (!_cpp_create_definition (r, h, 0))
abort ();
_cpp_pop_buffer (r);
}