mirror of
https://github.com/clang-retro/llvm.git
synced 2026-11-29 05:41:27 -08:00
This commit implements the entirety of the now-accepted [N3017 -Preprocessor Embed](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3017.htm) and its sister C++ paper [p1967](https://wg21.link/p1967). It implements everything in the specification, and includes an implementation that drastically improves the time it takes to embed data in specific scenarios (the initialization of character type arrays). The mechanisms used to do this are used under the "as-if" rule, and in general when the system cannot detect it is initializing an array object in a variable declaration, will generate EmbedExpr AST node which will be expanded by AST consumers (CodeGen or constant expression evaluators) or expand embed directive as a comma expression. This reverts commit https://github.com/llvm/llvm-project/commit/682d461d5a231cee54d65910e6341769419a67d7. --------- Co-authored-by: The Phantom Derpstorm <phdofthehouse@gmail.com> Co-authored-by: Aaron Ballman <aaron@aaronballman.com> Co-authored-by: cor3ntin <corentinjabot@gmail.com> Co-authored-by: H. Vetinari <h.vetinari@gmx.com>
61 lines
2.6 KiB
C
61 lines
2.6 KiB
C
// RUN: %clang_cc1 -std=c23 %s -E --embed-dir=%S/Inputs -verify
|
|
// expected-no-diagnostics
|
|
|
|
#if __has_embed(__FILE__) != __STDC_EMBED_FOUND__
|
|
#error 1
|
|
#elif __has_embed("media/art.txt") != __STDC_EMBED_FOUND__
|
|
#error 2
|
|
#elif __has_embed("asdkasdjkadsjkdsfjk") != __STDC_EMBED_NOT_FOUND__
|
|
#error 3
|
|
#elif __has_embed("asdkasdjkadsjkdsfjk" limit(1)) != __STDC_EMBED_NOT_FOUND__
|
|
#error 4
|
|
#elif __has_embed("asdkasdjkadsjkdsfjk" suffix(x) limit(1)) != __STDC_EMBED_NOT_FOUND__
|
|
#error 5
|
|
#elif __has_embed("asdkasdjkadsjkdsfjk" suffix(x) djsakdasjd::xmeow("xD")) != __STDC_EMBED_NOT_FOUND__
|
|
#error 6
|
|
#elif __has_embed(__FILE__ limit(2) prefix(y)) != __STDC_EMBED_FOUND__
|
|
#error 7
|
|
#elif __has_embed(__FILE__ limit(2)) != __STDC_EMBED_FOUND__
|
|
#error 8
|
|
// 6.10.1p7, if the search fails or any of the embed parameters in the embed
|
|
// parameter sequence specified are not supported by the implementation for the
|
|
// #embed directive;
|
|
// We don't support one of the embed parameters.
|
|
#elif __has_embed(__FILE__ dajwdwdjdahwk::meow(x)) != __STDC_EMBED_NOT_FOUND__
|
|
#error 9
|
|
#elif __has_embed(<media/empty>) != __STDC_EMBED_EMPTY__
|
|
#error 10
|
|
// 6.10.1p7: if the search for the resource succeeds and all embed parameters
|
|
// in the embed parameter sequence specified are supported by the
|
|
// implementation for the #embed directive and the resource is empty
|
|
// Limiting to zero characters means the resource is empty.
|
|
#elif __has_embed(<media/empty> limit(0)) != __STDC_EMBED_EMPTY__
|
|
#error 11
|
|
#elif __has_embed(<media/art.txt> limit(0)) != __STDC_EMBED_EMPTY__
|
|
#error 12
|
|
// Test that an offset past the end of the file produces an empty file.
|
|
#elif __has_embed(<single_byte.txt> clang::offset(1)) != __STDC_EMBED_EMPTY__
|
|
#error 13
|
|
// Test that we apply the offset before we apply the limit. If we did this in
|
|
// the reverse order, this would cause the file to be empty because we would
|
|
// have limited it to 1 byte and then offset past it.
|
|
#elif __has_embed(<media/art.txt> limit(1) clang::offset(12)) != __STDC_EMBED_FOUND__
|
|
#error 14
|
|
#elif __has_embed(<media/art.txt>) != __STDC_EMBED_FOUND__
|
|
#error 15
|
|
#elif __has_embed(<media/art.txt> if_empty(meow)) != __STDC_EMBED_FOUND__
|
|
#error 16
|
|
#endif
|
|
|
|
// Ensure that when __has_embed returns true, the file can actually be
|
|
// embedded. This was previously failing because the way in which __has_embed
|
|
// would search for files was differentl from how #embed would resolve them
|
|
// when the file path included relative path markers like `./` or `../`.
|
|
#if __has_embed("./embed___has_embed.c") == __STDC_EMBED_FOUND__
|
|
unsigned char buffer[] = {
|
|
#embed "./embed___has_embed.c"
|
|
};
|
|
#else
|
|
#error 17
|
|
#endif
|