diff mbox series

libcpp, c-family, v3: Add (dumb) C23 N3017 #embed support [PR105863]

Message ID Zr3QbpdrizBRA3XK@tucnak
State New
Headers show
Series libcpp, c-family, v3: Add (dumb) C23 N3017 #embed support [PR105863] | expand

Commit Message

Jakub Jelinek Aug. 15, 2024, 9:54 a.m. UTC
On Wed, Aug 14, 2024 at 09:58:04PM +0000, Joseph Myers wrote:
> On Tue, 18 Jun 2024, Jakub Jelinek wrote:
> 
> > The following patch implements the C23 N3017 "#embed - a scannable,
> > tooling-friendly binary resource inclusion mechanism" paper.
> 
> Some initial comments, not yet reviewed the whole patch.

Thanks.  Here is an updated patch (and will post the following two which
needed updates as well).

> Having that alias seems reasonable and consistent with various other 
> options.

Done (both --embed-directory and --embed-directory= to match
--include-directory and --include-directory=).

> -Wmissing-include-dirs should probably warn about missing embed 
> directories (I don't think a separate -Wmissing-embed-dirs is needed).  I 
> suspect that already works with this patch, but a testcase should be 
> included.

Yes, it works, tests added.

> > +/* Skip over balanced preprocessing tokens until END is found.
> > +   If SAVE is non-NULL, remember the parsed tokens in it.  */
> 
> Document the parameter NESTED.

Done.

> > +/* Parse parameters of #embed directive or __has_embed expression.  */
> > +
> > +bool
> > +_cpp_parse_embed_params (cpp_reader *pfile, struct cpp_embed_params *params)
> 
> Document the meaning of the return value.

Done.

> Comparing param_kind against constants 0, 1, 2, 3 isn't very readable (and 
> it only gets worse in subsequent patches in the series comparing with 4 
> and 5 as well).  I think there should be actual defined constants (whether 
> enumeration constants or macros) indexing the table(s) of embed 
> parameters, rather than hardcoding 0 through 5.  (Or some system with 
> function pointers for embed parameter handlers in the table, so that such 
> constants aren't needed.)

Indeed, that makes it more readable.  Because of this change I'll repost the
gnu::offset and gnu::base64 patches because they needed some follow-up
tweaks, rest should remain the same.

2024-08-15  Jakub Jelinek  <jakub@redhat.com>

	PR c/105863
libcpp/
	* include/cpplib.h: Implement C23 N3017 #embed - a scannable,
	tooling-friendly binary resource inclusion mechanism paper.
	(enum cpp_builtin_type): Add BT_HAS_EMBED.
	(cpp_set_include_chains): Add another cpp_dir * argument to
	the declaration.
	* internal.h (enum include_type): Add IT_EMBED.
	(struct cpp_reader): Add embed_include member.
	(struct cpp_embed_params_tokens): New type.
	(struct cpp_embed_params): New type.
	(_cpp_get_token_no_padding): Declare.
	(enum _cpp_find_file_kind): Add _cpp_FFK_EMBED and _cpp_FFK_HAS_EMBED.
	(_cpp_stack_embed): Declare.
	(_cpp_parse_expr): Change return type to cpp_num_part instead of
	bool, change second argument from bool to const char * and add third
	argument.
	(_cpp_parse_embed_params): Declare.
	* directives.cc (DIRECTIVE_TABLE): Add embed entry.
	(end_directive): Don't call skip_rest_of_line for T_EMBED directive.
	(_cpp_handle_directive): Return 2 rather than 1 for T_EMBED in
	directives-only mode.
	(parse_include): Don't Call check_eol for T_EMBED directive.
	(skip_balanced_token_seq): New function.
	(EMBED_PARAMS): Define.
	(enum embed_param_kind): New type.
	(embed_params): New variable.
	(_cpp_parse_embed_params): New function.
	(do_embed): New function.
	(do_if): Adjust _cpp_parse_expr caller.
	(do_elif): Likewise.
	* expr.cc (parse_defined): Diagnose defined in #embed or __has_embed
	parameters.
	(_cpp_parse_expr): Change return type to cpp_num_part instead of
	bool, change second argument from bool to const char * and add third
	argument.  Adjust function comment.  For #embed/__has_embed parameters
	add an artificial CPP_OPEN_PAREN.  Use the second argument DIR
	directly instead of string literals conditional on IS_IF.
	For #embed/__has_embed parameter, stop on reaching CPP_CLOSE_PAREN
	matching the artificial one.  Diagnose negative or too large embed
	parameter operands.
	(num_binary_op): Use #embed instead of #if for diagnostics if inside
	#embed/__has_embed parameter.
	(num_div_op): Likewise.
	* files.cc (struct _cpp_file): Add limit member and embed bitfield.
	(search_cache): Add IS_EMBED argument, formatting fix.  Skip over
	files with different file->embed from the argument.
	(find_file_in_dir): Don't call pch_open_file if file->embed.
	(_cpp_find_file): Handle _cpp_FFK_EMBED and _cpp_FFK_HAS_EMBED.
	(read_file_guts): Formatting fix.
	(has_unique_contents): Ignore file->embed files.
	(search_path_head): Handle IT_EMBED type.
	(_cpp_stack_embed): New function.
	(_cpp_get_file_stat): Formatting fix.
	(cpp_set_include_chains): Add embed argument, save it to
	pfile->embed_include and compute lens for the chain.
	* init.cc (builtin_array): Add __has_embed entry.
	(cpp_init_builtins): Predefine __STDC_EMBED_NOT_FOUND__,
	__STDC_EMBED_FOUND__ and __STDC_EMBED_EMPTY__.
	* lex.cc (cpp_directive_only_process): Handle #embed.
	* macro.cc (cpp_get_token_no_padding): Rename to ...
	(_cpp_get_token_no_padding): ... this.  No longer static.
	(builtin_has_include_1): New function.
	(builtin_has_include): Use it.  Use _cpp_get_token_no_padding
	instead of cpp_get_token_no_padding.
	(builtin_has_embed): New function.
	(_cpp_builtin_macro_text): Handle BT_HAS_EMBED.
gcc/
	* doc/cppdiropts.texi (--embed-dir=): Document.
	* doc/cpp.texi (Binary Resource Inclusion): New chapter.
	(__has_embed): Document.
	* doc/invoke.texi (Directory Options): Mention --embed-dir=.
	* gcc.cc (cpp_unique_options): Add %{-embed*}.
	* genmatch.cc (main): Adjust cpp_set_include_chains caller.
	* incpath.h (enum incpath_kind): Add INC_EMBED.
	* incpath.cc (merge_include_chains): Handle INC_EMBED.
	(register_include_chains): Adjust cpp_set_include_chains caller.
gcc/c-family/
	* c.opt (-embed-dir=): New option.
	(-embed-directory): New alias.
	(-embed-directory=): New alias.
	* c-opts.cc (c_common_handle_option): Handle OPT__embed_dir_.
gcc/testsuite/
	* c-c++-common/cpp/embed-1.c: New test.
	* c-c++-common/cpp/embed-2.c: New test.
	* c-c++-common/cpp/embed-3.c: New test.
	* c-c++-common/cpp/embed-4.c: New test.
	* c-c++-common/cpp/embed-5.c: New test.
	* c-c++-common/cpp/embed-6.c: New test.
	* c-c++-common/cpp/embed-7.c: New test.
	* c-c++-common/cpp/embed-8.c: New test.
	* c-c++-common/cpp/embed-9.c: New test.
	* c-c++-common/cpp/embed-10.c: New test.
	* c-c++-common/cpp/embed-11.c: New test.
	* c-c++-common/cpp/embed-12.c: New test.
	* c-c++-common/cpp/embed-13.c: New test.
	* c-c++-common/cpp/embed-14.c: New test.
	* c-c++-common/cpp/embed-25.c: New test.
	* c-c++-common/cpp/embed-26.c: New test.
	* c-c++-common/cpp/embed-dir/embed-1.inc: New test.
	* c-c++-common/cpp/embed-dir/embed-3.c: New test.
	* c-c++-common/cpp/embed-dir/embed-4.c: New test.
	* c-c++-common/cpp/embed-dir/magna-carta.txt: New test.
	* gcc.dg/cpp/embed-1.c: New test.
	* gcc.dg/cpp/embed-2.c: New test.
	* gcc.dg/cpp/embed-3.c: New test.
	* gcc.dg/cpp/embed-4.c: New test.
	* g++.dg/cpp/embed-1.C: New test.
	* g++.dg/cpp/embed-2.C: New test.
	* g++.dg/cpp/embed-3.C: New test.



	Jakub

Comments

Joseph Myers Aug. 15, 2024, 10:07 p.m. UTC | #1
On Thu, 15 Aug 2024, Jakub Jelinek wrote:

> +  D(embed,	T_EMBED,	STDC23,    INCL | EXPAND)		\

I'd like to query the macro expansion handling.  My understanding is that 
a #embed directive only gets macro-expanded if it fails to match either of 
the forms

  # embed < h-char-sequence > embed-parameter-sequenceopt new-line
  # embed " q-char-sequence " embed-parameter-sequenceopt new-line

and while the argument of a limit parameter gets processed (including 
macro expansion) like in a #if condition, that processing doesn't apply to 
the other standard parameters.  (Maybe it *should* apply to prefix / 
suffix / if_empty so the pp-tokens in their arguments can include macros 
without needing to e.g. use a macro for the name of the file to embed as 
well, but that doesn't seem to be what the current wording says.  There 
was some discussion of this on the reflector last month, ending with 
<https://www.open-std.org/jtc1/sc22/wg14//26110>.)

Apart from any consequences for arguments of prefix/suffix/is_empty (where 
there is a plausible argument that the argument should get expanded at 
some point and that the current wording is undesirable for usability), 
this would also mean that e.g.

#define LIMIT limit
#embed "file" LIMIT(1)

isn't valid because LIMIT doesn't get expanded (the syntax for 
non-expanded #embed is met, with an unknown parameter LIMIT), while

#define limit !
#embed "file" limit(1)

*is* valid, because limit doesn't get expanded (which may be convenient 
for usability - it means headers don't need to use __limit__ if using 
#embed, even if files including the header might have defined limit as a 
macro).

> +  if (CPP_PEDANTIC (pfile))
> +    {
> +      if (CPP_OPTION (pfile, cplusplus))
> +	cpp_error (pfile, CPP_DL_PEDWARN,
> +		   "#%s is a GCC extension", "embed");
> +      else if (!CPP_OPTION (pfile, warning_directive))
> +	cpp_error (pfile, CPP_DL_PEDWARN,
> +		   "#%s before C23 is a GCC extension", "embed");

I don't think warning_directive directive should be used here as the 
condition for diagnosing #embed as an extension; adding a separate 
embed_directive would be better.  (Especially if a future C++ version ends 
up adding #embed; you could then use embed_directive as a condition for 
the pedwarn for both C and C++, whereas warning_directive wouldn't work as 
a condition for C++ since #warning is already in C++23.)
Jakub Jelinek Aug. 15, 2024, 11:43 p.m. UTC | #2
On Thu, Aug 15, 2024 at 10:07:00PM +0000, Joseph Myers wrote:
> On Thu, 15 Aug 2024, Jakub Jelinek wrote:
> 
> > +  D(embed,	T_EMBED,	STDC23,    INCL | EXPAND)		\
> 
> I'd like to query the macro expansion handling.  My understanding is that 
> a #embed directive only gets macro-expanded if it fails to match either of 
> the forms
> 
>   # embed < h-char-sequence > embed-parameter-sequenceopt new-line
>   # embed " q-char-sequence " embed-parameter-sequenceopt new-line
> 
> and while the argument of a limit parameter gets processed (including 
> macro expansion) like in a #if condition, that processing doesn't apply to 
> the other standard parameters.  (Maybe it *should* apply to prefix / 
> suffix / if_empty so the pp-tokens in their arguments can include macros 
> without needing to e.g. use a macro for the name of the file to embed as 
> well, but that doesn't seem to be what the current wording says.  There 
> was some discussion of this on the reflector last month, ending with 
> <https://www.open-std.org/jtc1/sc22/wg14//26110>.)
> 
> Apart from any consequences for arguments of prefix/suffix/is_empty (where 
> there is a plausible argument that the argument should get expanded at 
> some point and that the current wording is undesirable for usability), 
> this would also mean that e.g.
> 
> #define LIMIT limit
> #embed "file" LIMIT(1)
> 
> isn't valid because LIMIT doesn't get expanded (the syntax for 
> non-expanded #embed is met, with an unknown parameter LIMIT), while
> 
> #define limit !
> #embed "file" limit(1)
> 
> *is* valid, because limit doesn't get expanded (which may be convenient 
> for usability - it means headers don't need to use __limit__ if using 
> #embed, even if files including the header might have defined limit as a 
> macro).

Is there an agreement on that?
Because at least checking on godbolt, none of the existing implementations
work that way.

#define FILE "/etc/passwd"
#define LIMIT limit(1)
#define THIS , 1, 2, 3
#define PRE prefix (42,
ONE
#embed FILE LIMIT suffix(THIS) PRE )
TWO
#embed "/etc/passwd" LIMIT suffix(THIS) PRE )
THREE
#define limit prefix
#embed "/etc/passwd" limit (4) suffix (THIS)

is expanded to something like
ONE 42,110 , 1, 2, 3 TWO 42,110 , 1, 2, 3 THREE 4 47, ... 104 , 1, 2, 3
(... just not to show all of godbolt's /etc/passwd)
by JeanHeyd's branch which was used as a prior art for the paper
and on the clang trunk.

My reading of it wasn't that whether it is
# embed < h-char-sequence > embed-parameter-sequence[opt] new-line
or
# embed < h-char-sequence > embed-parameter-sequence[opt] new-line
or
# embed pp-tokens new-line
depends solely on the filename part in there, but also whether
embed-parameter-sequence is syntactically valid (if specified).

Though, guess I'm still not implementing it like that,
(and none of the existing implementations do), because
the last #embed in that case is treated by all 3 as
prefix (4) suffix (, 1, 2, 3) even when it would be valid
as limit (4) suffix (THIS) too.
In that reading, it would be pretty hard to implement, one would need to
check twice, first with disabled expansion read the tokens and see if
it matches that way the syntax of embed-parameter-sequence (but guess
LIMIT suffix(THIS)
would be e.g. valid but the PRE ) in there is not) and if invalid repeat
with the expansion enabled.

Also, in either case (if it is determined solely based on the header
tokens or on valid embed-parameter-sequence), what should happen if
the tokens e.g. in limit clause argument is without expansion valid
balanced token sequence but with expansion is not and it e.g. provides
) in there?
I mean
#define ARG 0) prefix (
#embed "file" limit (ARG)

Anyway, if there is no preprocessing of the embed-parameter-sequence tokens,
then it would make less sense that there are the limit vs. __limit__ etc.
variants (though sure, if it is the pp-tokens case it would still matter).

In any case, I'd hope that prefix/suffix/if_empty argument is macro expanded
at some point, because otherwise it will be a serious usability problem
for users.

> > +  if (CPP_PEDANTIC (pfile))
> > +    {
> > +      if (CPP_OPTION (pfile, cplusplus))
> > +	cpp_error (pfile, CPP_DL_PEDWARN,
> > +		   "#%s is a GCC extension", "embed");
> > +      else if (!CPP_OPTION (pfile, warning_directive))
> > +	cpp_error (pfile, CPP_DL_PEDWARN,
> > +		   "#%s before C23 is a GCC extension", "embed");
> 
> I don't think warning_directive directive should be used here as the 
> condition for diagnosing #embed as an extension; adding a separate 
> embed_directive would be better.  (Especially if a future C++ version ends 
> up adding #embed; you could then use embed_directive as a condition for 
> the pedwarn for both C and C++, whereas warning_directive wouldn't work as 
> a condition for C++ since #warning is already in C++23.)

Ok, will change that (there are really too many features and the table
already needs 147 columns before this change, so wanted to avoid adding new
stuff there unless necessary).

	Jakub
Jakub Jelinek Aug. 16, 2024, 9:19 a.m. UTC | #3
On Fri, Aug 16, 2024 at 01:43:58AM +0200, Jakub Jelinek wrote:
> My reading of it wasn't that whether it is
> # embed < h-char-sequence > embed-parameter-sequence[opt] new-line
> or
> # embed < h-char-sequence > embed-parameter-sequence[opt] new-line
> or
> # embed pp-tokens new-line
> depends solely on the filename part in there, but also whether
> embed-parameter-sequence is syntactically valid (if specified).

But if so, doesn't that mean that also
#define foo bar
#define bar baz
#define limit suffix (1
#embed <foo/bar.inc> limit )
should be treated as
#embed <bar/baz.inc> suffix (1)
?
I'd think that for filenames that would be quite surprising.

I think what is implemented by the 3 implementations makes more sense,
is easier to implement and understand, but it would mean a DR.

Make just the filename part macro unexpanded or expanded based on whether
it matches
#embed < h-char-sequence > pp-tokens[opt] new-line
or
#embed " q-char-sequence " pp-tokens[opt] new-line
and if not use
#embed pp-tokens new-line
and say that the pp-tokens in the first two forms are macro expanded and
should be valid embed-parameter-sequence[opt] after macro expansion.

Because what is strictly specified right now means essentially lexing the
line (or more if \ is used at end of lines) twice, once with disabled macro
expansion, silently see if it matches the grammar and then depending on that
lex it again with or without macro expansion.  Plus really unsure what to do
about the limit argument if it is balanced before expansion and not balanced
after it and whether to macro expand prefix/suffix/if_empty argument at all
and when if yes.  If prefix/suffix/if_empty is macro unexpanded, it would be
a loop-hole how to introduce tokens without macro expansion into the source
(other than temporarily #undefining macros or using (foo) (args) to avoid
function-like macro expansion).

One could simply
#include <sys/stat.h>
#embed </dev/zero> if_empty (__linux__ = S_ISDIR (1, 2, 3, 4))

	Jakub
Joseph Myers Aug. 16, 2024, 4:05 p.m. UTC | #4
On Fri, 16 Aug 2024, Jakub Jelinek wrote:

> > Apart from any consequences for arguments of prefix/suffix/is_empty (where 
> > there is a plausible argument that the argument should get expanded at 
> > some point and that the current wording is undesirable for usability), 
> > this would also mean that e.g.
> > 
> > #define LIMIT limit
> > #embed "file" LIMIT(1)
> > 
> > isn't valid because LIMIT doesn't get expanded (the syntax for 
> > non-expanded #embed is met, with an unknown parameter LIMIT), while
> > 
> > #define limit !
> > #embed "file" limit(1)
> > 
> > *is* valid, because limit doesn't get expanded (which may be convenient 
> > for usability - it means headers don't need to use __limit__ if using 
> > #embed, even if files including the header might have defined limit as a 
> > macro).
> 
> Is there an agreement on that?

I think it's understood to be what the words mean (apart from the recent 
discussion, also noted in February 2022 discussion - e.g. 
<https://www.open-std.org/jtc1/sc22/wg14/21635>).  Whether it's desirable 
is another matter.  Apart from likely wanting to be able to use macros 
within the prefix/suffix/if_empty arguments, it would also seem fairly 
reasonable to want to have a macro expanding to such parameters used with 
more than one directive.

#define PARAMS prefix(X) suffix(Y)

#embed "a" PARAMS

#embed "b" PARAMS

without needing to arrange for the directive not to look like one of the 
other forms before macro expansion.

I've added this to my list of issues to file once we have an issue 
tracking system for the C standard in operation.

> > > +  if (CPP_PEDANTIC (pfile))
> > > +    {
> > > +      if (CPP_OPTION (pfile, cplusplus))
> > > +	cpp_error (pfile, CPP_DL_PEDWARN,
> > > +		   "#%s is a GCC extension", "embed");
> > > +      else if (!CPP_OPTION (pfile, warning_directive))
> > > +	cpp_error (pfile, CPP_DL_PEDWARN,
> > > +		   "#%s before C23 is a GCC extension", "embed");
> > 
> > I don't think warning_directive directive should be used here as the 
> > condition for diagnosing #embed as an extension; adding a separate 
> > embed_directive would be better.  (Especially if a future C++ version ends 
> > up adding #embed; you could then use embed_directive as a condition for 
> > the pedwarn for both C and C++, whereas warning_directive wouldn't work as 
> > a condition for C++ since #warning is already in C++23.)
> 
> Ok, will change that (there are really too many features and the table
> already needs 147 columns before this change, so wanted to avoid adding new
> stuff there unless necessary).

My concern here is more with the use of the fields in cpp_options, than 
with the initialization of that from lang_flags.  Maybe that large 
lang_defaults table isn't the optimal way of initializing all those 
cpp_options fields (although initializing CPP_OPTION (pfile, 
embed_directive) from l->warning_directive would also be awkward; the 
question is more whether computing the cpp_options fields with logic like 
"C from version X onwards, C++ from version Y onwards" would be an 
improvement on a table taking 147 columns).
Joseph Myers Aug. 16, 2024, 4:14 p.m. UTC | #5
On Fri, 16 Aug 2024, Jakub Jelinek wrote:

> On Fri, Aug 16, 2024 at 01:43:58AM +0200, Jakub Jelinek wrote:
> > My reading of it wasn't that whether it is
> > # embed < h-char-sequence > embed-parameter-sequence[opt] new-line
> > or
> > # embed < h-char-sequence > embed-parameter-sequence[opt] new-line
> > or
> > # embed pp-tokens new-line
> > depends solely on the filename part in there, but also whether
> > embed-parameter-sequence is syntactically valid (if specified).
> 
> But if so, doesn't that mean that also
> #define foo bar
> #define bar baz
> #define limit suffix (1
> #embed <foo/bar.inc> limit )
> should be treated as
> #embed <bar/baz.inc> suffix (1)
> ?
> I'd think that for filenames that would be quite surprising.

I think the header-name preprocessing token still gets recognized inside 
#embed, so preventing macro expansion inside the filename, because there 
are no identifier preprocessing tokens inside that filename.  Just as

#define EMPTY
#define foobar stdio
#include <foobar.h> EMPTY

doesn't end up including <stdio.h> after macro expansion.  (There is the 
subsequent implementation-defined process for combining preprocessing 
tokens between < and > into a header name, so allowing a header name to 
result from macro expansion without needing a header name as an argument 
to the macro, but no such process to split up a header name before macro 
expansion.)
Jakub Jelinek Aug. 16, 2024, 4:56 p.m. UTC | #6
On Fri, Aug 16, 2024 at 04:05:52PM +0000, Joseph Myers wrote:
> On Fri, 16 Aug 2024, Jakub Jelinek wrote:
> 
> > > Apart from any consequences for arguments of prefix/suffix/is_empty (where 
> > > there is a plausible argument that the argument should get expanded at 
> > > some point and that the current wording is undesirable for usability), 
> > > this would also mean that e.g.
> > > 
> > > #define LIMIT limit
> > > #embed "file" LIMIT(1)
> > > 
> > > isn't valid because LIMIT doesn't get expanded (the syntax for 
> > > non-expanded #embed is met, with an unknown parameter LIMIT), while
> > > 
> > > #define limit !
> > > #embed "file" limit(1)
> > > 
> > > *is* valid, because limit doesn't get expanded (which may be convenient 
> > > for usability - it means headers don't need to use __limit__ if using 
> > > #embed, even if files including the header might have defined limit as a 
> > > macro).
> > 
> > Is there an agreement on that?
> 
> I think it's understood to be what the words mean (apart from the recent 
> discussion, also noted in February 2022 discussion - e.g. 
> <https://www.open-std.org/jtc1/sc22/wg14/21635>).  Whether it's desirable 
> is another matter.  Apart from likely wanting to be able to use macros 
> within the prefix/suffix/if_empty arguments, it would also seem fairly 
> reasonable to want to have a macro expanding to such parameters used with 
> more than one directive.
> 
> #define PARAMS prefix(X) suffix(Y)
> 
> #embed "a" PARAMS
> 
> #embed "b" PARAMS
> 
> without needing to arrange for the directive not to look like one of the 
> other forms before macro expansion.
> 
> I've added this to my list of issues to file once we have an issue 
> tracking system for the C standard in operation.

Ok.  So for now, should I work on a patch variant which tries to follow
what is in C23 right now?
I.e. most likely set pfile->state.prevent_expansion = 1; initially,
keep checking the tokens just for the basic syntax match (header token or
string literal, followed by check for pp-parameter matches if any until end
of line, based on that decide and push all the read tokens back to
lookaside?
Still, as I wrote, not really sure if it goes with the
pfile->state.prevent_expansion = 1 decision when temporarily switching that
off for the limit argument real parsing when the closing ) (i.e.
non-balanced) comes from a macro, and whether to ignore the macro expansion
of prefix/suffix/if_empty altogether, or push those expanded when actually
using them (and if so, again, what to do with unbalanced case; maybe in that
case it would be desirable and would allow to insert unbalanced {,(,[,],),}
to the token stream).

> My concern here is more with the use of the fields in cpp_options, than 
> with the initialization of that from lang_flags.  Maybe that large 
> lang_defaults table isn't the optimal way of initializing all those 
> cpp_options fields (although initializing CPP_OPTION (pfile, 
> embed_directive) from l->warning_directive would also be awkward; the 
> question is more whether computing the cpp_options fields with logic like 
> "C from version X onwards, C++ from version Y onwards" would be an 
> improvement on a table taking 147 columns).

Ok, will change it.  And think how to improve the table next.
Indeed, having some macro for this option is C >= n && C++ >= m, whether GNU
only or standard etc. would be nice.
Right now it is 28x23 bit matrix.
One possibility would be

/*                                              u         e w
                                          b d   8         l a   t
                              x         u i i   c v s   s i r d r
                        x     i   d u r d n g t h a c   z f n e u
                    c c n x c d s i l l l c s r l o o d l d d l f
                    9 + u i 1 i t g i i i s e i i p p f i e i i a
                    9 + m d 1 d d r t t t t p g t t e p t f r m l  */
{ /* GNUC89   */  { 0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0 },
  /* GNUC99   */  { 1,0,1,1,0,0,0,1,1,1,0,0,0,0,0,1,1,0,0,0,0,0,0 },
  /* GNUC11   */  { 1,0,1,1,1,0,0,1,1,1,0,0,0,0,0,1,1,0,0,0,0,0,0 },
  /* GNUC17   */  { 1,0,1,1,1,0,0,1,1,1,0,0,0,0,0,1,1,0,0,0,0,0,0 },
  /* GNUC23   */  { 1,0,1,1,1,1,0,1,1,1,0,1,1,0,1,1,1,1,0,1,1,0,1 },
  /* GNUC2Y   */  { 1,0,1,1,1,1,0,1,1,1,0,1,1,0,1,1,1,1,0,1,1,0,1 },
  /* STDC89   */  { 0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0 },
  /* STDC94   */  { 0,0,0,0,0,0,1,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0 },
  /* STDC99   */  { 1,0,1,1,0,0,1,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0 },
  /* STDC11   */  { 1,0,1,1,1,0,1,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0 },
  /* STDC17   */  { 1,0,1,1,1,0,1,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0 },
  /* STDC23   */  { 1,0,1,1,1,1,1,1,1,0,0,1,1,0,1,1,1,1,0,1,1,0,1 },
  /* STDC2Y   */  { 1,0,1,1,1,1,1,1,1,0,0,1,1,0,1,1,1,1,0,1,1,0,1 },
  /* GNUCXX   */  { 0,1,1,1,0,1,0,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,1 },
  /* CXX98    */  { 0,1,0,1,0,1,1,1,0,0,0,0,0,1,0,0,1,0,0,0,0,0,1 },
  /* GNUCXX11 */  { 1,1,1,1,1,1,0,1,1,1,1,0,0,0,0,1,1,0,0,0,0,0,1 },
  /* CXX11    */  { 1,1,0,1,1,1,1,1,1,1,1,0,0,1,0,0,1,0,0,0,0,0,1 },
  /* GNUCXX14 */  { 1,1,1,1,1,1,0,1,1,1,1,1,1,0,0,1,1,0,0,0,0,0,1 },
  /* CXX14    */  { 1,1,0,1,1,1,1,1,1,1,1,1,1,1,0,0,1,0,0,0,0,0,1 },
  /* GNUCXX17 */  { 1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,0,0,0,0,0,1 },
  /* CXX17    */  { 1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0,0,0,0,0,1 },
  /* GNUCXX20 */  { 1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,0,0,0,0,0,1 },
  /* CXX20    */  { 1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,0,0,0,0,1 },
  /* GNUCXX23 */  { 1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1 },
  /* CXX23    */  { 1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1 },
  /* GNUCXX26 */  { 1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1 },
  /* CXX26    */  { 1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1 },
  /* ASM      */  { 0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
};

	Jakub
Joseph Myers Aug. 16, 2024, 5:14 p.m. UTC | #7
On Fri, 16 Aug 2024, Jakub Jelinek wrote:

> Ok.  So for now, should I work on a patch variant which tries to follow
> what is in C23 right now?

Not sure how useful having such a patch variant would be until we have a 
better idea of what the desired semantics actually are.
Jakub Jelinek Sept. 2, 2024, 2:51 p.m. UTC | #8
On Fri, Aug 16, 2024 at 05:14:42PM +0000, Joseph Myers wrote:
> On Fri, 16 Aug 2024, Jakub Jelinek wrote:
> 
> > Ok.  So for now, should I work on a patch variant which tries to follow
> > what is in C23 right now?
> 
> Not sure how useful having such a patch variant would be until we have a 
> better idea of what the desired semantics actually are.

BTW, another question is whether __has_embed is macro expanded or not.
Because
6.10.1/13 says that
"Prior to evaluation, macro invocations in the list of preprocessing tokens that will
become the controlling constant expression are replaced (except for those macro names
modified by the defined unary operator), just as in normal text."
so the only special case there is defined, not
__has_embed/__has_include/__has_c_attribute.
But then 6.10.1/11 has:
"The identifiers __has_include, __has_embed, and __has_c_attribute
shall not appear in any context not mentioned in this subclause."
so wonder if
#define HAVE_STDIO_H __has_include (<stdio.h>)
#if HAVE_STDIO_H
#endif
isn't invalid (although both gcc and clang accept it).
Anyway, 6.10.1/1 still has the two different forms of
__has_include/__has_embed and in 6.10.1/5 says
"The second form of the has_include expression and has_embed expression is considered only if the
first form does not match, in which case the preprocessing tokens are processed just as in normal
text."

So, if we do the scan whole #embed line for syntax without macro expansion
and based on that decide whether to macro expand that or just
limit/gnu::offset args and prefix/suffix/if_empty only when actually using
those, shall the same be done also for __has_embed, or always do macro
expansion there, or do it depending on whether __has_embed itself comes
from a macro or not?  Maybe for __has_include it doesn't really matter,
but for __has_embed it does.

	Jakub
diff mbox series

Patch

--- libcpp/include/cpplib.h.jj	2024-08-05 13:04:54.052114116 +0200
+++ libcpp/include/cpplib.h	2024-08-15 10:29:44.409065336 +0200
@@ -974,6 +974,7 @@  enum cpp_builtin_type
   BT_HAS_BUILTIN,		/* `__has_builtin(x)' */
   BT_HAS_INCLUDE,		/* `__has_include(x)' */
   BT_HAS_INCLUDE_NEXT,		/* `__has_include_next(x)' */
+  BT_HAS_EMBED,			/* `__has_embed(x)' */
   BT_HAS_FEATURE,		/* `__has_feature(x)' */
   BT_HAS_EXTENSION		/* `__has_extension(x)' */
 };
@@ -1092,7 +1093,8 @@  extern void cpp_set_line_map (cpp_reader
 extern void cpp_set_lang (cpp_reader *, enum c_lang);
 
 /* Set the include paths.  */
-extern void cpp_set_include_chains (cpp_reader *, cpp_dir *, cpp_dir *, int);
+extern void cpp_set_include_chains (cpp_reader *, cpp_dir *, cpp_dir *,
+				    cpp_dir *, int);
 
 /* Call these to get pointers to the options, callback, and deps
    structures for a given reader.  These pointers are good until you
--- libcpp/internal.h.jj	2024-08-05 13:04:54.068113904 +0200
+++ libcpp/internal.h	2024-08-15 10:29:44.422065173 +0200
@@ -122,6 +122,7 @@  enum include_type
    IT_INCLUDE,  /* #include */
    IT_INCLUDE_NEXT,  /* #include_next */
    IT_IMPORT,   /* #import  */
+   IT_EMBED,  /* #embed  */
 
    /* Non-directive including mechanisms.  */
    IT_CMDLINE,  /* -include */
@@ -463,6 +464,7 @@  struct cpp_reader
   struct cpp_dir *quote_include;	/* "" */
   struct cpp_dir *bracket_include;	/* <> */
   struct cpp_dir no_search_path;	/* No path.  */
+  struct cpp_dir *embed_include;	/* #embed <> */
 
   /* Chain of all hashed _cpp_file instances.  */
   struct _cpp_file *all_files;
@@ -614,6 +616,24 @@  struct cpp_reader
   }
 };
 
+/* Lists of tokens for #embed/__has_embed prefix/suffix/if_empty
+   parameters.  */
+struct cpp_embed_params_tokens
+{
+  cpp_token *cur_token;
+  tokenrun base_run, *cur_run;
+  size_t count;
+};
+
+/* #embed and __has_embed parameters.  */
+struct cpp_embed_params
+{
+  location_t loc;
+  bool has_embed;
+  cpp_num_part limit;
+  cpp_embed_params_tokens prefix, suffix, if_empty;
+};
+
 /* Character classes.  Based on the more primitive macros in safe-ctype.h.
    If the definition of `numchar' looks odd to you, please look up the
    definition of a pp-number in the C standard [section 6.4.8 of C99].
@@ -702,6 +722,7 @@  extern bool _cpp_arguments_ok (cpp_reade
 extern const unsigned char *_cpp_builtin_macro_text (cpp_reader *,
 						     cpp_hashnode *,
 						     location_t = 0);
+extern const cpp_token *_cpp_get_token_no_padding (cpp_reader *);
 extern int _cpp_warn_if_unused_macro (cpp_reader *, cpp_hashnode *, void *);
 extern void _cpp_push_token_context (cpp_reader *, cpp_hashnode *,
 				     const cpp_token *, unsigned int);
@@ -714,13 +735,16 @@  extern void _cpp_destroy_hashtable (cpp_
 
 /* In files.cc */
 enum _cpp_find_file_kind
-  { _cpp_FFK_NORMAL, _cpp_FFK_FAKE, _cpp_FFK_PRE_INCLUDE, _cpp_FFK_HAS_INCLUDE };
+  { _cpp_FFK_NORMAL, _cpp_FFK_FAKE, _cpp_FFK_PRE_INCLUDE, _cpp_FFK_HAS_INCLUDE,
+    _cpp_FFK_EMBED, _cpp_FFK_HAS_EMBED };
 extern _cpp_file *_cpp_find_file (cpp_reader *, const char *, cpp_dir *,
 				  int angle, _cpp_find_file_kind, location_t);
 extern bool _cpp_find_failed (_cpp_file *);
 extern void _cpp_mark_file_once_only (cpp_reader *, struct _cpp_file *);
 extern const char *_cpp_find_header_unit (cpp_reader *, const char *file,
 					  bool angle_p,  location_t);
+extern int _cpp_stack_embed (cpp_reader *, const char *, bool,
+			     cpp_embed_params *);
 extern void _cpp_fake_include (cpp_reader *, const char *);
 extern bool _cpp_stack_file (cpp_reader *, _cpp_file*, include_type, location_t);
 extern bool _cpp_stack_include (cpp_reader *, const char *, int,
@@ -739,7 +763,8 @@  extern bool _cpp_has_header (cpp_reader
 			     enum include_type);
 
 /* In expr.cc */
-extern bool _cpp_parse_expr (cpp_reader *, bool);
+extern cpp_num_part _cpp_parse_expr (cpp_reader *, const char *,
+				     const cpp_token *);
 extern struct op *_cpp_expand_op_stack (cpp_reader *);
 
 /* In lex.cc */
@@ -780,6 +805,7 @@  extern void _cpp_restore_pragma_names (c
 extern int _cpp_do__Pragma (cpp_reader *, location_t);
 extern void _cpp_init_directives (cpp_reader *);
 extern void _cpp_init_internal_pragmas (cpp_reader *);
+extern bool _cpp_parse_embed_params (cpp_reader *, struct cpp_embed_params *);
 extern void _cpp_do_file_change (cpp_reader *, enum lc_reason, const char *,
 				 linenum_type, unsigned int);
 extern void _cpp_pop_buffer (cpp_reader *);
--- libcpp/directives.cc.jj	2024-08-05 13:04:54.049114156 +0200
+++ libcpp/directives.cc	2024-08-15 11:02:56.653279609 +0200
@@ -159,6 +159,7 @@  static void cpp_pop_definition (cpp_read
   D(error,	T_ERROR,	STDC89,    0)				\
   D(pragma,	T_PRAGMA,	STDC89,    IN_I)			\
   D(warning,	T_WARNING,	STDC23,    0)				\
+  D(embed,	T_EMBED,	STDC23,    INCL | EXPAND)		\
   D(include_next, T_INCLUDE_NEXT, EXTENSION, INCL | EXPAND)		\
   D(ident,	T_IDENT,	EXTENSION, IN_I)			\
   D(import,	T_IMPORT,	EXTENSION, INCL | EXPAND)  /* ObjC */	\
@@ -326,7 +327,8 @@  end_directive (cpp_reader *pfile, int sk
   /* We don't skip for an assembler #.  */
   else if (skip_line)
     {
-      skip_rest_of_line (pfile);
+      if (pfile->directive != &dtable[T_EMBED])
+	skip_rest_of_line (pfile);
       if (!pfile->keep_tokens)
 	{
 	  pfile->cur_run = &pfile->base_run;
@@ -569,7 +571,15 @@  _cpp_handle_directive (cpp_reader *pfile
     prepare_directive_trad (pfile);
 
   if (dir)
-    pfile->directive->handler (pfile);
+    {
+      pfile->directive->handler (pfile);
+      if (pfile->directive == &dtable[T_EMBED]
+	  && skip
+	  && CPP_OPTION (pfile, directives_only))
+	/* Signal to cpp_directive_only_process it needs to emit
+	   the #embed expansion.  */
+	skip = 2;
+    }
   else if (skip == 0)
     _cpp_backup_tokens (pfile, 1);
 
@@ -821,9 +831,10 @@  parse_include (cpp_reader *pfile, int *p
       return NULL;
     }
 
-  if (pfile->directive == &dtable[T_PRAGMA])
+  if (pfile->directive == &dtable[T_PRAGMA]
+      || pfile->directive == &dtable[T_EMBED])
     {
-      /* This pragma allows extra tokens after the file name.  */
+      /* This pragma or #embed allows extra tokens after the file name.  */
     }
   else if (buf == NULL || CPP_OPTION (pfile, discard_comments))
     check_eol (pfile, true);
@@ -921,6 +932,343 @@  do_include_next (cpp_reader *pfile)
   do_include_common (pfile, type);
 }
 
+/* Skip over balanced preprocessing tokens until END is found.
+   If SAVE is non-NULL, remember the parsed tokens in it.  NESTED is
+   false in the outermost invocation of the function and true
+   when called recursively.  */
+
+static void
+skip_balanced_token_seq (cpp_reader *pfile, cpp_ttype end,
+			 cpp_embed_params_tokens *save, bool nested)
+{
+  do
+    {
+      const cpp_token *token = cpp_peek_token (pfile, 0);
+      if (token->type == CPP_EOF)
+	{
+	  char c = 0;
+	  switch (end)
+	    {
+	    case CPP_CLOSE_PAREN: c = '('; break;
+	    case CPP_CLOSE_SQUARE: c = '['; break;
+	    case CPP_CLOSE_BRACE: c = '{'; break;
+	    default: abort ();
+	    }
+	  cpp_error (pfile, CPP_DL_ERROR, "unbalanced '%c'", c);
+	  return;
+	}
+      token = cpp_get_token (pfile);
+      if (save
+	  && (token->type != CPP_PADDING || save->count)
+	  && (token->type != end || nested))
+	{
+	  if (save->count == 0)
+	    {
+	      _cpp_init_tokenrun (&save->base_run, 4);
+	      save->cur_run = &save->base_run;
+	      save->cur_token = save->base_run.base;
+	    }
+	  else if (save->cur_token == save->cur_run->limit)
+	    {
+	      save->cur_run->next = XNEW (tokenrun);
+	      save->cur_run->next->prev = save->cur_run;
+	      _cpp_init_tokenrun (save->cur_run->next, 4);
+	      save->cur_run = save->cur_run->next;
+	      save->cur_token = save->cur_run->base;
+	    }
+	  *save->cur_token = *token;
+	  save->cur_token->flags |= NO_EXPAND;
+	  save->cur_token++;
+	  save->count++;
+	}
+      if (token->type == end)
+	return;
+      switch (token->type)
+	{
+	case CPP_OPEN_PAREN:
+	  skip_balanced_token_seq (pfile, CPP_CLOSE_PAREN, save, true);
+	  break;
+	case CPP_OPEN_SQUARE:
+	  skip_balanced_token_seq (pfile, CPP_CLOSE_SQUARE, save, true);
+	  break;
+	case CPP_OPEN_BRACE:
+	  skip_balanced_token_seq (pfile, CPP_CLOSE_BRACE, save, true);
+	  break;
+	case CPP_CLOSE_PAREN:
+	  cpp_error (pfile, CPP_DL_ERROR, "unbalanced '%c'", ')');
+	  break;
+	case CPP_CLOSE_SQUARE:
+	  cpp_error (pfile, CPP_DL_ERROR, "unbalanced '%c'", ']');
+	  break;
+	case CPP_CLOSE_BRACE:
+	  cpp_error (pfile, CPP_DL_ERROR, "unbalanced '%c'", '}');
+	  break;
+	default:
+	  break;
+	}
+    }
+  while (1);
+}
+
+#define EMBED_PARAMS \
+  EMBED_PARAM (LIMIT, "limit")		\
+  EMBED_PARAM (PREFIX, "prefix")	\
+  EMBED_PARAM (SUFFIX, "suffix")	\
+  EMBED_PARAM (IF_EMPTY, "if_empty")
+
+enum embed_param_kind {
+#define EMBED_PARAM(c, s) EMBED_PARAM_##c,
+  EMBED_PARAMS
+#undef EMBED_PARAM
+  NUM_EMBED_PARAMS
+};
+
+static struct { int len; const char *name; } embed_params[NUM_EMBED_PARAMS] = {
+#define EMBED_PARAM(c, s) { sizeof (s) - 1, s },
+  EMBED_PARAMS
+#undef EMBED_PARAM
+};
+
+/* Parse parameters of #embed directive or __has_embed expression.
+   Fills in details about parsed parameters in *PARAMS.
+   Returns true if all the parameters have been successfully parsed,
+   false on errors.  */
+
+bool
+_cpp_parse_embed_params (cpp_reader *pfile, struct cpp_embed_params *params)
+{
+  const cpp_token *token = _cpp_get_token_no_padding (pfile);
+  bool ret = true;
+  int seen = 0;
+  params->limit = -1;
+  do
+    {
+      const unsigned char *param_name = NULL;
+      const unsigned char *param_prefix = NULL;
+      int param_name_len = 0, param_prefix_len = 0;
+      bool has_scope = false;
+      if (token->type != CPP_NAME)
+	{
+	  if (token->type == CPP_EOF)
+	    {
+	      if (params->has_embed)
+		{
+		  cpp_error (pfile, CPP_DL_ERROR, "expected ')'");
+		  return false;
+		}
+	      return ret;
+	    }
+	  else if (token->type == CPP_CLOSE_PAREN && params->has_embed)
+	    return ret;
+	  cpp_error (pfile, CPP_DL_ERROR, "expected parameter name");
+	  return false;
+	}
+      param_name = NODE_NAME (token->val.node.spelling);
+      param_name_len = NODE_LEN (token->val.node.spelling);
+      location_t loc = token->src_loc;
+      token = _cpp_get_token_no_padding (pfile);
+      if (token->type == CPP_SCOPE)
+	{
+	  has_scope = true;
+	  token = _cpp_get_token_no_padding (pfile);
+	}
+      else if (token->type == CPP_COLON
+	       && (token->flags & COLON_SCOPE) != 0)
+	{
+	  has_scope = true;
+	  token = _cpp_get_token_no_padding (pfile);
+	  if (token->type != CPP_COLON)
+	    {
+	      cpp_error (pfile, CPP_DL_ERROR, "expected ':'");
+	      return false;
+	    }
+	  token = _cpp_get_token_no_padding (pfile);
+	}
+      if (has_scope)
+	{
+	  if (token->type != CPP_NAME)
+	    {
+	      cpp_error (pfile, CPP_DL_ERROR, "expected parameter name");
+	      return false;
+	    }
+	  param_prefix = param_name;
+	  param_prefix_len = param_name_len;
+	  param_name = NODE_NAME (token->val.node.spelling);
+	  param_name_len = NODE_LEN (token->val.node.spelling);
+	  loc = token->src_loc;
+	  token = _cpp_get_token_no_padding (pfile);
+	}
+      if (param_name_len > 4
+	  && param_name[0] == '_'
+	  && param_name[1] == '_'
+	  && param_name[param_name_len - 1] == '_'
+	  && param_name[param_name_len - 2] == '_')
+	{
+	  param_name += 2;
+	  param_name_len -= 4;
+	}
+      if (param_prefix
+	  && param_prefix_len > 4
+	  && param_prefix[0] == '_'
+	  && param_prefix[1] == '_'
+	  && param_prefix[param_prefix_len - 1] == '_'
+	  && param_prefix[param_prefix_len - 2] == '_')
+	{
+	  param_prefix += 2;
+	  param_prefix_len -= 4;
+	}
+      size_t param_kind = -1;
+      if (param_prefix == NULL)
+	{
+	  for (size_t i = 0; i < NUM_EMBED_PARAMS; ++i)
+	    if (param_name_len == embed_params[i].len
+		&& memcmp (param_name, embed_params[i].name,
+			   param_name_len) == 0)
+	      {
+		param_kind = i;
+		break;
+	      }
+	}
+      if (param_kind != (size_t) -1)
+	{
+	  if ((seen & (1 << param_kind)) == 0)
+	    seen |= 1 << param_kind;
+	  else
+	    cpp_error_with_line (pfile, CPP_DL_ERROR, loc, 0,
+				 "duplicate embed parameter '%.*s%s%.*s'",
+				 param_prefix_len,
+				 param_prefix
+				 ? (const char *) param_prefix : "",
+				 param_prefix ? "::" : "",
+				 param_name_len, param_name);
+	}
+      else
+	{
+	  ret = false;
+	  if (!params->has_embed)
+	    cpp_error_with_line (pfile, CPP_DL_ERROR, loc, 0,
+				 "unknown embed parameter '%.*s%s%.*s'",
+				 param_prefix_len,
+				 param_prefix
+				 ? (const char *) param_prefix : "",
+				 param_prefix ? "::" : "",
+				 param_name_len, param_name);
+	}
+      if (param_kind != (size_t) -1 && token->type != CPP_OPEN_PAREN)
+	cpp_error_with_line (pfile, CPP_DL_ERROR, loc, 0,
+			     "expected '('");
+      else if (param_kind == EMBED_PARAM_LIMIT)
+	{
+	  if (params->has_embed && pfile->op_stack == NULL)
+	    _cpp_expand_op_stack (pfile);
+	  params->limit = _cpp_parse_expr (pfile, "#embed", token);
+	  token = _cpp_get_token_no_padding (pfile);
+	}
+      else if (token->type == CPP_OPEN_PAREN)
+	{
+	  cpp_embed_params_tokens *save = NULL;
+	  auto save_comments = pfile->state.save_comments;
+	  switch (param_kind)
+	    {
+	    case EMBED_PARAM_PREFIX: save = &params->prefix; break;
+	    case EMBED_PARAM_SUFFIX: save = &params->suffix; break;
+	    case EMBED_PARAM_IF_EMPTY: save = &params->if_empty; break;
+	    default: break;
+	    }
+	  if (params->has_embed)
+	    save = NULL;
+	  else if (save)
+	    pfile->state.save_comments = !CPP_OPTION (pfile, discard_comments);
+	  skip_balanced_token_seq (pfile, CPP_CLOSE_PAREN, save, false);
+	  pfile->state.save_comments = save_comments;
+	  token = _cpp_get_token_no_padding (pfile);
+	}
+    }
+  while (1);
+}
+
+/* Handle #embed directive.  */
+
+static void
+do_embed (cpp_reader *pfile)
+{
+  int angle_brackets;
+  struct cpp_embed_params params = {};
+  bool ok;
+  const char *fname = NULL;
+
+  /* Tell the lexer this is an embed directive.  */
+  pfile->state.in_directive = 3;
+
+  if (CPP_OPTION (pfile, traditional))
+    {
+      cpp_error (pfile, CPP_DL_ERROR, /* FIXME should be DL_SORRY */
+		 "#embed not supported in traditional C");
+      skip_rest_of_line (pfile);
+      goto done;
+    }
+
+  if (CPP_PEDANTIC (pfile))
+    {
+      if (CPP_OPTION (pfile, cplusplus))
+	cpp_error (pfile, CPP_DL_PEDWARN,
+		   "#%s is a GCC extension", "embed");
+      else if (!CPP_OPTION (pfile, warning_directive))
+	cpp_error (pfile, CPP_DL_PEDWARN,
+		   "#%s before C23 is a GCC extension", "embed");
+    }
+
+  fname = parse_include (pfile, &angle_brackets, NULL, &params.loc);
+  if (!fname)
+    {
+      skip_rest_of_line (pfile);
+      goto done;
+    }
+
+  if (!*fname)
+    {
+      cpp_error_with_line (pfile, CPP_DL_ERROR, params.loc, 0,
+			   "empty filename in #%s",
+			   pfile->directive->name);
+      skip_rest_of_line (pfile);
+      goto done;
+    }
+
+  pfile->state.angled_headers = false;
+  pfile->state.directive_wants_padding = false;
+  ok = _cpp_parse_embed_params (pfile, &params);
+
+  /* Get out of macro context, if we are.  */
+  skip_rest_of_line (pfile);
+
+  if (ok)
+    _cpp_stack_embed (pfile, fname, angle_brackets, &params);
+
+  for (int i = 0; i < 3; ++i)
+    {
+      cpp_embed_params_tokens *p;
+      if (i == 0)
+	p = &params.prefix;
+      else if (i == 1)
+	p = &params.suffix;
+      else
+	p = &params.if_empty;
+      if (p->count == 0)
+	continue;
+      tokenrun *n;
+      for (tokenrun *t = &p->base_run; t; t = n)
+	{
+	  n = t->next;
+	  XDELETEVEC (t->base);
+	  if (t != &p->base_run)
+	    XDELETE (t);
+	}
+    }
+
+ done:
+  XDELETEVEC (fname);
+}
+
 /* Subroutine of do_linemarker.  Read possible flags after file name.
    LAST is the last flag seen; 0 if this is the first flag. Return the
    flag if it is valid, 0 at the end of the directive. Otherwise
@@ -2084,7 +2432,7 @@  do_if (cpp_reader *pfile)
   int skip = 1;
 
   if (! pfile->state.skipping)
-    skip = _cpp_parse_expr (pfile, true) == false;
+    skip = _cpp_parse_expr (pfile, "#if", NULL) == false;
 
   push_conditional (pfile, skip, T_IF, pfile->mi_ind_cmacro);
 }
@@ -2172,7 +2520,7 @@  do_elif (cpp_reader *pfile)
       else
 	{
 	  if (pfile->directive == &dtable[T_ELIF])
-	    pfile->state.skipping = !_cpp_parse_expr (pfile, false);
+	    pfile->state.skipping = !_cpp_parse_expr (pfile, "#elif", NULL);
 	  else
 	    {
 	      cpp_hashnode *node = lex_macro_node (pfile, false);
--- libcpp/expr.cc.jj	2024-08-05 13:04:54.050114143 +0200
+++ libcpp/expr.cc	2024-08-15 10:29:44.460064699 +0200
@@ -1106,6 +1106,9 @@  parse_defined (cpp_reader *pfile)
   const cpp_token *token;
   cpp_context *initial_context = pfile->context;
 
+  if (pfile->state.in_directive == 3)
+    cpp_error (pfile, CPP_DL_ERROR, "'defined' in #embed parameter");
+
   /* Don't expand macros.  */
   pfile->state.prevent_expansion++;
 
@@ -1356,7 +1359,9 @@  static const struct cpp_operator
 };
 
 /* Parse and evaluate a C expression, reading from PFILE.
-   Returns the truth value of the expression.
+   Returns the truth value of the expression if OPEN_PAREN
+   is NULL, otherwise the low 64-bits of the result (when parsing
+   #embed/__has_embed parameters).
 
    The implementation is an operator precedence parser, i.e. a
    bottom-up parser, using a stack for not-yet-reduced tokens.
@@ -1366,8 +1371,9 @@  static const struct cpp_operator
    recently pushed operator is 'top->op'.  An operand (value) is
    stored in the 'value' field of the stack element of the operator
    that precedes it.  */
-bool
-_cpp_parse_expr (cpp_reader *pfile, bool is_if)
+cpp_num_part
+_cpp_parse_expr (cpp_reader *pfile, const char *dir,
+		 const cpp_token *open_paren)
 {
   struct op *top = pfile->op_stack;
   unsigned int lex_count;
@@ -1384,6 +1390,14 @@  _cpp_parse_expr (cpp_reader *pfile, bool
   /* Lowest priority operator prevents further reductions.  */
   top->op = CPP_EOF;
 
+  if (pfile->state.in_directive == 3)
+    {
+      ++top;
+      top->op = CPP_OPEN_PAREN;
+      top->token = open_paren;
+      top->loc = open_paren->src_loc;
+    }
+
   for (;;)
     {
       struct op op;
@@ -1454,7 +1468,7 @@  _cpp_parse_expr (cpp_reader *pfile, bool
 
 	  if (op.op == CPP_EOF && top->op == CPP_EOF)
  	    SYNTAX_ERROR2_AT (op.loc,
-			      "%s with no expression", is_if ? "#if" : "#elif");
+			      "%s with no expression", dir);
 
  	  if (top->op != CPP_EOF && top->op != CPP_OPEN_PAREN)
  	    SYNTAX_ERROR2_AT (op.loc,
@@ -1478,6 +1492,8 @@  _cpp_parse_expr (cpp_reader *pfile, bool
       switch (op.op)
 	{
 	case CPP_CLOSE_PAREN:
+	  if (pfile->state.in_directive == 3 && top == pfile->op_stack)
+	    goto embed_done;
 	  continue;
 	case CPP_OR_OR:
 	  if (!num_zerop (top->value))
@@ -1520,12 +1536,31 @@  _cpp_parse_expr (cpp_reader *pfile, bool
   if (top != pfile->op_stack)
     {
       cpp_error_with_line (pfile, CPP_DL_ICE, top->loc, 0,
-			   "unbalanced stack in %s",
-			   is_if ? "#if" : "#elif");
+			   "unbalanced stack in %s", dir);
     syntax_error:
       return false;  /* Return false on syntax error.  */
     }
 
+  if (pfile->state.in_directive == 3)
+    {
+    embed_done:
+      if (num_zerop (top->value))
+	return 0;
+      if (!top->value.unsignedp
+	  && !num_positive (top->value, CPP_OPTION (pfile, precision)))
+	{
+	  cpp_error_with_line (pfile, CPP_DL_ERROR, top->loc, 0,
+			       "negative embed parameter operand");
+	  return 1;
+	}
+      if (top->value.high)
+	{
+	  cpp_error_with_line (pfile, CPP_DL_ERROR, top->loc, 0,
+			       "too large embed parameter operand");
+	  return 1;
+	}
+      return top->value.low;
+    }
   return !num_zerop (top->value);
 }
 
@@ -2079,7 +2114,9 @@  num_binary_op (cpp_reader *pfile, cpp_nu
       if (CPP_PEDANTIC (pfile) && (!CPP_OPTION (pfile, c99)
 				   || !pfile->state.skip_eval))
 	cpp_pedwarning (pfile, CPP_W_PEDANTIC,
-			"comma operator in operand of #if");
+			"comma operator in operand of #%s",
+			pfile->state.in_directive == 3
+			? "embed" : "if");
       lhs = rhs;
       break;
     }
@@ -2215,7 +2252,9 @@  num_div_op (cpp_reader *pfile, cpp_num l
     {
       if (!pfile->state.skip_eval)
 	cpp_error_with_line (pfile, CPP_DL_ERROR, location, 0,
-			     "division by zero in #if");
+			     "division by zero in #%s",
+			     pfile->state.in_directive == 3
+			     ? "embed" : "if");
       lhs.unsignedp = unsignedp;
       return lhs;
     }
--- libcpp/files.cc.jj	2024-08-05 13:04:54.052114116 +0200
+++ libcpp/files.cc	2024-08-15 10:29:44.479064462 +0200
@@ -87,6 +87,9 @@  struct _cpp_file
   /* As filled in by stat(2) for the file.  */
   struct stat st;
 
+  /* Size for #embed, perhaps smaller than st.st_size.  */
+  size_t limit;
+
   /* File descriptor.  Invalid if -1, otherwise open.  */
   int fd;
 
@@ -113,6 +116,9 @@  struct _cpp_file
      and error should be emitted if it is included normally.  */
   bool deferred_error : 1;
 
+  /* File loaded from #embed.  */
+  bool embed : 1;
+
   /* > 0: Known C++ Module header unit, <0: known not.  ==0, unknown  */
   int header_unit : 2;
 };
@@ -187,7 +193,8 @@  static const char *dir_name_of_file (_cp
 static void open_file_failed (cpp_reader *pfile, _cpp_file *file, int,
 			      location_t);
 static struct cpp_file_hash_entry *search_cache (struct cpp_file_hash_entry *head,
-					     const cpp_dir *start_dir);
+						 const cpp_dir *start_dir,
+						 bool is_embed);
 static _cpp_file *make_cpp_file (cpp_dir *, const char *fname);
 static void destroy_cpp_file (_cpp_file *);
 static cpp_dir *make_cpp_dir (cpp_reader *, const char *dir_name, int sysp);
@@ -425,7 +432,7 @@  find_file_in_dir (cpp_reader *pfile, _cp
 	}
 
       file->path = path;
-      if (pch_open_file (pfile, file, invalid_pch))
+      if (!file->embed && pch_open_file (pfile, file, invalid_pch))
 	return true;
 
       if (open_file (file))
@@ -514,7 +521,9 @@  _cpp_find_file (cpp_reader *pfile, const
   bool invalid_pch = false;
   bool saw_bracket_include = false;
   bool saw_quote_include = false;
+  bool saw_embed_include = false;
   struct cpp_dir *found_in_cache = NULL;
+  bool is_embed = kind == _cpp_FFK_EMBED || kind == _cpp_FFK_HAS_EMBED;
 
   /* Ensure we get no confusion between cached files and directories.  */
   if (start_dir == NULL)
@@ -526,10 +535,12 @@  _cpp_find_file (cpp_reader *pfile, const
 
   /* First check the cache before we resort to memory allocation.  */
   cpp_file_hash_entry *entry
-    = search_cache ((struct cpp_file_hash_entry *) *hash_slot, start_dir);
+    = search_cache ((struct cpp_file_hash_entry *) *hash_slot, start_dir,
+		    is_embed);
   if (entry)
     {
-      if (entry->u.file->deferred_error && kind == _cpp_FFK_NORMAL)
+      if (entry->u.file->deferred_error
+	  && (kind == _cpp_FFK_NORMAL || kind == _cpp_FFK_EMBED))
 	{
 	  open_file_failed (pfile, entry->u.file, angle_brackets, loc);
 	  entry->u.file->deferred_error = false;
@@ -541,6 +552,7 @@  _cpp_find_file (cpp_reader *pfile, const
   file->implicit_preinclude
     = (kind == _cpp_FFK_PRE_INCLUDE
        || (pfile->buffer && pfile->buffer->file->implicit_preinclude));
+  file->embed = is_embed;
 
   if (kind == _cpp_FFK_FAKE)
     file->dont_read = true;
@@ -551,10 +563,17 @@  _cpp_find_file (cpp_reader *pfile, const
 	if (find_file_in_dir (pfile, file, &invalid_pch, loc))
 	  break;
 
-	file->dir = file->dir->next;
+	if (is_embed
+	    && file->dir == start_dir
+	    && start_dir != pfile->embed_include
+	    && start_dir != &pfile->no_search_path)
+	  file->dir = pfile->embed_include;
+	else
+	  file->dir = file->dir->next;
 	if (file->dir == NULL)
 	  {
-	    if (search_path_exhausted (pfile, fname, file))
+	    if (!is_embed
+		&& search_path_exhausted (pfile, fname, file))
 	      {
 		/* Although this file must not go in the cache,
 		   because the file found might depend on things (like
@@ -601,7 +620,7 @@  _cpp_find_file (cpp_reader *pfile, const
 		return NULL;
 	      }
 
-	    if (kind != _cpp_FFK_HAS_INCLUDE)
+	    if (kind != _cpp_FFK_HAS_INCLUDE && kind != _cpp_FFK_HAS_EMBED)
 	      open_file_failed (pfile, file, angle_brackets, loc);
 	    else
 	      file->deferred_error = true;
@@ -615,11 +634,14 @@  _cpp_find_file (cpp_reader *pfile, const
 	  saw_bracket_include = true;
 	else if (file->dir == pfile->quote_include)
 	  saw_quote_include = true;
+	else if (file->dir == pfile->embed_include)
+	  saw_embed_include = true;
 	else
 	  continue;
 
 	entry
-	  = search_cache ((struct cpp_file_hash_entry *) *hash_slot, file->dir);
+	  = search_cache ((struct cpp_file_hash_entry *) *hash_slot,
+			  file->dir, is_embed);
 	if (entry)
 	  {
 	    found_in_cache = file->dir;
@@ -673,6 +695,17 @@  _cpp_find_file (cpp_reader *pfile, const
       entry->u.file = file;
       *hash_slot = (void *) entry;
     }
+  if (saw_embed_include
+      && pfile->embed_include != start_dir
+      && found_in_cache != pfile->embed_include)
+    {
+      entry = new_file_hash_entry (pfile);
+      entry->next = (struct cpp_file_hash_entry *) *hash_slot;
+      entry->start_dir = pfile->embed_include;
+      entry->location = loc;
+      entry->u.file = file;
+      *hash_slot = (void *) entry;
+    }
 
   return file;
 }
@@ -761,7 +794,7 @@  read_file_guts (cpp_reader *pfile, _cpp_
 
   if (pfile && regular && total != size && STAT_SIZE_RELIABLE (file->st))
     cpp_error_at (pfile, CPP_DL_WARNING, loc,
-	       "%s is shorter than expected", file->path);
+		  "%s is shorter than expected", file->path);
 
   file->buffer = _cpp_convert_input (pfile,
 				     input_charset,
@@ -872,6 +905,9 @@  has_unique_contents (cpp_reader *pfile,
       if (f == file)
 	continue; /* It'sa me!  */
 
+      if (f->embed)
+	continue;
+
       if ((import || f->once_only)
 	  && f->err_no == 0
 	  && f->st.st_mtime == file->st.st_mtime
@@ -1063,12 +1099,12 @@  search_path_head (cpp_reader *pfile, con
       && file->dir != &pfile->no_search_path)
     dir = file->dir->next;
   else if (angle_brackets)
-    dir = pfile->bracket_include;
+    dir = type == IT_EMBED ? pfile->embed_include : pfile->bracket_include;
   else if (type == IT_CMDLINE)
     /* -include and -imacros use the #include "" chain with the
        preprocessor's cwd prepended.  */
     return make_cpp_dir (pfile, "./", false);
-  else if (pfile->quote_ignores_source_dir)
+  else if (pfile->quote_ignores_source_dir && type != IT_EMBED)
     dir = pfile->quote_include;
   else
     return make_cpp_dir (pfile, dir_name_of_file (file),
@@ -1182,6 +1218,306 @@  cpp_probe_header_unit (cpp_reader *pfile
   return nullptr;
 }
 
+/* Try to load FNAME with #embed/__has_embed parameters PARAMS.
+   If !PARAMS->has_embed, return new token in pfile->directive_result
+   (first token) and rest in a pushed non-macro context.
+   Returns 0 for not found/errors, 1 for non-empty resource and 2
+   for empty resource.  */
+
+int
+_cpp_stack_embed (cpp_reader *pfile, const char *fname, bool angle,
+		  struct cpp_embed_params *params)
+{
+  cpp_dir *dir = search_path_head (pfile, fname, angle, IT_EMBED,
+				   params->has_embed);
+  if (!dir)
+    return 0;
+  _cpp_file *file = _cpp_find_file (pfile, fname, dir, angle,
+				    params->has_embed
+				    ? _cpp_FFK_HAS_EMBED : _cpp_FFK_EMBED,
+				    params->loc);
+  if (!file)
+    return 0;
+  if (file->dont_read || file->err_no)
+    return 0;
+  _cpp_file *orig_file = file;
+  if (file->buffer_valid
+      && (!S_ISREG (file->st.st_mode)
+	  || (file->limit < file->st.st_size + (size_t) 0
+	      && file->limit < params->limit)))
+    {
+      bool found = false;
+      if (S_ISREG (file->st.st_mode))
+	{
+	  while (file->next_file
+		 && file->next_file->embed
+		 && file->next_file->buffer_valid
+		 && file->next_file->dir == file->dir
+		 && strcmp (file->name, file->next_file->name) == 0
+		 && strcmp (file->path, file->next_file->path) == 0)
+	    {
+	      file = file->next_file;
+	      if (file->limit >= file->st.st_size + (size_t) 0
+		  || file->limit >= params->limit)
+		{
+		  found = true;
+		  break;
+		}
+	    }
+	}
+      if (!found)
+	{
+	  _cpp_file *file2 = make_cpp_file (file->dir, file->name);
+	  file2->path = xstrdup (file->path);
+	  file2->next_file = file->next_file;
+	  file2->embed = true;
+	  file->next_file = file2;
+	  file = file2;
+	}
+    }
+  if (!file->buffer_valid)
+    {
+      if (file->fd == -1 && !open_file (file))
+	{
+	  if (params->has_embed)
+	    file->deferred_error = true;
+	  else
+	    open_file_failed (pfile, file, 0, params->loc);
+	  return 0;
+	}
+      if (S_ISBLK (file->st.st_mode))
+	{
+	  if (params->has_embed)
+	    {
+	      close (file->fd);
+	      file->fd = -1;
+	      return 0;
+	    }
+	  cpp_error_at (pfile, CPP_DL_ERROR, params->loc,
+			"%s is a block device", file->path);
+	fail:
+	  close (file->fd);
+	  file->fd = -1;
+	  file->dont_read = true;
+	  return 0;
+	}
+
+      if (CPP_OPTION (pfile, deps.style)
+	  && !params->has_embed
+	  && file == orig_file
+	  && file->path[0])
+	deps_add_dep (pfile->deps, file->path);
+
+      bool regular = S_ISREG (file->st.st_mode) != 0;
+      ssize_t size, total, count;
+      uchar *buf;
+      if (regular)
+	{
+	  cpp_num_part limit;
+	  if (file->st.st_size + (cpp_num_part) 0 < params->limit)
+	    limit = file->st.st_size;
+	  else
+	    limit = params->limit;
+	  if (params->has_embed)
+	    return limit != 0 ? 1 : 2;
+	  if (limit > INTTYPE_MAXIMUM (ssize_t))
+	    {
+	      cpp_error_at (pfile, CPP_DL_ERROR, params->loc,
+			    "%s is too large", file->path);
+	      goto fail;
+	    }
+	  file->limit = limit;
+	  size = limit;
+	}
+      else if (params->has_embed)
+	return 2;
+      else if (params->limit > 8 * 1024)
+	size = 8 * 1024;
+      else
+	size = params->limit;
+      buf = XNEWVEC (uchar, size ? size : 1);
+      total = 0;
+
+      while ((count = read (file->fd, buf + total, size - total)) > 0)
+	{
+	  total += count;
+	  if (total == size)
+	    {
+	      if (regular || size + (cpp_num_part) 0 == params->limit)
+		break;
+	      size = (size_t) size * 2;
+	      if (size < 0)
+		{
+		  if (params->limit <= INTTYPE_MAXIMUM (ssize_t))
+		    size = params->limit;
+		  else
+		    {
+		      cpp_error_at (pfile, CPP_DL_ERROR, params->loc,
+				    "%s is too large", file->path);
+		      free (buf);
+		      goto fail;
+		    }
+		}
+	      else if (size + (cpp_num_part) 0 > params->limit)
+		size = params->limit;
+	      buf = XRESIZEVEC (uchar, buf, size);
+	    }
+	}
+
+      if (count < 0)
+	{
+	  cpp_errno_filename (pfile, CPP_DL_ERROR, file->path, params->loc);
+	  free (buf);
+	  goto fail;
+	}
+
+      if (regular && total != size && STAT_SIZE_RELIABLE (file->st))
+	{
+	  cpp_error_at (pfile, CPP_DL_WARNING, params->loc,
+			"%s is shorter than expected", file->path);
+	  file->limit = total;
+	}
+      else if (!regular)
+	file->limit = total;
+
+      file->buffer_start = buf;
+      file->buffer = buf;
+      file->buffer_valid = 1;
+      close (file->fd);
+      file->fd = -1;
+    }
+  else if (params->has_embed)
+    return file->limit && params->limit ? 1 : 2;
+
+  size_t limit = file->limit;
+  if (params->limit < limit)
+    limit = params->limit;
+
+  /* For sizes larger than say 64 bytes, this is just a temporary
+     solution, we should emit a single new token which the FEs will
+     handle as an optimization.  */
+  size_t max = INTTYPE_MAXIMUM (size_t) / sizeof (cpp_token);
+  if (limit > max / 2
+      || (limit
+	  ? (params->prefix.count > max
+	     || params->suffix.count > max
+	     || (limit * 2 + params->prefix.count
+		 + params->suffix.count > max))
+	  : params->if_empty.count > max))
+    {
+      cpp_error_at (pfile, CPP_DL_ERROR, params->loc,
+		    "%s is too large", file->path);
+      return 0;
+    }
+
+  size_t len = 0;
+  for (size_t i = 0; i < limit; ++i)
+    {
+      if (file->buffer[i] < 10)
+	len += 2;
+      else if (file->buffer[i] < 100)
+	len += 3;
+#if UCHAR_MAX == 255
+      else
+	len += 4;
+#else
+      else if (file->buffer[i] < 1000)
+	len += 4;
+      else
+	{
+	  char buf[64];
+	  len += sprintf (buf, "%d", file->buffer[i]) + 1;
+	}
+#endif
+      if (len > INTTYPE_MAXIMUM (ssize_t))
+	{
+	  cpp_error_at (pfile, CPP_DL_ERROR, params->loc,
+			"%s is too large", file->path);
+	  return 0;
+	}
+    }
+  uchar *s = len ? _cpp_unaligned_alloc (pfile, len) : NULL;
+  _cpp_buff *tok_buff = NULL;
+  cpp_token *toks = NULL, *tok = &pfile->directive_result;
+  size_t count = 0;
+  if (limit)
+    count = (params->prefix.count + limit * 2 - 1
+	     + params->suffix.count) - 1;
+  else if (params->if_empty.count)
+    count = params->if_empty.count - 1;
+  if (count)
+    {
+      tok_buff = _cpp_get_buff (pfile, count * sizeof (cpp_token));
+      toks = (cpp_token *) tok_buff->base;
+    }
+  cpp_embed_params_tokens *prefix
+    = limit ? &params->prefix : &params->if_empty;
+  if (prefix->count)
+    {
+      *tok = *prefix->base_run.base;
+      tok = toks;
+      tokenrun *cur_run = &prefix->base_run;
+      while (cur_run)
+	{
+	  size_t cnt = (cur_run->next ? cur_run->limit
+			: prefix->cur_token) - cur_run->base;
+	  cpp_token *t = cur_run->base;
+	  if (cur_run == &prefix->base_run)
+	    {
+	      t++;
+	      cnt--;
+	    }
+	  memcpy (tok, t, cnt * sizeof (cpp_token));
+	  tok += cnt;
+	  cur_run = cur_run->next;
+	}
+    }
+  for (size_t i = 0; i < limit; ++i)
+    {
+      tok->src_loc = params->loc;
+      tok->type = CPP_NUMBER;
+      tok->flags = NO_EXPAND;
+      if (i == 0)
+	tok->flags |= PREV_WHITE;
+      tok->val.str.text = s;
+      tok->val.str.len = sprintf ((char *) s, "%d", file->buffer[i]);
+      s += tok->val.str.len + 1;
+      if (tok == &pfile->directive_result)
+	tok = toks;
+      else
+	tok++;
+      if (i < limit - 1)
+	{
+	  tok->src_loc = params->loc;
+	  tok->type = CPP_COMMA;
+	  tok->flags = NO_EXPAND;
+	  tok++;
+	}
+    }
+  if (limit && params->suffix.count)
+    {
+      tokenrun *cur_run = &params->suffix.base_run;
+      cpp_token *orig_tok = tok;
+      while (cur_run)
+	{
+	  size_t cnt = (cur_run->next ? cur_run->limit
+			: params->suffix.cur_token) - cur_run->base;
+	  cpp_token *t = cur_run->base;
+	  memcpy (tok, t, cnt * sizeof (cpp_token));
+	  tok += cnt;
+	  cur_run = cur_run->next;
+	}
+      orig_tok->flags |= PREV_WHITE;
+    }
+  pfile->directive_result.flags |= PREV_WHITE;
+  if (count)
+    {
+      _cpp_push_token_context (pfile, NULL, toks, count);
+      pfile->context->buff = tok_buff;
+    }
+  return limit ? 1 : 2;
+}
+
 /* Retrofit the just-entered main file asif it was an include.  This
    will permit correct include_next use, and mark it as a system
    header if that's where it resides.  We use filesystem-appropriate
@@ -1257,9 +1593,11 @@  open_file_failed (cpp_reader *pfile, _cp
 /* Search in the chain beginning at HEAD for a file whose search path
    started at START_DIR != NULL.  */
 static struct cpp_file_hash_entry *
-search_cache (struct cpp_file_hash_entry *head, const cpp_dir *start_dir)
+search_cache (struct cpp_file_hash_entry *head, const cpp_dir *start_dir,
+	      bool is_embed)
 {
-  while (head && head->start_dir != start_dir)
+  while (head && (head->start_dir != start_dir
+		  || head->u.file->embed != is_embed))
     head = head->next;
 
   return head;
@@ -1693,21 +2031,24 @@  _cpp_get_file_name (_cpp_file *file)
 struct stat *
 _cpp_get_file_stat (_cpp_file *file)
 {
-    return &file->st;
+  return &file->st;
 }
 
 /* Set the include chain for "" to QUOTE, for <> to BRACKET.  If
    QUOTE_IGNORES_SOURCE_DIR, then "" includes do not look in the
    directory of the including file.
 
-   If BRACKET does not lie in the QUOTE chain, it is set to QUOTE.  */
+   If BRACKET does not lie in the QUOTE chain, it is set to QUOTE.
+
+   EMBED is include chain for #embed <>.  */
 void
 cpp_set_include_chains (cpp_reader *pfile, cpp_dir *quote, cpp_dir *bracket,
-			int quote_ignores_source_dir)
+			cpp_dir *embed, int quote_ignores_source_dir)
 {
   pfile->quote_include = quote;
   pfile->bracket_include = quote;
   pfile->quote_ignores_source_dir = quote_ignores_source_dir;
+  pfile->embed_include = embed;
 
   for (; quote; quote = quote->next)
     {
@@ -1716,6 +2057,11 @@  cpp_set_include_chains (cpp_reader *pfil
       if (quote == bracket)
 	pfile->bracket_include = bracket;
     }
+  for (; embed; embed = embed->next)
+    {
+      embed->name_map = NULL;
+      embed->len = strlen (embed->name);
+    }
 }
 
 /* Append the file name to the directory to create the path, but don't
--- libcpp/init.cc.jj	2024-08-05 13:04:54.053114103 +0200
+++ libcpp/init.cc	2024-08-15 10:29:44.500064200 +0200
@@ -437,6 +437,7 @@  static const struct builtin_macro builti
   B("__has_builtin",	 BT_HAS_BUILTIN,   true),
   B("__has_include",	 BT_HAS_INCLUDE,   true),
   B("__has_include_next",BT_HAS_INCLUDE_NEXT,   true),
+  B("__has_embed",	 BT_HAS_EMBED, true),
   B("__has_feature",	 BT_HAS_FEATURE, true),
   B("__has_extension",	 BT_HAS_EXTENSION, true),
   /* Keep builtins not used for -traditional-cpp at the end, and
@@ -623,6 +624,10 @@  cpp_init_builtins (cpp_reader *pfile, in
   else
     _cpp_define_builtin (pfile, "__STDC_HOSTED__ 0");
 
+  _cpp_define_builtin (pfile, "__STDC_EMBED_NOT_FOUND__ 0");
+  _cpp_define_builtin (pfile, "__STDC_EMBED_FOUND__ 1");
+  _cpp_define_builtin (pfile, "__STDC_EMBED_EMPTY__ 2");
+
   if (CPP_OPTION (pfile, objc))
     _cpp_define_builtin (pfile, "__OBJC__ 1");
 }
--- libcpp/lex.cc.jj	2024-08-12 10:53:16.906444014 +0200
+++ libcpp/lex.cc	2024-08-15 10:29:44.518063975 +0200
@@ -5259,7 +5259,20 @@  cpp_directive_only_process (cpp_reader *
 		     error messages. */
 		  buffer->line_base -= pos - line_start;
 
-		  _cpp_handle_directive (pfile, line_start + 1 != pos);
+		  if (_cpp_handle_directive (pfile, line_start + 1 != pos) == 2)
+		    {
+		      if (pfile->directive_result.type != CPP_PADDING)
+			cb (pfile, CPP_DO_token, data,
+			    &pfile->directive_result, pfile->directive_result.src_loc);
+		      if (pfile->context->prev)
+			{
+			  gcc_assert (pfile->context->tokens_kind == TOKENS_KIND_DIRECT);
+			  for (const cpp_token *tok = FIRST (pfile->context).token;
+			       tok != LAST (pfile->context).token; ++tok)
+			    cb (pfile, CPP_DO_token, data, tok, tok->src_loc);
+			  _cpp_pop_context (pfile);
+			}
+		    }
 
 		  /* Sanitize the line settings.  Duplicate #include's can
 		     mess things up. */
--- libcpp/macro.cc.jj	2024-08-05 13:04:54.096113532 +0200
+++ libcpp/macro.cc	2024-08-15 10:29:44.532063800 +0200
@@ -371,8 +371,8 @@  unsigned num_macro_tokens_counter = 0;
 
 /* Wrapper around cpp_get_token to skip CPP_PADDING tokens
    and not consume CPP_EOF.  */
-static const cpp_token *
-cpp_get_token_no_padding (cpp_reader *pfile)
+const cpp_token *
+_cpp_get_token_no_padding (cpp_reader *pfile)
 {
   for (;;)
     {
@@ -385,32 +385,32 @@  cpp_get_token_no_padding (cpp_reader *pf
     }
 }
 
-/* Handle meeting "__has_include" builtin macro.  */
+/* Helper function for builtin_has_include and builtin_has_embed.  */
 
-static int
-builtin_has_include (cpp_reader *pfile, cpp_hashnode *op, bool has_next)
+static char *
+builtin_has_include_1 (cpp_reader *pfile, const char *name, bool *paren,
+		       bool *bracket, location_t *loc)
 {
-  int result = 0;
-
   if (!pfile->state.in_directive)
     cpp_error (pfile, CPP_DL_ERROR,
-	       "\"%s\" used outside of preprocessing directive",
-	       NODE_NAME (op));
+	       "\"%s\" used outside of preprocessing directive", name);
 
   pfile->state.angled_headers = true;
   const auto sav_padding = pfile->state.directive_wants_padding;
   pfile->state.directive_wants_padding = true;
-  const cpp_token *token = cpp_get_token_no_padding (pfile);
-  bool paren = token->type == CPP_OPEN_PAREN;
-  if (paren)
-    token = cpp_get_token_no_padding (pfile);
+  const cpp_token *token = _cpp_get_token_no_padding (pfile);
+  *paren = token->type == CPP_OPEN_PAREN;
+  if (*paren)
+    token = _cpp_get_token_no_padding (pfile);
   else
     cpp_error (pfile, CPP_DL_ERROR,
-	       "missing '(' before \"%s\" operand", NODE_NAME (op));
+	       "missing '(' before \"%s\" operand", name);
   pfile->state.angled_headers = false;
   pfile->state.directive_wants_padding = sav_padding;
 
-  bool bracket = token->type != CPP_STRING;
+  if (loc)
+    *loc = token->src_loc;
+  *bracket = token->type != CPP_STRING;
   char *fname = NULL;
   if (token->type == CPP_STRING || token->type == CPP_HEADER_NAME)
     {
@@ -422,7 +422,19 @@  builtin_has_include (cpp_reader *pfile,
     fname = _cpp_bracket_include (pfile);
   else
     cpp_error (pfile, CPP_DL_ERROR,
-	       "operator \"%s\" requires a header-name", NODE_NAME (op));
+	       "operator \"%s\" requires a header-name", name);
+  return fname;
+}
+
+/* Handle meeting "__has_include" builtin macro.  */
+
+static int
+builtin_has_include (cpp_reader *pfile, cpp_hashnode *op, bool has_next)
+{
+  int result = 0;
+  bool paren, bracket;
+  char *fname = builtin_has_include_1 (pfile, (const char *) NODE_NAME (op),
+				       &paren, &bracket, NULL);
 
   if (fname)
     {
@@ -437,13 +449,70 @@  builtin_has_include (cpp_reader *pfile,
     }
 
   if (paren
-      && cpp_get_token_no_padding (pfile)->type != CPP_CLOSE_PAREN)
+      && _cpp_get_token_no_padding (pfile)->type != CPP_CLOSE_PAREN)
     cpp_error (pfile, CPP_DL_ERROR,
 	       "missing ')' after \"%s\" operand", NODE_NAME (op));
 
   return result;
 }
 
+/* Handle the "__has_embed" expression.  */
+
+static int
+builtin_has_embed (cpp_reader *pfile)
+{
+  int result = 0;
+  bool paren, bracket;
+  struct cpp_embed_params params = {};
+  char *fname = builtin_has_include_1 (pfile, "__has_embed", &paren,
+				       &bracket, &params.loc);
+
+  if (fname)
+    {
+      params.has_embed = true;
+      auto save_in_directive = pfile->state.in_directive;
+      auto save_angled_headers = pfile->state.angled_headers;
+      auto save_directive_wants_padding = pfile->state.directive_wants_padding;
+      auto save_op_stack = pfile->op_stack;
+      auto save_op_limit = pfile->op_limit;
+      auto save_skip_eval = pfile->state.skip_eval;
+      auto save_mi_ind_cmacro = pfile->mi_ind_cmacro;
+      /* Tell the lexer this is an embed directive.  */
+      pfile->state.in_directive = 3;
+      pfile->state.angled_headers = false;
+      pfile->state.directive_wants_padding = false;
+      pfile->op_stack = NULL;
+      pfile->op_limit = NULL;
+      bool ok = _cpp_parse_embed_params (pfile, &params);
+      free (pfile->op_stack);
+      pfile->state.in_directive = save_in_directive;
+      pfile->state.angled_headers = save_angled_headers;
+      pfile->state.directive_wants_padding = save_directive_wants_padding;
+      pfile->op_stack = save_op_stack;
+      pfile->op_limit = save_op_limit;
+      pfile->state.skip_eval = save_skip_eval;
+      pfile->mi_ind_cmacro = save_mi_ind_cmacro;
+
+      if (!*fname)
+	{
+	  cpp_error_with_line (pfile, CPP_DL_ERROR, params.loc, 0,
+			       "empty filename in '%s'", "__has_embed");
+	  ok = false;
+	}
+
+      /* Do not do the lookup if we're skipping, that's unnecessary
+	 IO.  */
+      if (ok && !pfile->state.skip_eval)
+	result = _cpp_stack_embed (pfile, fname, bracket, &params);
+
+      XDELETEVEC (fname);
+    }
+  else if (paren)
+    _cpp_get_token_no_padding (pfile);
+
+  return result;
+}
+
 /* Emits a warning if NODE is a macro defined in the main file that
    has not been used.  */
 int
@@ -681,6 +750,16 @@  _cpp_builtin_macro_text (cpp_reader *pfi
 				    node->value.builtin == BT_HAS_INCLUDE_NEXT);
       break;
 
+    case BT_HAS_EMBED:
+      if (CPP_OPTION (pfile, traditional))
+	{
+	  cpp_error (pfile, CPP_DL_ERROR, /* FIXME should be DL_SORRY */
+		     "'__has_embed' not supported in traditional C");
+	  break;
+	}
+      number = builtin_has_embed (pfile);
+      break;
+
     case BT_HAS_FEATURE:
     case BT_HAS_EXTENSION:
       number = pfile->cb.has_feature (pfile,
--- gcc/doc/cppdiropts.texi.jj	2024-08-05 13:04:53.715118584 +0200
+++ gcc/doc/cppdiropts.texi	2024-08-15 10:29:44.545063638 +0200
@@ -152,3 +152,12 @@  Do not search for header files in the C+
 but do still search the other standard directories.  (This option is
 used when building the C++ library.)
 
+@opindex embed-dir
+@item --embed-dir=@var{dir}
+Append @var{dir} directory to the list of searched directories for
+@code{#embed} preprocessing directive or @code{__has_embed} macro.
+There are no default directories for @code{#embed}.
+
+If @var{dir} begins with @samp{=} or @code{$SYSROOT}, then the @samp{=}
+or @code{$SYSROOT} is replaced by the sysroot prefix; see
+@option{--sysroot} and @option{-isysroot}.
--- gcc/doc/cpp.texi.jj	2024-08-05 13:04:53.715118584 +0200
+++ gcc/doc/cpp.texi	2024-08-15 10:29:44.567063363 +0200
@@ -82,6 +82,7 @@  useful on its own.
 * Diagnostics::
 * Line Control::
 * Pragmas::
+* Binary Resource Inclusion::
 * Other Directives::
 * Preprocessor Output::
 * Traditional Mode::
@@ -3204,6 +3205,7 @@  directive}: @samp{#if}, @samp{#ifdef} or
 * @code{__has_feature}::
 * @code{__has_extension}::
 * @code{__has_include}::
+* @code{__has_embed}::
 @end menu
 
 @node Ifdef
@@ -3643,6 +3645,36 @@  but not with others that don't.
 #endif
 @end smallexample
 
+@node @code{__has_embed}
+@subsection @code{__has_embed}
+@cindex @code{__has_embed}
+
+The special operator @code{__has_embed (@var{operands})} may be used in
+@samp{#if} and @samp{#elif} expressions to test whether a binary resource
+specified by the first operand with optional @samp{#embed} parameters can
+be included using the @samp{#embed} directive (@pxref{Binary Resource
+Inclusion}) with the same parameters.  The operator returns
+@code{__STDC_EMBED_NOT_FOUND__} if either the binary resource does not exist
+or at least one of the parameters is not supported by the implementation,
+@code{__STDC_EMBED_FOUND__} if all the parameters are supported and the
+resource is not empty and finally @code{__STDC_EMBED_EMPTY__} if all the
+parameters are supported and the resource is empty.
+The support of @code{__has_embed} operator can be tested with @samp{#ifdef}
+etc. similarly to @code{__has_include} and the same rules on how to
+test it apply.  @code{__FILE__} can be often used to test if an
+implementation supports some implementation defined parameter, e.g.@:
+
+@smallexample
+#ifdef __has_embed
+#if __has_embed (__FILE__ limit (4) myvendor::myattr (42)) != __STDC_EMBED_NOT_FOUND__
+#embed "foo.dat" limit (4) myvendor::myattr (42)
+#endif
+#endif
+@end smallexample
+
+The @code{__has_embed} operator is not supported in the Traditional Mode
+(@pxref{Traditional Mode}).
+
 @node Deleted Code
 @section Deleted Code
 @cindex commenting out code
@@ -3893,6 +3925,61 @@  These pragmas are accepted, but have no
 
 @end ftable
 
+@node Binary Resource Inclusion
+@chapter Binary Resource Inclusion
+
+@cindex embed directive
+
+The @samp{#embed} directive as specified in the C23 standard allows
+efficient inclusion of binary data, usually in initializers of arrays.
+GCC supports this directive in C23 mode and as an extension in older C
+versions and in C++.
+
+Similarly to the @samp{#include} directive (@pxref{Include Syntax})
+the first argument of the directive is a filename in the same forms
+as @samp{#include}.
+
+@table @code
+@item #embed <@var{file}>
+If @var{file} is an absolute filename, this includes the mentioned
+file, otherwise searches it in directories specified by the
+@option{--embed-dir=} command line option for the @var{file}.
+
+@item #embed "@var{file}"
+This variant searches @var{file} in the same directory as the source
+file which uses the @code{#embed} directive and only if not found there
+continues searching directories specified by the @option{--embed-dir=}
+command line option.
+@end table
+
+The @code{#embed} directive is expanded as if it was a sequence of
+integer literals from 0 to @code{UCHAR_MAX} separated by commas, e.g.@:
+@code{#embed __FILE__ limit(4)}
+could act as if it expanded to
+@code{35,101,109,98}.  No character set conversion is performed.
+
+Optional embed parameters can be specified after the required filename
+argument.  There are either standard attributes, specified by an
+identifier or identifier prefixed and suffixed by 2 underscores (both
+treated the same), followed by parameter argument in parentheses, like
+@code{#embed "foo.dat" limit(1) __prefix__(32, ) suffix(, 0)}
+with currently supported standard parameters @code{limit}, @code{prefix},
+@code{suffix} and @code{if_empty}, or implementation defined parameters
+specified by a unique vendor prefix followed by @code{::} followed by
+name of the parameter.  GCC will use the @code{gnu} prefix but currently
+doesn't support any extensions.
+
+The @code{limit} parameter argument is a constant expression which
+specifies the maximum number of bytes included by the directive,
+@code{prefix} and @code{suffix} arguments are balanced token sequences
+which are prepended and appended to the integer literal sequence if
+that sequence is not empty and @code{if_empty} argument is balanced token
+sequence which is used as expansion for @code{#embed} directive if the
+resource is empty.
+
+The @code{#embed} directive is not supported in the Traditional Mode
+(@pxref{Traditional Mode}).
+
 @node Other Directives
 @chapter Other Directives
 
--- gcc/doc/invoke.texi.jj	2024-08-14 18:19:28.855127977 +0200
+++ gcc/doc/invoke.texi	2024-08-15 10:29:44.577063239 +0200
@@ -722,6 +722,7 @@  Objective-C and Objective-C++ Dialects}.
 -iplugindir=@var{dir}  -iprefix @var{file}
 -iquote @var{dir}  -isysroot @var{dir}  -isystem @var{dir}
 -iwithprefix @var{dir}  -iwithprefixbefore @var{dir}
+--embed-dir=@var{dir}
 -L@var{dir}  -no-canonical-prefixes  --no-sysroot-suffix
 -nostdinc  -nostdinc++  --sysroot=@var{dir}}
 
--- gcc/gcc.cc.jj	2024-08-05 13:04:53.804117404 +0200
+++ gcc/gcc.cc	2024-08-15 10:29:44.596063001 +0200
@@ -1248,7 +1248,7 @@  static const char *cpp_unique_options =
  %{remap} %{%:debug-level-gt(2):-dD}\
  %{!iplugindir*:%{fplugin*:%:find-plugindir()}}\
  %{H} %C %{D*&U*&A*} %{i*} %Z %i\
- %{E|M|MM:%W{o*}}\
+ %{E|M|MM:%W{o*}} %{-embed*}\
  %{fdeps-format=*:%{!fdeps-file=*:-fdeps-file=%:join(%{!o:%b.ddi}%{o*:%.ddi%*})}}\
  %{fdeps-format=*:%{!fdeps-target=*:-fdeps-target=%:join(%{!o:%b.o}%{o*:%.o%*})}}";
 
--- gcc/genmatch.cc.jj	2024-08-05 13:04:53.821117179 +0200
+++ gcc/genmatch.cc	2024-08-15 10:29:44.606062877 +0200
@@ -5634,7 +5634,7 @@  main (int argc, char **argv)
   dir->name = getpwd ();
   if (!dir->name)
     dir->name = ASTRDUP (".");
-  cpp_set_include_chains (r, dir, NULL, false);
+  cpp_set_include_chains (r, dir, NULL, NULL, false);
 
   if (!cpp_read_main_file (r, input))
     return 1;
--- gcc/incpath.h.jj	2024-08-05 13:04:53.927115773 +0200
+++ gcc/incpath.h	2024-08-15 10:29:44.622062677 +0200
@@ -24,6 +24,7 @@  enum incpath_kind {
   INC_BRACKET,   /* include <foo> */
   INC_SYSTEM,    /* sys-include */
   INC_AFTER,	 /* post-sysinclude  */
+  INC_EMBED,     /* embed <foo> */
   INC_MAX
 };
 
--- gcc/incpath.cc.jj	2024-08-05 13:04:53.927115773 +0200
+++ gcc/incpath.cc	2024-08-15 10:29:44.626062627 +0200
@@ -360,6 +360,7 @@  merge_include_chains (const char *sysroo
       add_sysroot_to_chain (sysroot, INC_BRACKET);
       add_sysroot_to_chain (sysroot, INC_SYSTEM);
       add_sysroot_to_chain (sysroot, INC_AFTER);
+      add_sysroot_to_chain (sysroot, INC_EMBED);
     }
 
   /* Join the SYSTEM and AFTER chains.  Remove duplicates in the
@@ -383,6 +384,10 @@  merge_include_chains (const char *sysroo
     = remove_duplicates (pfile, heads[INC_QUOTE], heads[INC_SYSTEM],
 			 heads[INC_BRACKET], verbose);
 
+  /* Remove duplicates from EMBED that are in itself.  */
+  heads[INC_EMBED]
+    = remove_duplicates (pfile, heads[INC_EMBED], 0, 0, verbose);
+
   /* If verbose, print the list of dirs to search.  */
   if (verbose)
     {
@@ -398,6 +403,13 @@  merge_include_chains (const char *sysroo
 	  fprintf (stderr, " %s\n", p->name);
 	}
       fprintf (stderr, _("End of search list.\n"));
+      if (heads[INC_EMBED])
+	{
+	  fprintf (stderr, _("#embed <...> search starts here:\n"));
+	  for (p = heads[INC_EMBED]; p; p = p->next)
+	    fprintf (stderr, " %s\n", p->name);
+	  fprintf (stderr, _("End of #embed search list.\n"));
+	}
     }
 }
 
@@ -506,7 +518,7 @@  register_include_chains (cpp_reader *pfi
   merge_include_chains (sysroot, pfile, verbose);
 
   cpp_set_include_chains (pfile, heads[INC_QUOTE], heads[INC_BRACKET],
-			  quote_ignores_source_dir);
+			  heads[INC_EMBED], quote_ignores_source_dir);
 }
 
 /* Return the current chain of cpp dirs.  */
--- gcc/c-family/c.opt.jj	2024-08-14 18:19:28.687129948 +0200
+++ gcc/c-family/c.opt	2024-08-15 10:33:55.294934218 +0200
@@ -66,6 +66,16 @@  C ObjC C++ ObjC++ Separate Alias(d)
 -dump=
 C ObjC C++ ObjC++ Joined Alias(d)
 
+-embed-dir=
+C ObjC C++ ObjC++ Joined MissingArgError(missing filename after %qs)
+--embed-dir=<dir>	Add <dir> to the #embed path.
+
+-embed-directory
+C ObjC C++ ObjC++ Separate Alias(-embed-dir=) MissingArgError(missing path after %qs)
+
+-embed-directory=
+C ObjC C++ ObjC++ Joined Alias(-embed-dir=) MissingArgError(missing path after %qs)
+
 -imacros
 C ObjC C++ ObjC++ Separate Alias(imacros) MissingArgError(missing filename after %qs)
 
--- gcc/c-family/c-opts.cc.jj	2024-08-05 13:04:53.489121581 +0200
+++ gcc/c-family/c-opts.cc	2024-08-15 10:29:44.627062615 +0200
@@ -623,6 +623,10 @@  c_common_handle_option (size_t scode, co
       add_prefixed_path (arg, INC_BRACKET);
       break;
 
+    case OPT__embed_dir_:
+      add_path (xstrdup (arg), INC_EMBED, 0, true);
+      break;
+
     case OPT_lang_asm:
       cpp_set_lang (parse_in, CLK_ASM);
       cpp_opts->dollars_in_ident = false;
--- gcc/testsuite/c-c++-common/cpp/embed-1.c.jj	2024-08-15 10:29:44.628062602 +0200
+++ gcc/testsuite/c-c++-common/cpp/embed-1.c	2024-08-15 10:29:44.628062602 +0200
@@ -0,0 +1,333 @@ 
+/* { dg-do run } */
+/* { dg-options "--embed-dir=${srcdir}/c-c++-common/cpp/embed-dir" } */
+/* { dg-additional-options "-std=gnu99" { target c } } */
+
+#if !defined(__STDC_EMBED_NOT_FOUND__) || __STDC_EMBED_NOT_FOUND__ != 0
+#error "__STDC_EMBED_NOT_FOUND__ not defined or has invalid value"
+#endif
+
+#if __STDC_EMBED_FOUND__ != 1
+#error "__STDC_EMBED_FOUND__ not defined or has invalid value"
+#endif
+
+#if __STDC_EMBED_EMPTY__ != 2
+#error "__STDC_EMBED_EMPTY__ not defined or has invalid value"
+#endif
+
+#ifndef __has_embed
+#error "__has_embed not defined"
+#endif
+
+#if __has_embed (__FILE__) != __STDC_EMBED_FOUND__
+#error "__has_embed fail"
+#endif
+
+#if __has_embed (__FILE__ limit (NONEXISTENT_MACRO) prefix (1 2 3) __suffix__ () if_empty ({})) != __STDC_EMBED_EMPTY__
+#error "__has_embed fail"
+#endif
+
+#if __has_embed (__FILE__ __limit__ (1) __prefix__ () suffix (1 / 0) __if_empty__ ((({{[0[0{0{0(0(0)1)1}1}]]}})))) != __STDC_EMBED_FOUND__
+#error "__has_embed fail"
+#endif
+
+#if __has_embed (__FILE__ limit (0) gnu::nonexistent ({})) != __STDC_EMBED_NOT_FOUND__
+#error "__has_embed fail"
+#endif
+
+#if __has_embed (__FILE__ limit (0) __gnu__::__non_existent__ ({})) != __STDC_EMBED_NOT_FOUND__
+#error "__has_embed fail"
+#endif
+
+#if __has_embed (__FILE__ limit (0) gnu::__non_existent__ ({})) != __STDC_EMBED_NOT_FOUND__
+#error "__has_embed fail"
+#endif
+
+#if __has_embed (__FILE__ limit (0) non_existent_standard_arg (42)) != __STDC_EMBED_NOT_FOUND__
+#error "__has_embed fail"
+#endif
+
+#if __has_embed ("non-existent-file" limit (NONEXISTENT_MACRO + 1)) != __STDC_EMBED_NOT_FOUND__
+#error "__has_embed fail"
+#endif
+
+#if __has_embed ("embed-1.c" limit (0)) != __STDC_EMBED_EMPTY__
+#errror "__has_embed fail"
+#endif
+
+#define E1 "embed-1.c"
+#define E2 limit (
+#define E3 1)
+#if __has_embed (E1 E2 E3) != __STDC_EMBED_FOUND__
+#errror "__has_embed fail"
+#endif
+
+#if __has_embed (<embed-1.c>) != __STDC_EMBED_NOT_FOUND__
+#error "__has_embed fail"
+#endif
+
+#define E4 <embed-1.c>
+#define E5 limit
+#define E6 1)
+#if __has_embed ( \
+E4 \
+E5 ( \
+E6 \
+) != __STDC_EMBED_NOT_FOUND__
+#error "__has_embed fail"
+#endif
+
+#if __has_embed ("embed-1.inc") != __STDC_EMBED_FOUND__
+#errror "__has_embed fail"
+#endif
+
+#if __has_embed ( "embed-1.inc" __limit__ ( 7 - 7 ) ) != __STDC_EMBED_EMPTY__
+#errror "__has_embed fail"
+#endif
+
+#if __has_embed (<embed-1.inc>) != __STDC_EMBED_FOUND__
+#errror "__has_embed fail"
+#endif
+
+#if __has_embed (<embed-1.inc> limit(0)) != __STDC_EMBED_EMPTY__
+#errror "__has_embed fail"
+#endif
+
+#if __has_embed ("../empty.h") != __STDC_EMBED_EMPTY__
+#error "__has_embed fail"
+#endif
+
+#if __has_embed (<../empty.h>) != __STDC_EMBED_NOT_FOUND__
+#error "__has_embed fail"
+#endif
+
+#if __has_embed ("../../empty.h") != __STDC_EMBED_EMPTY__
+#error "__has_embed fail"
+#endif
+
+#if __has_embed (<../../empty.h>) != __STDC_EMBED_EMPTY__
+#error "__has_embed fail"
+#endif
+
+#if __has_embed ("../empty.h" __limit__ (42)) !=  __STDC_EMBED_EMPTY__
+#error "__has_embed fail"
+#endif
+
+#if __has_embed (<../empty.h> __limit__ (42)) !=  __STDC_EMBED_NOT_FOUND__
+#error "__has_embed fail"
+#endif
+
+#if __has_embed ("../../empty.h" limit (42)) !=  __STDC_EMBED_EMPTY__
+#error "__has_embed fail"
+#endif
+
+#if __has_embed (<../../empty.h> __limit__ (42)) !=  __STDC_EMBED_EMPTY__
+#error "__has_embed fail"
+#endif
+
+#if 1 + (2 + (3 + (4 + (5 + (6 + (7 + (8 + (9 + (10 + (11 + (12 + (13 + (14 + \
+    (15 + (16 + (17 + (18 + (19 + (20 + (21 + (22 + (23 + (24 + (25 + (26 + \
+    __has_embed (<magna-carta.txt> limit (17 + (16 + (15 + (14 + (13 \
+    + 12))))))))))))))))))))))))))))))) != 27 * 26 / 2 + __STDC_EMBED_FOUND__
+#error "__has_embed fail"
+#endif
+
+#if 0
+#if __has_embed (<non-existent-file.bin> limit (1 + 2 + 3 + 4)) != 42
+#error "__has_embed fail"
+#endif
+#endif
+
+#if (0 && __has_embed (<non-existent-file.bin> limit (3))) != 0
+#error "fail"
+#endif
+
+#if __STDC_VERSION__ >= 202311L || __cplusplus >= 201103L
+static_assert (
+#embed <embed-1.inc>
+== 'a', "");
+static_assert (
+#embed "embed-1.inc" \
+__limit__ (\
+0) __if_empty__ (42) __prefix__ ( \
+256 + ) __suffix__ (+ 17)
+== 42, "");
+static_assert (
+#embed "embed-1.inc" limit (42) if_empty (42) prefix (256 + ) suffix (+ 17)
+== 256 + 'a' + 17, "");
+#endif
+
+int a =
+#embed __FILE__ limit (1)
+;
+int b =
+#embed __FILE__ if_empty (42; int c = 0) limit (0)
+;
+const unsigned char magna_carta[] = {
+#embed <magna-carta.txt> prefix (/* This is a prefix */) suffix (, 0) if_empty (0)
+};
+const unsigned char d[] = {
+#define MAGNA_CARTA "magna-carta.txt"
+#define MAGNA_CARTA_PARAMS prefix (239, 187, 191,) \
+suffix (, 0) limit (15)
+#embed MAGNA_CARTA MAGNA_CARTA_PARAMS \
+\
+if_empty (0{1[2[3{4(5(6)7)8}9]0]1}2)
+};
+#ifndef __cplusplus
+const unsigned char e[] = {
+#embed MAGNA_CARTA __limit__ (42) __suffix__ (, [21] = 'X', [22] = 'X', [23] = 'X')
+};
+#endif
+int f;
+struct S { int a; long b; unsigned short c; long long d; } g = {
+#embed "magna-carta.txt" limit (4)
+};
+const unsigned char h[] = {
+#embed __FILE__ suffix (, 0)
+};
+struct T { int a; };
+struct U { unsigned short a; struct T b; long long c; };
+struct V { unsigned long long a; struct U b; short int c; int d; };
+struct V v = {
+#embed "magna-carta.txt" __limit__(4)__prefix__(42,)__suffix__(,-42)
+};
+#ifndef __cplusplus
+const unsigned char w[] = {
+#embed <magna-carta.txt> prefix([0] = 42, [72] =) limit(1500)
+};
+#endif
+const unsigned char x[] = {
+#define XIFEMPTY1 0, 1
+#define XIFEMPTY2 ,3,
+#define XIFEMPTY3 4
+#embed "../empty.h" if_empty (XIFEMPTY1,2 XIFEMPTY2 \
+XIFEMPTY3) prefix (5, 6, 7, ) suffix (, 8, 9)
+};
+const unsigned char y[] = {
+#embed <embed-3.c> suffix(,0)
+};
+const unsigned char z[] = {
+#embed "embed-3.c" suffix(,0)
+};
+
+#if 0
+#embed <non-existent-file.bin> limit (3)
+#endif
+
+#ifdef __cplusplus
+#define C "C"
+#else
+#define C
+#endif
+extern C void abort (void);
+#ifdef __cplusplus
+extern C const char *strstr (const char *, const char *);
+#else
+extern C char *strstr (const char *, const char *);
+#endif
+
+void
+foo (unsigned int a, unsigned long long b, unsigned char c, int d, int e)
+{
+  if (a != 'H' || b != 'e' || c != 'n' || d != 'r' || !e)
+    abort ();
+}
+
+int
+main ()
+{
+  if (a != '/' || b != 42 || c != 0)
+    abort ();
+  if (sizeof (magna_carta) != 17893 + 1
+      /* Allow for DOS line endings instead of Unix just in case.  */
+      && sizeof (magna_carta) != 17939 + 1)
+    abort ();
+  if (!strstr ((const char *) magna_carta, "imprisonétur"))
+    abort ();
+  if (sizeof (d) != 3 + 15 + 1
+      || d[0] != 239 || d[1] != 187 || d[2] != 191 || d[3 + 15] != 0)
+    abort ();
+#ifndef __cplusplus
+  if (sizeof (e) != 42 || e[21] != 'X' || e[22] != 'X' || e[23] != 'X')
+    abort ();
+#endif
+  f = (
+#embed "magna-carta.txt" limit (4) prefix (172 + ) suffix (+ 2)
+  );
+  if (f != 'r' + 2)
+    abort ();
+  if (g.a != 'H' || g.b != 'e' || g.c != 'n' || g.d != 'r')
+    abort ();
+  if (!strstr ((const char *) h, "imprisonétur")
+      || !strstr ((const char *) h, "blah blah"))
+    abort ();
+  if (v.a != 42 || v.b.a != 'H' || v.b.b.a != 'e'
+      || v.b.c != 'n' || v.c != 'r' || v.d != -42)
+    abort ();
+#ifndef __cplusplus
+  if (sizeof (w) != 1572 || w[0] != 42 || w[1] != 0 || w[71] != 0
+      || w[72] != 'H' || w[73] != 'e' || w[74] != 'n' || w[75] != 'r')
+    abort ();
+#endif
+  if (sizeof (x) != 5 || x[0] != 0 || x[1] != 1 || x[2] != 2
+      || x[3] != 3 || x[4] != 4)
+    abort ();
+  foo (
+#embed <magna-carta.txt> limit(5)
+  );
+  if (sizeof (y) > 100
+      || !strstr ((const char *) y, "Dummy file.")
+      || strstr ((const char *) y, "__gnu__::__non_existent_parameter"))
+    abort ();
+  if (sizeof (z) < 100
+      || strstr ((const char *) z, "Dummy file.")
+      || !strstr ((const char *) z, "__gnu__::__non_existent_parameter"))
+    abort ();
+  if (sizeof (
+#embed "embed-1.inc"
+      ) != sizeof (int))
+    abort ();
+#ifndef __cplusplus
+  if (_Generic (
+#embed "embed-1.inc" __limit__ (1) __suffix__ (, int: 42, default: 0)
+      ) != 42)
+    abort ();
+#endif
+#if __STDC_VERSION__ >= 202311L
+  typeof (
+#embed "embed-1.inc" limit (1)
+  ) j;
+  if (sizeof (j) != sizeof (int))
+    abort ();
+#elif __cplusplus >= 201103L
+  decltype (
+#embed "embed-1.inc" limit (1)
+  ) j;
+  if (sizeof (j) != sizeof (int))
+    abort ();
+#endif
+#if __has_embed ("embed-5.c" ds9000::element_type(short))
+  short meow[] = {
+    #embed "embed-5.c" ds9000::element_type(short)
+  };
+#elif __has_embed ("embed-5.c")
+  const unsigned char meow_bytes[] = {
+    #embed "embed-5.c"
+  };
+  short meow[sizeof (meow_bytes) / sizeof (short)] = {};
+  for (int i = 0; i < (int) (sizeof (meow) / sizeof (short)); i++)
+    meow[i] = (meow_bytes[i * 2] << 8) | meow_bytes[i * 2 + 1];
+#else
+  #error "cannot find embed-5.c resource"
+#endif
+  if (meow[0] != ('/' << 8) + '*')
+    abort ();
+#if __has_embed("././././embed-1.c" __limit__(1))
+  if (
+		#embed		"././././embed-1.c" /* This */ limit /* is */ ( /* a */ 1 /*comment*/) // .
+      != '/')
+    abort ();
+#else
+#error "__has_embed fail"
+#endif
+}
--- gcc/testsuite/c-c++-common/cpp/embed-2.c.jj	2024-08-15 10:29:44.628062602 +0200
+++ gcc/testsuite/c-c++-common/cpp/embed-2.c	2024-08-15 11:08:00.231497134 +0200
@@ -0,0 +1,5 @@ 
+/* { dg-do run } */
+/* { dg-options "--embed-directory ${srcdir}/c-c++-common/cpp/embed-dir -save-temps" } */
+/* { dg-additional-options "-std=gnu99" { target c } } */
+
+#include "embed-1.c"
--- gcc/testsuite/c-c++-common/cpp/embed-3.c.jj	2024-08-15 10:29:44.628062602 +0200
+++ gcc/testsuite/c-c++-common/cpp/embed-3.c	2024-08-15 10:29:44.628062602 +0200
@@ -0,0 +1,83 @@ 
+/* { dg-do preprocess } */
+/* { dg-options "" } */
+
+#embed __FILE__ , limit(1) /* { dg-error "expected parameter name" } */
+#embed __FILE__ limit(1)) /* { dg-error "expected parameter name" } */
+#embed __FILE__ limit(1) limit(1) /* { dg-error "duplicate embed parameter 'limit'" } */
+#embed __FILE__ limit(1) prefix() prefix() /* { dg-error "duplicate embed parameter 'prefix'" } */
+#embed __FILE__ limit(1) suffix(1 2 3) __suffix__() /* { dg-error "duplicate embed parameter 'suffix'" } */
+#embed __FILE__ if_empty ("this") if_empty("that") limit(1) /* { dg-error "duplicate embed parameter 'if_empty'" } */
+#embed __FILE__ non_existent_parameter (42) limit(1) /* { dg-error "unknown embed parameter 'non_existent_parameter'" } */
+#embed __FILE__ limit(1) gnu::non_existent_parameter /* { dg-error "unknown embed parameter 'gnu::non_existent_parameter'" } */
+#embed __FILE__ limit(1) __gnu__::__non_existent_parameter /* { dg-error "unknown embed parameter 'gnu::__non_existent_parameter'" } */
+#embed __FILE__ limit(1) gnu__::__non_existent_parameter__ /* { dg-error "unknown embed parameter 'gnu__::non_existent_parameter'" } */
+#embed __FILE__ limit prefix() suffix() /* { dg-error "expected '\\\('" } */
+#embed __FILE__ __prefix__ suffix() limit(1) /* { dg-error "expected '\\\('" } */
+#embed __FILE__ prefix() suffix limit(1) /* { dg-error "expected '\\\('" } */
+#embed __FILE__ if_empty limit(1) /* { dg-error "expected '\\\('" } */
+#embed __FILE__ limit (1 / 0) /* { dg-error "division by zero in #embed" } */
+#embed __FILE__ limit (+ + +) /* { dg-error "operator '\\\+' has no right operand" } */
+#embed __FILE__ limit(1) prefix(() /* { dg-error "unbalanced '\\\('" } */
+#embed __FILE__ limit(1) prefix(({[})]) /* { dg-error "unbalanced '\\\('" } */
+/* { dg-error "unbalanced '\\\)'" "" { target *-*-* } .-1 } */
+/* { dg-error "unbalanced '\\\{'" "" { target *-*-* } .-2 } */
+/* { dg-error "unbalanced '\\\}'" "" { target *-*-* } .-3 } */
+#embed __FILE__ limit(1) prefix(]) /* { dg-error "unbalanced '\\\]'" } */
+#embed __FILE__ limit(1) prefix([) /* { dg-error "unbalanced '\\\)'" } */
+/* { dg-error "unbalanced '\\\['" "" { target *-*-* } .-1 } */
+/* { dg-error "unbalanced '\\\('" "" { target *-*-* } .-2 } */
+#embed __FILE__ limit(1) __suffix__(() /* { dg-error "unbalanced '\\\('" } */
+#embed __FILE__ limit(1) __suffix__(({[})]) /* { dg-error "unbalanced '\\\('" } */
+/* { dg-error "unbalanced '\\\)'" "" { target *-*-* } .-1 } */
+/* { dg-error "unbalanced '\\\{'" "" { target *-*-* } .-2 } */
+/* { dg-error "unbalanced '\\\}'" "" { target *-*-* } .-3 } */
+#embed __FILE__ limit(1) suffix([) /* { dg-error "unbalanced '\\\)'" } */
+/* { dg-error "unbalanced '\\\['" "" { target *-*-* } .-1 } */
+/* { dg-error "unbalanced '\\\('" "" { target *-*-* } .-2 } */
+#embed __FILE__ limit(1) if_empty(() /* { dg-error "unbalanced '\\\('" } */
+#embed __FILE__ limit(1) __if_empty__(({[})]) /* { dg-error "unbalanced '\\\('" } */
+/* { dg-error "unbalanced '\\\)'" "" { target *-*-* } .-1 } */
+/* { dg-error "unbalanced '\\\{'" "" { target *-*-* } .-2 } */
+/* { dg-error "unbalanced '\\\}'" "" { target *-*-* } .-3 } */
+#embed __FILE__ limit(1) __if_empty__([) /* { dg-error "unbalanced '\\\)'" } */
+/* { dg-error "unbalanced '\\\['" "" { target *-*-* } .-1 } */
+/* { dg-error "unbalanced '\\\('" "" { target *-*-* } .-2 } */
+#embed __FILE__ limit(1) gnu::non_existent_parameter(() /* { dg-error "unknown embed parameter 'gnu::non_existent_parameter'" } */
+/* { dg-error "unbalanced '\\\('" "" { target *-*-* } .-1 } */
+#embed __FILE__ limit(1) __gnu__::__non_existent_parameter__(({[})]) /* { dg-error "unknown embed parameter 'gnu::non_existent_parameter'" } */
+/* { dg-error "unbalanced '\\\('" "" { target *-*-* } .-1 } */
+/* { dg-error "unbalanced '\\\)'" "" { target *-*-* } .-2 } */
+/* { dg-error "unbalanced '\\\{'" "" { target *-*-* } .-3 } */
+/* { dg-error "unbalanced '\\\}'" "" { target *-*-* } .-4 } */
+#embed __FILE__ limit(1) __gnu__::__non_existent_parameter__([) /* { dg-error "unknown embed parameter 'gnu::non_existent_parameter'" } */
+/* { dg-error "unbalanced '\\\)'" "" { target *-*-* } .-1 } */
+/* { dg-error "unbalanced '\\\['" "" { target *-*-* } .-2 } */
+/* { dg-error "unbalanced '\\\('" "" { target *-*-* } .-3 } */
+#embed limit(1) /* { dg-error "#embed expects \\\"FILENAME\\\" or <FILENAME>" } */
+#define FOO 1
+#embed __FILE__ limit(0 + defined(FOO)) /* { dg-error "'defined' in #embed parameter" } */
+#embed /* { dg-error "#embed expects \\\"FILENAME\\\" or <FILENAME>" } */
+#embed "
+/* { dg-warning "missing terminating \\\" character" "" { target *-*-* } .-1 } */
+ /* { dg-error "#embed expects \\\"FILENAME\\\" or <FILENAME>" "" { target *-*-* } .-2 } */
+#embed <
+/* { dg-error "empty filename in #embed" "" { target *-*-* } .-1 } */
+/* { dg-error "missing terminating > character" "" { target *-*-* } .-2 } */
+#embed >  /* { dg-error "#embed expects \\\"FILENAME\\\" or <FILENAME>" } */
+#embed "" /* { dg-error "empty filename in #embed" } */
+#embed <> /* { dg-error "empty filename in #embed" } */
+#embed embed-4.c  /* { dg-error "#embed expects \\\"FILENAME\\\" or <FILENAME>" } */
+#embed __FILE__ foo: /* { dg-error "expected parameter name" } */
+/* { dg-error "unknown embed parameter 'foo'" "" { target *-*-* } .-1 } */
+#embed __FILE__ bar:: /* { dg-error "expected parameter name" } */
+#embed __FILE__ :: /* { dg-error "expected parameter name" } */
+#embed __FILE__ foo:bar /* { dg-error "expected parameter name" } */
+/* { dg-error "unknown embed parameter 'foo'" "" { target *-*-* } .-1 } */
+#embed __FILE__ foo::bar::baz /* { dg-error "expected parameter name" } */
+/* { dg-error "unknown embed parameter 'foo::bar'" "" { target *-*-* } .-1 } */
+#embed __FILE__ foo : : bar /* { dg-error "expected parameter name" } */
+/* { dg-error "unknown embed parameter 'foo'" "" { target *-*-* } .-1 } */
+#embed __FILE__ 42 /* { dg-error "expected parameter name" } */
+#embed __FILE__ 42::foo /* { dg-error "expected parameter name" } */
+#embed __FILE__ foo::42 /* { dg-error "expected parameter name" } */
+#embed __FILE__ limit(1/0) /* { dg-error "division by zero in #embed" } */
--- gcc/testsuite/c-c++-common/cpp/embed-4.c.jj	2024-08-15 10:29:44.629062590 +0200
+++ gcc/testsuite/c-c++-common/cpp/embed-4.c	2024-08-15 10:29:44.629062590 +0200
@@ -0,0 +1,141 @@ 
+/* { dg-do preprocess } */
+/* { dg-options "" } */
+
+#if 1 + __has_embed (__FILE__ , limit(1)) /* { dg-error "expected parameter name" } */
+/* { dg-error "missing binary operator before token \\\"limit\\\"" "" { target *-*-* } .-1 } */
+#endif
+#if 1 + __has_embed (__FILE__ limit(1) /* { dg-error "expected '\\\)'" } */
+#endif
+#if 1 + __has_embed (__FILE__ limit(1) limit(1)) /* { dg-error "duplicate embed parameter 'limit'" } */
+#endif
+#if 1 + __has_embed (__FILE__ limit(1) prefix() prefix()) /* { dg-error "duplicate embed parameter 'prefix'" } */
+#endif
+#if 1 + __has_embed (__FILE__ limit(1) suffix(1 2 3) __suffix__()) /* { dg-error "duplicate embed parameter 'suffix'" } */
+#endif
+#if 1 + __has_embed (__FILE__ if_empty ("this") if_empty("that") limit(1)) /* { dg-error "duplicate embed parameter 'if_empty'" } */
+#endif
+#if 1 + __has_embed (__FILE__ limit prefix() suffix()) /* { dg-error "expected '\\\('" } */
+#endif
+#if 1 + __has_embed (__FILE__ __prefix__ suffix() limit(1)) /* { dg-error "expected '\\\('" } */
+#endif
+#if 1 + __has_embed (__FILE__ prefix() suffix limit(1)) /* { dg-error "expected '\\\('" } */
+#endif
+#if 1 + __has_embed (__FILE__ if_empty limit(1)) /* { dg-error "expected '\\\('" } */
+#endif
+#if 1 + __has_embed (__FILE__ limit (1 / 0)) /* { dg-error "division by zero in #embed" } */
+#endif
+#if 1 + __has_embed (__FILE__ limit (+ + +)) /* { dg-error "operator '\\\+' has no right operand" } */
+#endif
+#if 1 + __has_embed (__FILE__ limit(1) prefix(()) /* { dg-error "expected '\\\)'" } */
+#endif
+#if 1 + __has_embed (__FILE__ limit(1) prefix(({[})])) /* { dg-error "unbalanced '\\\('" } */
+/* { dg-error "unbalanced '\\\)'" "" { target *-*-* } .-1 } */
+/* { dg-error "unbalanced '\\\{'" "" { target *-*-* } .-2 } */
+/* { dg-error "unbalanced '\\\}'" "" { target *-*-* } .-3 } */
+/* { dg-error "expected '\\\)'" "" { target *-*-* } .-4 } */
+#endif
+#if 1 + __has_embed (__FILE__ limit(1) prefix(])) /* { dg-error "unbalanced '\\\]'" } */
+#endif
+#if 1 + __has_embed (__FILE__ limit(1) prefix([)) /* { dg-error "unbalanced '\\\)'" } */
+/* { dg-error "unbalanced '\\\['" "" { target *-*-* } .-1 } */
+/* { dg-error "unbalanced '\\\('" "" { target *-*-* } .-2 } */
+/* { dg-error "expected '\\\)'" "" { target *-*-* } .-3 } */
+#endif
+#if 1 + __has_embed (__FILE__ limit(1) __suffix__(()) /* { dg-error "expected '\\\)'" } */
+#endif
+#if 1 + __has_embed (__FILE__ limit(1) __suffix__(({[})])) /* { dg-error "unbalanced '\\\('" } */
+/* { dg-error "unbalanced '\\\)'" "" { target *-*-* } .-1 } */
+/* { dg-error "unbalanced '\\\{'" "" { target *-*-* } .-2 } */
+/* { dg-error "unbalanced '\\\}'" "" { target *-*-* } .-3 } */
+/* { dg-error "expected '\\\)'" "" { target *-*-* } .-4 } */
+#endif
+#if 1 + __has_embed (__FILE__ limit(1) suffix([)) /* { dg-error "unbalanced '\\\)'" } */
+/* { dg-error "unbalanced '\\\['" "" { target *-*-* } .-1 } */
+/* { dg-error "unbalanced '\\\('" "" { target *-*-* } .-2 } */
+/* { dg-error "expected '\\\)'" "" { target *-*-* } .-3 } */
+#endif
+#if 1 + __has_embed (__FILE__ limit(1) if_empty(()) /* { dg-error "expected '\\\)'" } */
+#endif
+#if 1 + __has_embed (__FILE__ limit(1) __if_empty__(({[})])) /* { dg-error "unbalanced '\\\('" } */
+/* { dg-error "unbalanced '\\\)'" "" { target *-*-* } .-1 } */
+/* { dg-error "unbalanced '\\\{'" "" { target *-*-* } .-2 } */
+/* { dg-error "unbalanced '\\\}'" "" { target *-*-* } .-3 } */
+/* { dg-error "expected '\\\)'" "" { target *-*-* } .-4 } */
+#endif
+#if 1 + __has_embed (__FILE__ limit(1) __if_empty__([)) /* { dg-error "unbalanced '\\\)'" } */
+/* { dg-error "unbalanced '\\\['" "" { target *-*-* } .-1 } */
+/* { dg-error "unbalanced '\\\('" "" { target *-*-* } .-2 } */
+/* { dg-error "expected '\\\)'" "" { target *-*-* } .-3 } */
+#endif
+#if 1 + __has_embed (__FILE__ limit(1) gnu::non_existent_parameter(()) /* { dg-error "expected '\\\)'" } */
+#endif
+#if 1 + __has_embed (__FILE__ limit(1) __gnu__::__non_existent_parameter__(({[})])) /* { dg-error "unbalanced '\\\('" } */
+/* { dg-error "unbalanced '\\\)'" "" { target *-*-* } .-1 } */
+/* { dg-error "unbalanced '\\\{'" "" { target *-*-* } .-2 } */
+/* { dg-error "unbalanced '\\\}'" "" { target *-*-* } .-3 } */
+/* { dg-error "expected '\\\)'" "" { target *-*-* } .-4 } */
+#endif
+#if 1 + __has_embed (__FILE__ limit(1) __gnu__::__non_existent_parameter__([)) /* { dg-error "unbalanced '\\\)'" } */
+/* { dg-error "unbalanced '\\\['" "" { target *-*-* } .-1 } */
+/* { dg-error "unbalanced '\\\('" "" { target *-*-* } .-2 } */
+/* { dg-error "expected '\\\)'" "" { target *-*-* } .-3 } */
+#endif
+#define FOO 1
+#if 1 + __has_embed (limit(1)) /* { dg-error "operator \\\"__has_embed\\\" requires a header-name" } */
+/* { dg-error "missing binary operator before token \\\"1\\\"" "" { target *-*-* } .-1 } */
+#endif
+#if 1 + __has_embed (__FILE__ limit(0 + defined(FOO))) /* { dg-error "'defined' in #embed parameter" } */
+#endif
+int a = __has_embed (__FILE__); /* { dg-error "\\\"__has_embed\\\" used outside of preprocessing directive" } */
+#if __has_embed /* { dg-error "missing '\\\(' before \\\"__has_embed\\\" operand" } */
+/* { dg-error "operator \\\"__has_embed\\\" requires a header-name" "" { target *-*-* } .-1 } */
+#endif
+#if __has_embed( /* { dg-error "operator \\\"__has_embed\\\" requires a header-name" } */
+#endif
+#if __has_embed() /* { dg-error "operator \\\"__has_embed\\\" requires a header-name" } */
+#endif
+#if __has_embed(")
+/* { dg-warning "missing terminating \\\" character" "" { target *-*-* } .-1 } */
+/* { dg-error "operator \\\"__has_embed\\\" requires a header-name" "" { target *-*-* } .-2 } */
+#endif
+#if __has_embed(<)
+/* { dg-error "missing terminating > character" "" { target *-*-* } .-1 } */
+/* { dg-error "expected '\\\)'" "" { target *-*-* } .-2 } */
+#endif
+#if __has_embed(>) /* { dg-error "operator \\\"__has_embed\\\" requires a header-name" } */
+#endif
+#if __has_embed("") /* { dg-error "empty filename in '__has_embed'" } */
+#endif
+#if __has_embed(<>) /* { dg-error "empty filename in '__has_embed'" } */
+#endif
+#if __has_embed(embed-4.c) /* { dg-error "operator \\\"__has_embed\\\" requires a header-name" } */
+/* { dg-error "missing binary operator before token \\\"4.c\\\"" "" { target *-*-* } .-1 } */
+#endif
+#if __has_embed(__FILE__ foo:) /* { dg-error "expected parameter name" } */
+/* { dg-error "missing '\\\(' in expression" "" { target *-*-* } .-1 } */
+#endif
+#if __has_embed(__FILE__ bar::) /* { dg-error "expected parameter name" } */
+#endif
+#if __has_embed(__FILE__ ::) /* { dg-error "expected parameter name" } */
+/* { dg-error "missing '\\\(' in expression" "" { target *-*-* } .-1 } */
+#endif
+#if __has_embed(__FILE__ foo:bar) /* { dg-error "expected parameter name" } */
+/* { dg-error "missing binary operator before token \\\"bar\\\"" "" { target *-*-* } .-1 } */
+#endif
+#if __has_embed(__FILE__ foo::bar::baz) /* { dg-error "expected parameter name" } */
+/* { dg-error "missing binary operator before token \\\"baz\\\"" "" { target *-*-* } .-1 } */
+#endif
+#if __has_embed(__FILE__ foo : : bar) /* { dg-error "expected parameter name" } */
+/* { dg-error "':' without preceding '\\\?'" "" { target *-*-* } .-1 } */
+#endif
+#if __has_embed(__FILE__ 42) /* { dg-error "expected parameter name" } */
+/* { dg-error "missing '\\\(' in expression" "" { target *-*-* } .-1 } */
+#endif
+#if __has_embed(__FILE__ 42::foo) /* { dg-error "expected parameter name" } */
+/* { dg-error "token \\\"::\\\" is not valid in preprocessor expressions" "" { target *-*-* } .-1 } */
+#endif
+#if __has_embed(__FILE__ foo::42) /* { dg-error "expected parameter name" } */
+/* { dg-error "missing '\\\(' in expression" "" { target *-*-* } .-1 } */
+#endif
+#if __has_embed(__FILE__ limit(1/0)) /* { dg-error "division by zero in #embed" } */
+#endif
--- gcc/testsuite/c-c++-common/cpp/embed-5.c.jj	2024-08-15 10:29:44.629062590 +0200
+++ gcc/testsuite/c-c++-common/cpp/embed-5.c	2024-08-15 10:29:44.629062590 +0200
@@ -0,0 +1,9 @@ 
+/* { dg-do preprocess } */
+/* { dg-options "" } */
+
+#undef FOOBAR
+#embed __FILE__ prefix (#include <non-existent-file.h>) suffix (#define FOOBAR baz) if_empty (#error "abcd")
+#embed __FILE__ __prefix__(#define FOOBAR baz)
+#ifdef FOOBAR
+#error "FOOBAR is defined"
+#endif
--- gcc/testsuite/c-c++-common/cpp/embed-6.c.jj	2024-08-15 10:29:44.629062590 +0200
+++ gcc/testsuite/c-c++-common/cpp/embed-6.c	2024-08-15 10:29:44.629062590 +0200
@@ -0,0 +1,24 @@ 
+/* { dg-do preprocess } */
+/* { dg-options "-M -nostdinc --embed-dir=${srcdir}/c-c++-common/cpp/embed-dir" } */
+
+#if __has_embed ("embed-1.c")
+#embed "magna-carta.txt" limit(1)
+#embed "magna-carta.txt" limit(64)
+#embed "magna-carta.txt" prefix(1 +)suffix(+ 42)if_empty()
+#elif
+#embed "non-existent-file"
+#endif
+#if 1 || __has_embed ("embed-2.c")
+#embed <embed-1.inc>
+#embed <embed-4.c>
+#embed "embed-3.c"
+#endif
+
+/* { dg-final { scan-file embed-6.i "(^|\\n)embed-6.o:" } }
+   { dg-final { scan-file embed-6.i "embed-6.c" } }
+   { dg-final { scan-file embed-6.i "c-c..-common/cpp/embed-dir/magna-carta.txt" } }
+   { dg-final { scan-file embed-6.i "c-c..-common/cpp/embed-dir/embed-1.inc" } }
+   { dg-final { scan-file embed-6.i "c-c..-common/cpp/embed-dir/embed-4.c" } }
+   { dg-final { scan-file embed-6.i "(\[^/]|cpp/)embed-3.c" } } */
+/* { dg-final { scan-file-not embed-6.i "embed-1.c" } }
+   { dg-final { scan-file-not embed-6.i "embed-2.c" } } */
--- gcc/testsuite/c-c++-common/cpp/embed-7.c.jj	2024-08-15 10:29:44.629062590 +0200
+++ gcc/testsuite/c-c++-common/cpp/embed-7.c	2024-08-15 10:29:44.629062590 +0200
@@ -0,0 +1,5 @@ 
+/* { dg-do preprocess } */
+/* { dg-options "" } */
+
+#embed "non-existent-file" /* { dg-error "non-existent-file: No such file or directory" } */
+/* { dg-prune-output "compilation terminated" } */
--- gcc/testsuite/c-c++-common/cpp/embed-8.c.jj	2024-08-15 10:29:44.630062577 +0200
+++ gcc/testsuite/c-c++-common/cpp/embed-8.c	2024-08-15 10:29:44.630062577 +0200
@@ -0,0 +1,5 @@ 
+/* { dg-do preprocess } */
+/* { dg-options "--embed-dir=${srcdir}/c-c++-common/cpp/embed-dir" } */
+
+#embed <non-existent-file> /* { dg-error "non-existent-file: No such file or directory" } */
+/* { dg-prune-output "compilation terminated" } */
--- gcc/testsuite/c-c++-common/cpp/embed-9.c.jj	2024-08-15 10:29:44.630062577 +0200
+++ gcc/testsuite/c-c++-common/cpp/embed-9.c	2024-08-15 10:29:44.630062577 +0200
@@ -0,0 +1,4 @@ 
+/* { dg-do preprocess } */
+/* { dg-options "" } */
+
+#embed <non-existent-file> /* { dg-error "no include path in which to search for non-existent-file" } */
--- gcc/testsuite/c-c++-common/cpp/embed-10.c.jj	2024-08-15 10:29:44.630062577 +0200
+++ gcc/testsuite/c-c++-common/cpp/embed-10.c	2024-08-15 11:08:31.499107554 +0200
@@ -0,0 +1,10 @@ 
+/* { dg-do compile } */
+/* { dg-options "--embed-directory=${srcdir}/c-c++-common/cpp/embed-dir" } */
+
+const char *p =
+#embed <magna-carta.txt> limit (42)
+;
+/* { dg-error "makes pointer from integer without a cast" "" { target c } .-2 } */
+/* { dg-error "expected identifier" "" { target c } .-3 } */
+/* { dg-error "invalid conversion" "" { target c++ } .-4 } */
+/* { dg-error "expected unqualified-id before numeric constant" "" { target c++ } .-5 } */
--- gcc/testsuite/c-c++-common/cpp/embed-11.c.jj	2024-08-15 10:29:44.630062577 +0200
+++ gcc/testsuite/c-c++-common/cpp/embed-11.c	2024-08-15 10:29:44.630062577 +0200
@@ -0,0 +1,27 @@ 
+/* { dg-do run { target native } } */
+/* { dg-options "-DMAGNA_CARTA=\"${srcdir}/c-c++-common/cpp/embed-dir/magna-carta.txt\"" } */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+int
+main (void)
+{
+  static const unsigned char embed_data[] = {
+    #embed MAGNA_CARTA
+  };
+  char f_data[sizeof (embed_data)];
+  FILE *f_source = fopen (MAGNA_CARTA, "rb");
+  if (f_source == NULL)
+    abort ();
+  if (fread (f_data, 1, sizeof (embed_data),
+	     f_source) != sizeof (embed_data))
+    {
+      fclose (f_source);
+      abort ();
+    }
+  fclose (f_source);
+  if (memcmp (&embed_data[0], f_data, sizeof (embed_data)))
+    abort ();
+}
--- gcc/testsuite/c-c++-common/cpp/embed-12.c.jj	2024-08-15 10:29:44.631062565 +0200
+++ gcc/testsuite/c-c++-common/cpp/embed-12.c	2024-08-15 10:29:44.630062577 +0200
@@ -0,0 +1,18 @@ 
+/* { dg-do preprocess } */
+/* { dg-options "" } */
+
+#if __has_embed (__FILE__ limit (-1)) /* { dg-error "negative embed parameter operand" } */
+#endif
+#if __has_embed (__FILE__ limit (-42)) /* { dg-error "negative embed parameter operand" } */
+#endif
+#if __has_embed (__FILE__ limit (-9223372036854775807 - 1)) /* { dg-error "negative embed parameter operand" } */
+#endif
+#if __has_embed (__FILE__ limit (18446744073709551615ULL))
+#endif
+#if __has_embed (__FILE__ limit (18446744073709551615ULL + 42))
+#endif
+#embed __FILE__ limit (-1) /* { dg-error "negative embed parameter operand" } */
+#embed __FILE__ limit (-42) /* { dg-error "negative embed parameter operand" } */
+#embed __FILE__ limit (-9223372036854775807 - 1) /* { dg-error "negative embed parameter operand" } */
+#embed __FILE__ limit (18446744073709551615ULL)
+#embed __FILE__ limit (18446744073709551615ULL + 42)
--- gcc/testsuite/c-c++-common/cpp/embed-13.c.jj	2024-08-15 10:29:44.631062565 +0200
+++ gcc/testsuite/c-c++-common/cpp/embed-13.c	2024-08-15 10:29:44.631062565 +0200
@@ -0,0 +1,12 @@ 
+/* { dg-do preprocess } */
+/* { dg-options "-P" } */
+
+#if __has_embed(__FILE__ limit(6))
+#define FOO 20000,20001,20002
+#define BAR 30000,30001,30002
+#embed __FILE__ limit (4) prefix(10000,10001,10002+) suffix(+10003,10004,10005)
+#embed __FILE__ limit (6) prefix(FOO,) suffix(,BAR)
+#endif
+
+/* { dg-final { scan-file embed-13.i "10000,10001,10002\\\+\[ \t\n\r]*\[0-9]+,\[0-9]+,\[0-9]+,\[0-9]+\[ \t\n\r]*\\\+10003,10004,10005" } } */
+/* { dg-final { scan-file embed-13.i "20000,20001,20002,\[ \t\n\r]*\[0-9]+,\[0-9]+,\[0-9]+,\[0-9]+,\[0-9]+,\[0-9]+\[ \t\n\r]*,30000,30001,30002" } } */
--- gcc/testsuite/c-c++-common/cpp/embed-14.c.jj	2024-08-15 10:29:44.631062565 +0200
+++ gcc/testsuite/c-c++-common/cpp/embed-14.c	2024-08-15 10:29:44.631062565 +0200
@@ -0,0 +1,13 @@ 
+/* { dg-do preprocess } */
+/* { dg-options "-P -fdirectives-only" } */
+
+#if __has_embed(__FILE__ limit(6))
+#define FOO 20000,20001,20002
+#define BAR 30000,30001,30002
+#embed __FILE__ limit (4) prefix(10000,10001,10002+) suffix(+10003,10004,10005)
+#embed __FILE__ limit (6) prefix(FOO,) suffix(,BAR)
+#endif
+
+/* { dg-final { scan-file embed-14.i "10000,10001,10002\\\+\[ \t\n\r]*\[0-9]+,\[0-9]+,\[0-9]+,\[0-9]+\[ \t\n\r]*\\\+10003,10004,10005" } } */
+/* { dg-final { scan-file embed-14.i "20000,20001,20002,\[ \t\n\r]*\[0-9]+,\[0-9]+,\[0-9]+,\[0-9]+,\[0-9]+,\[0-9]+\[ \t\n\r]*,30000,30001,30002" } } */
+/* { dg-final { scan-file-not embed-14.i "\[#]embed" } } */
--- gcc/testsuite/c-c++-common/cpp/embed-25.c.jj	2024-08-15 11:11:04.286203884 +0200
+++ gcc/testsuite/c-c++-common/cpp/embed-25.c	2024-08-15 11:10:58.298278490 +0200
@@ -0,0 +1,5 @@ 
+/* { dg-do preprocess } */
+/* { dg-options "--embed-dir=${srcdir}/c-c++-common/cpp/embed-dir --embed-dir=${srcdir}/c-c++-common/cpp/embed-dir/nonexistent" } */
+/* { dg-additional-options "-std=c23" { target c } } */
+
+#embed "embed-1.inc" prefix (int a = ) suffix (;)
--- gcc/testsuite/c-c++-common/cpp/embed-26.c.jj	2024-08-15 11:11:12.549100930 +0200
+++ gcc/testsuite/c-c++-common/cpp/embed-26.c	2024-08-15 11:13:39.271272827 +0200
@@ -0,0 +1,7 @@ 
+/* { dg-do preprocess } */
+/* { dg-options "--embed-dir=${srcdir}/c-c++-common/cpp/embed-dir --embed-dir=${srcdir}/c-c++-common/cpp/embed-dir/nonexistent -Wmissing-include-dirs" } */
+/* { dg-additional-options "-std=c23" { target c } } */
+
+#embed "embed-1.inc" prefix (int a = ) suffix (;)
+
+/* { dg-warning "No such file or directory.*Wmissing-include-dirs" "-Wmissing-include-dirs" { target *-*-* } 0 } */
--- gcc/testsuite/c-c++-common/cpp/embed-dir/embed-1.inc.jj	2024-08-15 10:29:44.631062565 +0200
+++ gcc/testsuite/c-c++-common/cpp/embed-dir/embed-1.inc	2024-08-15 10:29:44.631062565 +0200
@@ -0,0 +1 @@ 
+a
\ No newline at end of file
--- gcc/testsuite/c-c++-common/cpp/embed-dir/embed-3.c.jj	2024-08-15 10:29:44.631062565 +0200
+++ gcc/testsuite/c-c++-common/cpp/embed-dir/embed-3.c	2024-08-15 10:29:44.631062565 +0200
@@ -0,0 +1,4 @@ 
+/* { dg-do preprocess } */
+
+/* Dummy file.  */
+int i;
--- gcc/testsuite/c-c++-common/cpp/embed-dir/embed-4.c.jj	2024-08-15 10:29:44.632062552 +0200
+++ gcc/testsuite/c-c++-common/cpp/embed-dir/embed-4.c	2024-08-15 10:29:44.632062552 +0200
@@ -0,0 +1,3 @@ 
+/* { dg-do preprocess } */
+
+int i;
--- gcc/testsuite/c-c++-common/cpp/embed-dir/magna-carta.txt.jj	2024-08-15 10:29:44.632062552 +0200
+++ gcc/testsuite/c-c++-common/cpp/embed-dir/magna-carta.txt	2024-08-15 10:29:44.632062552 +0200
@@ -0,0 +1,46 @@ 
+Henrícus Dei grátia rex Angliæ, dóminus Hibérniæ, dux Normánniæ, Aquitániæ, et comes Andegáviæ, archiepíscopis, epíscopis, abbátibus, prióribus, comítibus, barónibus, vicecomítibus, præpósitis, minístris et ómnibus ballívis et fidélibus suis præséntem cartam inspectúris, salútem. Sciátis quod nos, intúitu Dei et pro salúte ánime nostre et animárum antecessórum et successórum nostrórum, ad exaltatiónem sancte ecclésiæ et emendatiónem regni nostri, spontánea et bona voluntáte nostra, dédimus et concéssimus archiepíscopis, epíscopis, abbátibus, prióribus, comítibus, barónibus et ómnibus de regno nostro has libertátes subscríptas tenéndas in regno nostro Angliæ in perpétuum.
+In primis concéssimus Deo et hac præsénti carta nostra confirmávimus pro nobis et herédibus nostris in perpétuum quod anglicána ecclésia líbera sit, et hábeat ómnia iura sua íntegra et libertátes suas illǽsas. Concéssimus étiam ómnibus líberis homínibus regni nostri pro nobis et herédibus nostris in perpétuum omnes libertátes subscríptas, habéndas et tenéndas eis et herédibus suis de nobis et herédibus nostris in perpétuum.
+Si quis cómitum vel barónum nostrórum sive aliórum tenéncium de nobis in cápite per servícium militáre mórtuus fúerit, et, cum decésserit, heres eius plene ætátis fúerit et relévium débeat, hábeat hereditátem suam per antíquum relévium, scílicet heres vel herédes cómitis de barónia cómitis íntegra per centum libras, heres vel herédes barónis de barónia íntegra per centum libras, heres vel herédes mílitis de feódo mílitis íntegro per centum sólidos ad plus; et qui minus debúerit minus det secúndum antíquam consuetúdinem feodórum.
+Si autem heres alícuius tálium fúerit infra etatem, dóminus eius non hábeat custódiam eius nec terre sue ántequam homágium eius céperit; et, postquam talis heres fúerit in custódia, cum ad etatem pervénerit, scílicet vigínti et únius anni, hábeat hereditátem suam sine relévio et sine fine, ita tamen quod, si ipse, dum infra etatem fúerit, fiat miles, nichilominus terra remáneat in custódia dominórum suórum usque ad términum prædíctum.
+Custos terre huiúsmodi herédis qui infra etatem fúerit non cápiat de terra herédis nisi rationábiles éxitus et rationábiles consuetúdines et rationabília servícia, et hoc sine destructióne et vasto hóminum vel rerum; et si nos commisérimus custódiam alícuius talis terre vicecomíti vel alícui álii qui de exítibus terre illíus nobis débeat respondére, et ille destructiónem de custódia fécerit vel vastum, nos ab illo capiémus eméndam, et terra committétur duóbus legálibus et discrétis homínibus de feódo illo qui de exítibus nobis respóndeant vel ei cui eos assignavérimus; et si dedérimus vel vendidérimus alícui custódiam alícuius talis terre, et ille destructiónem inde fécerit vel vastum, amíttat ipsam custódiam et tradátur duóbus legálibus et discrétis homínibus de feódo illo qui simíliter nobis respóndeant, sicut prædíctum est.
+Custos autem, quámdiu custódiam terre habúerit, susténtet domos, parcos, vivária, stagna, molendína et cétera ad terram illam pertinéncia de exítibus terre eiusdem, et reddat herédi, cum ad plenam etatem pervénerit, terram suam totam instaurátam de carúcis et ómnibus áliis rebus, ad minus secúndum quod illam recépit. Hec ómnia observéntur de custódiis archiepiscopátuum, episcopátuum, abbatiárum, priorátuum, ecclesiárum et dignitátum vacáncium que ad nos pértinent, excépto quod huiúsmodi custódie vendi non debent.
+Herédes mariténtur absque disparagatióne.
+Vídua post mortem maríti sui statim et sine difficultáte áliqua hábeat maritágium suum et hereditátem suam, nec áliquid det pro dote sua vel pro maritagio suo vel pro hereditáte sua, quam hereditátum marítus suus et ipsa tenuérunt die óbitus ípsius maríti, et máneat in capitáli meságio maríti sui per quadrangínta dies post óbitum ípsius maríti sui, infra quos assignétur ei dos sua, nisi prius et fúerit assignáta, vel nisi domus illa sit castrum; et si de castro recésserit, statim provideátur ei domus cómpetens in qua possit honéste morári, quoúsque doe sua ei assignétur secúndum quod prædíctum est, et hábeat rationábile estovérium suum ínterim de commúni. Assignétur autem ei pro dote sua tércia pars tócius terre maríti sui que sua fuit in vita sua, nisi de minóri dotáta fúerit ad hóstium ecclésiæ.
+Nulla vídua distringátur ad se maritándam, dum vívere volúerit sine maríto, ita tamen quod securitátem fáciet quod se non maritábit sine assénsu nostro, si de nobis tenúerit, vel sine assénsu dómini sui, si de áliquo tenúerit.
+Nos vero vel bállivi nostri non seisiémus terram áliquam nec rédditum pro débito áliquo quámdiu catálla debitóris præséncia suffíciant ad débitum reddéndum et ipse débitor parátus sit inde satisfácere; nec plégii ípsius debitóris distringántur quámdiu ipse capitális débitor suffíciat ad solutiónem débiti; et, si capitális débitor defécerit in solutióne débiti, non habens unde reddat aut réddere rolit cum possit, plégii respóndeant pro débito; et, si volúerint, hábeant terras et rédditus debitóris quoúsque sit eis satisfáctum de débito quod ante pro eo solvérunt, nisi capitális débitor monstráverit se inde esse quiétum versus eósdem plégios.
+Cívitas Londóniæ hábeat omnes antíquas libertátes et líberas consuetúdines suas. Pretérea vólumus et concédimus quod omnes álie civitátes, et burgi, et ville, et barónes de quinque pórtubus, et omnes portus, hábeant omnes libertátes et líberas consuetúdines suas.
+Nullus distringátur ad faciéndum maius servícium de feódo mílitis nec de álio líbero teneménto quam inde debétur.
+Commúnia plácita non sequántur cúriam nostram, set teneántur in áliquo loco certo.
+Recognitiónes de nova disseísina et de morte antecessóris non capiántur nisi in suis comitátibus, et hoc modo: nos, vel si extra regnum fuérimus, capitális iusticiárius noster, mittémus iusticiários per unumquémque comitátum semel in anno, qui cum milítibus comitátuum cápiant in comitátibus assísas prædíctas. Et ea que in illo advéntu suo in comitátu per iusticiários prædíctos ad dictas assísas capiéndas missos terminári non possunt, per eósdem terminéntur álibi in itínere suo; et ea que per eósem propter difficultátem aliquórum articulórum terminári non possunt, refer-antur ad iusticiários, nostros de banco, et ibi terminéntur.
+Assise de última præsentatióne semper capiántur coram iusticiáriis nostris de banco et ibi terminéntur.
+Liber homo non amerciétur pro parvo delícto nisi secúndum modum ípsius delícti, et pro magno delícto, secúndum magnitúdinem delícti, salvo conteneménto suo; et mercátor eódem modo salva mercandísa sua; et villánus altérius quam noster eódem modo amerciétur salvo wainágio suo, si incíderit in misericórdiam nostram; et nulla prædictárum misericordiárum ponátur nisi per sacraméntum probórum et legálium hóminum de visnéto.
+Cómites et barónes non amerciéntur nisi per pares suos, et non nisi secúndum modum delícti.
+Nulla ecclesiástica persóna amerciétur secúndum quantitátem benefícii sui ecclesiástici, set secúndum láicum teneméntum suum, et secúndum quantitátem delícti.
+Nec villa, nec homo, distringátur fácere pontes ad ripárias nisi que ex antíquo et de iure fácere debet.
+Nulla ripária decétero defendátur, nisi ille que fuérunt in defénso témpore regis Henríci avi nostri, per eádem loca et eósdem términos sicut esse consuevérunt témpore suo.
+Nullus vicecómes, constabulárius, coronatóres vel álii bállivi nostri téneant plácita corone nostre.
+Si áliquis tenens de nobis láicum feódum moriátur, et vice-comes vel ballívus noster osténdat lítteras nostras paténtes de summonitióne nostra de débito quod defúnctus nobis débuit, líceat vicecomíti vel ballivo nostro attachiáre et inbreviáre cátalla defúncti invénta in láico feódo ad valénciam illíus débiti per visum legálium hóminum, ita tamen quod nichil inde amoveátur donec persolvátur nobis débitum quod clarum fúerit, et resíduum relinquátur executóribus ad faciéndum testaméntum defúncti; et si nichil nobis debeátur ab ipso, ómnia cátalla cedant defúncto, salvis uxóri ípsius et púeris suis rationabílibus pártibus suis.
+Nullus constabulárius vel eius ballívus cápiat blada vel ália cátalla alícuius qui non sit de villa ubi castrum situm est, nisi statim inde reddat denários aut respéctum inde habére possit de voluntáte venditóris; si autem de villa ipsa fúerit, infra quadragínta dies précium reddat.
+Nullus constabulárius distríngat áliquem mílitem ad dandum denários pro custódia castri, si ipse eam fácere volúerit in própria persóna sua, vel per álium probum hóminem, si ipse eam fácere non possit propter rationábilem causam, et, si nos duxérimus eum vel misérimus in exércitum, erit quiétus de custódia secúndum quantitátem témporis quo per nos fúerit in exércitu de feódo pro quo fecit servícium in exércitu.
+Nullus vicecómes, vel ballívus noster, vel álius cápiat equos vel caréttas alícuius pro cariagio faciéndo, nisi reddat liberatiónem antíquitus statútam, scílicet pro carétta ad duos equos decem denários per diem, et pro carétta ad tres equos quatuórdecim denários per diem. Nulla carétta domínica alícuius ecclesiástice pérsone vel mílitis vel alícuius dómine capiátur per ballivos prædíctos.
+Nec nos nec bállivi nostri nec álii capiémus aliénum boscum ad castra vel ália agénda nostra, nisi per voluntátem illíus cuius boscus ille fúerit.
+Nos non tenébimus terras eórum qui convícti fúerint de felónia, nisi per unum annum et unum diem; et tunc reddántur terre dóminis feodórum.
+Omnes kidélli decétero deponántur penítus per Tamísiam et Medéweiam et per totam Angliam, nisi per costéram maris.
+Breve quod vocátur Précipe decétero non fiat alícui de áliquo tenaménto, unde liber homo perdat cúriam suam.
+Una mensúra vini sit per totum regnum nostrum, et una mensúra cervísiæ, et una mensúra bladi, scílicet quartérium London, et una latitúdo pannórum tinctórum et russettórum et haubergettórum, scílicet due ulne infra listas; de pondéribus vero sit ut de mensúris.
+Nihil detur de cétero pro brevi inquisitiónis ab eo qui inquisitiónem petit de vita vel membris, set gratis concedátur et non negétur.
+Si áliquis téneat de nobis per feodifírmam vel soccágium, vel per burgágium, et de álio terram téneat per servícium militáre, nos non habébimus custódiam herédis nec terre sue que est de feódo altérius, occasióne illíus feodifírme, vel soccágii, vel burgágii, nec habébimus custódiam illíus feodifírme vel soccágii vel burgágii, nisi ipsa feodifírma débeat servícium militáre. Nos non habébimus custódiam herédis nec terre alícuius quam tenet de álio per servícium militáre, occasióne alícuius parve seriantériæ quam tenet de nobis per servícium reddéndi nobis cultéllos, vel sagíttas, vel huiúsmodi.
+Nullus ballívus ponat decétero áliquem ad legem maniféstam vel ad iuraméntum símplici loquéla sua, sine téstibus fidélibus ad hoc indúctis.
+Nullus liber homo decétero capiátur vel imprisonétur aut disseisiátur de áliquo líbero teneménto suo vel libertátibus vel líberis consuetudínibus suis, aut utlagétur, aut exulétur aut áliquo álio modo destruátur, nec super eum íbimus, nec super eum mittémus, nisi per legále iudícium párium suórum, vel per legem terre.
+Nulli vendémus, nulli negábimus aut differémus rectum vel iustíciam.
+Omnes mercatóres, nisi públice ántea prohíbiti fúerint, hábeant salvum et secúrum exíre de Anglia, et veníre in Angliam, et morári, et ire per Angliam tam per terram quam per aquam ad eméndum vel vendéndum sine ómnibus toltis malis per antíquas et rectas consuetúdines, preterquam in témpore gwerre, et si sint de terra contra nos gwérrina; et si tales inveniántur in terra nostra in princípio gwerre, attachientur sine dampno córporum vel rerum, donec sciátur a nobis vel a capitáli iusticiário nostro quómodo mercatóres terre nostre tracténtur, qui tunc inveniéntur in terra contra nos gwérrina; et, si nostri salvi sint ibi, álii salvi sint in terra nostra.
+Si quis tenúerit de áliqua escǽta, sicut de honóre Wallingefórdiæ, Bolóniæ, Notingeham, Lancástriæ, vel de áliis que sunt in manu nostra, et sint barónie, et obíerit, heres eius non det aliud relévium nec fiat nobis aliud servícium quam fáceret baróni, si ipsa esset in manu barónis; et nos eódem modo eam tenébimus quo baro eam ténuit, nec nos, occasióne talis barónie vel escæte, habébimus áliquam escǽtam vel custódiam aliquórum hóminum nostrórum, nisi álibi tenúerit de nobis in cápite ille qui ténuit baróniam vel escǽtam.
+Nullus liber homo decétero det ámplius alícui vel vendat de terra sua quam ut de resíduo terre sue possit sufficiénter fíeri dómino feódi servícium ei débitum quod pértinet ad feódum illud.
+Omnes patróni abbatiárum qui habent cartas regum Angliæ de advocatióne, vel antíquam tenúram vel possessiónem, hábeant eárum custódiam cum vacáverint, sicut habére debent, et sicut supra declarátum est.
+Nullus capiátur vel imprisonétur propter appéllum fémine de morte altérius quam viri sui.
+Nullus comitátus decétero teneátur, nisi de mense in mensem; et, ubi maior términus esse solébat, maior sit. Nec áliquis vicecómes vel ballívus fáciat turnum suum per hundrédum nisi bis in anno et non nisi in loco débito et consuéto, vidélicet semel post Pascha et íterum post festum sancti Michaélis. Et visus de franco plegio tunc fiat ad illum términum sancti Michális sine occasióne, ita scílicet quod quilíbet hábeat libertátes suas quas hábuit et habére consuévit témpore regis Henríci avi nostri, vel quas póstea perquisívit. Fiat autem visus de franco plegio sic, vidélicet quod pax nostra teneátur, et quod tethinga íntegra sit sicut esse consuévit, et quod vicecómes non quérat occasiónes, et quod contintus sit eo quod vicecómes habére consuévit de visu suo faciéndo témpore regis Henríci avi nostri.
+Non líceat alícui decétero dare terram suam alícui dómui religióse, ita quod eam resúmat tenéndam de eádem domo, nec líceat alícui dómui religióse terram alícuius sic accípere quod tradat illam ei a quo ipsam recépit tenéndam. Si quis autem de cétero terram suam alícui dómui religióse sic déderit, et super hoc convincátur, donum suum penítus cassétur, et terra illa dómino suo illíus feódi incurrátur.
+Scutágium decétero capiátur sicut capi solébat témpore regis Henríci avi nostri. Et salve sint archiepíscopis, epíscopis, abbátibus, prióribus, templáriis, hospitaláriis, comítibus, barónibus et ómnibus áliis tam ecclesiásticis quam seculáribus persónis libertátes et líbere consuetúdines quas prius habuérunt.
+Omnes autem istas consuetúdines prædíctas et libertátes quas concéssimus in regno nostro tenéndas quantum ad nos pértinet erga nostros, omnes de regno nostro tam clérici quam láici obsérvent quantum ad se pértinet erga suos. Pro hac autem concessióne et donatióne libertátum istárum et aliárum libertátum contentárum in carta nostra de libertátibus fóreste, archiepíscopi, epíscopi, abbátes, prióres, cómites, barónes, mílites, líbere tenéntes, et omnes de regno nostro dedérunt nobis quintam décimam partem ómnium mobílium suórum. Concéssimus étiam eísdem pro nobis et herédibus nostris quod nec nos nec herédes nostri áliquid perquirémus per quod libertátes in hac carta conténte infringántur vel infirméntur; et, si de áliquo áliquid contra hoc perquisítum fúerit, nichil váleat et pro nullo habeátur.
+His téstibus dómino Stéphano Cantuariensi archiepíscopo, Eustáchio Lundoniensi, Iocelino Bathoniensi, Petro Wintoniensi, Hugoni Lincolniensi, Ricardo Sarrisberiensi, Benedícto Roffensi, Willelmo Wigorniensi, Iohanne Eliensi, Hugone Herefordiensi, Radulpho Cicestriensi, Willelmo Exoniensi epíscopis, abbáte sancti Albáni, abbáte sancti Edmundi, abbáte de Bello, abbáte sancti Augustíni Cantuariensis, abbáte de Evashamia, abbáte de Westmonasterio, abbáte de Burgo sancti Petri, abbáte Radingensi, abbáte Abbendoniensi, abbáte de Maumeburia, abbáte de Winchecomba, abbáte de Hida, abbáte de Certeseia, abbáte de Sire-burnia, abbáte de Cerne, abbáte de Abbotebiria, abbáte de Middletonia, abbáte de Seleby, abbáte de Wyteby, abbáte de Cirencestria, Huberto de Burgo iusticiário, Ranulfo cómite Cestrie et Lincolnie, Willelmo cómite Sarrisberie, Willelmo cómite Warennie, Gilberto de Clara cómite Gloucestrie et Hertfordie, Willelmo de Ferráriis cómite Derbeie, Willelmo de Mandevilla cómite Essexie, Hugone Le Bigod cómite Norfolcie, Willelmo cómite Aubemarle, Hunfrido cómite Herefordie, Iohanne constabulario Cestrie, Roberto de Ros, Roberto fílio Walteri, Roberto de Véteri ponte, Willielmo Brigwerre, Ricardo de Munfichet, Petro fílio Herberti, Matheo fílio Herberti, Willielmo de Albiniaco, Roberto Gresley, Reginaldo de Brahus, Iohanne de Munemutha, Iohanne fílio Aláni, Hugone de Mortuomari, Waltero de Bellocampo, Willielmo de sancto Iohanne, Petro de Malalacu, Briano de Insula, Thoma de Muletonia, Ricardo de Argentein., Gaulfrido de Nevilla, Willielmo Mauduit, Iohanne de Baalun.
+Datum apud Westmonastérium undécimo die februárii anno regni nostri nono.
--- gcc/testsuite/gcc.dg/cpp/embed-1.c.jj	2024-08-15 10:29:44.632062552 +0200
+++ gcc/testsuite/gcc.dg/cpp/embed-1.c	2024-08-15 10:29:44.632062552 +0200
@@ -0,0 +1,4 @@ 
+/* { dg-do run } */
+/* { dg-options "-std=c23 -pedantic-errors --embed-dir=${srcdir}/c-c++-common/cpp/embed-dir" } */
+
+#include "../../c-c++-common/cpp/embed-1.c"
--- gcc/testsuite/gcc.dg/cpp/embed-2.c.jj	2024-08-15 10:29:44.632062552 +0200
+++ gcc/testsuite/gcc.dg/cpp/embed-2.c	2024-08-15 10:29:44.632062552 +0200
@@ -0,0 +1,14 @@ 
+/* { dg-do compile } */
+/* { dg-options "-std=c17 -pedantic-errors -Wall -W" } */
+
+#if __has_embed (__FILE__ limit (1)) != 1
+#error "__has_embed failed"
+#endif
+
+int a =
+#embed __FILE__ limit (1) /* { dg-error "#embed before C23 is a GCC extension" } */
+;
+int b =
+(__extension__
+#embed __FILE__ limit (1)
+);
--- gcc/testsuite/gcc.dg/cpp/embed-3.c.jj	2024-08-15 10:29:44.633062540 +0200
+++ gcc/testsuite/gcc.dg/cpp/embed-3.c	2024-08-15 10:29:44.633062540 +0200
@@ -0,0 +1,14 @@ 
+/* { dg-do compile } */
+/* { dg-options "-std=c17 -pedantic -Wall -W" } */
+
+#if __has_embed (__FILE__ limit (1)) != 1
+#error "__has_embed failed"
+#endif
+
+int a =
+#embed __FILE__ limit (1) /* { dg-warning "#embed before C23 is a GCC extension" } */
+;
+int b =
+(__extension__
+#embed __FILE__ limit (1)
+);
--- gcc/testsuite/gcc.dg/cpp/embed-4.c.jj	2024-08-15 10:29:44.633062540 +0200
+++ gcc/testsuite/gcc.dg/cpp/embed-4.c	2024-08-15 10:29:44.633062540 +0200
@@ -0,0 +1,13 @@ 
+/* { dg-do preprocess } */
+/* { dg-options "-traditional-cpp" } */
+
+#if __has_embed(__FILE__ limit(6))
+#endif
+/* { dg-error "-:'__has_embed' not supported in traditional C" "" { target *-*-* } .-2 } */
+/* { dg-error "-:missing binary operator before token \\\"\\\(\\\"" "" { target *-*-* } .-3 } */
+#define FOO 20000,20001,20002
+#define BAR 30000,30001,30002
+#embed __FILE__ limit (4) prefix(10000,10001,10002+) suffix(+10003,10004,10005)
+/* { dg-error "-:#embed not supported in traditional C" "" { target *-*-* } .-1 } */
+#embed __FILE__ limit (6) prefix(FOO,) suffix(,BAR)
+/* { dg-error "-:#embed not supported in traditional C" "" { target *-*-* } .-1 } */
--- gcc/testsuite/g++.dg/cpp/embed-1.C.jj	2024-08-15 10:29:44.633062540 +0200
+++ gcc/testsuite/g++.dg/cpp/embed-1.C	2024-08-15 10:29:44.633062540 +0200
@@ -0,0 +1,14 @@ 
+// { dg-do compile }
+// { dg-options "-pedantic-errors -Wall -W" }
+
+#if __has_embed (__FILE__ limit (1)) != 1
+#error "__has_embed failed"
+#endif
+
+int a =
+#embed __FILE__ limit (1) // { dg-error "#embed is a GCC extension" }
+;
+int b =
+(__extension__
+#embed __FILE__ limit (1) // { dg-error "#embed is a GCC extension" }
+);
--- gcc/testsuite/g++.dg/cpp/embed-2.C.jj	2024-08-15 10:29:44.633062540 +0200
+++ gcc/testsuite/g++.dg/cpp/embed-2.C	2024-08-15 10:29:44.633062540 +0200
@@ -0,0 +1,14 @@ 
+// { dg-do compile }
+// { dg-options "-pedantic -Wall -W" }
+
+#if __has_embed (__FILE__ limit (1)) != 1
+#error "__has_embed failed"
+#endif
+
+int a =
+#embed __FILE__ limit (1) // { dg-warning "#embed is a GCC extension" }
+;
+int b =
+(__extension__
+#embed __FILE__ limit (1) // { dg-warning "#embed is a GCC extension" }
+);
--- gcc/testsuite/g++.dg/cpp/embed-3.C.jj	2024-08-15 10:29:44.634062527 +0200
+++ gcc/testsuite/g++.dg/cpp/embed-3.C	2024-08-15 10:29:44.633062540 +0200
@@ -0,0 +1,48 @@ 
+// { dg-do compile { target c++11 } }
+// { dg-options "--embed-dir=${srcdir}/c-c++-common/cpp/embed-dir" }
+
+template <int... N>
+constexpr decltype (sizeof 0)
+foo ()
+{
+  return sizeof... (N);
+}
+
+template <typename T, typename U>
+struct same_type;
+template <typename T>
+struct same_type <T, T> {};
+
+void
+bar ()
+{
+}
+
+template <typename U, typename... T>
+same_type <U, int> *
+bar (U u, T... t)
+{
+  bar (t...);
+  return nullptr;
+}
+
+static_assert (
+#embed <magna-carta.txt> limit (1) prefix (foo <) suffix (> () == 1, "")
+);
+static_assert (
+#embed <magna-carta.txt> limit (2) prefix (foo <) suffix (> () == 2, "")
+);
+static_assert (
+#embed <magna-carta.txt> limit (42) prefix (foo <) suffix (> () == 42, "")
+);
+static_assert (
+#embed <magna-carta.txt> limit (521) prefix (foo <) suffix (> () == 521, "")
+);
+
+void
+baz ()
+{
+  bar (
+#embed "magna-carta.txt" limit (54)
+      );
+}