| 1 |
// RUN: %clang_cc1 -std=c23 %s -E --embed-dir=%S/Inputs -verify |
| 2 |
// expected-no-diagnostics |
| 3 |
|
| 4 |
#if __has_embed(__FILE__) != __STDC_EMBED_FOUND__ |
| 5 |
#error 1 |
| 6 |
#elif __has_embed("media/art.txt") != __STDC_EMBED_FOUND__ |
| 7 |
#error 2 |
| 8 |
#elif __has_embed("asdkasdjkadsjkdsfjk") != __STDC_EMBED_NOT_FOUND__ |
| 9 |
#error 3 |
| 10 |
#elif __has_embed("asdkasdjkadsjkdsfjk" limit(1)) != __STDC_EMBED_NOT_FOUND__ |
| 11 |
#error 4 |
| 12 |
#elif __has_embed("asdkasdjkadsjkdsfjk" suffix(x) limit(1)) != __STDC_EMBED_NOT_FOUND__ |
| 13 |
#error 5 |
| 14 |
#elif __has_embed("asdkasdjkadsjkdsfjk" suffix(x) djsakdasjd::xmeow("xD")) != __STDC_EMBED_NOT_FOUND__ |
| 15 |
#error 6 |
| 16 |
#elif __has_embed(__FILE__ limit(2) prefix(y)) != __STDC_EMBED_FOUND__ |
| 17 |
#error 7 |
| 18 |
#elif __has_embed(__FILE__ limit(2)) != __STDC_EMBED_FOUND__ |
| 19 |
#error 8 |
| 20 |
// 6.10.1p7, if the search fails or any of the embed parameters in the embed |
| 21 |
// parameter sequence specified are not supported by the implementation for the |
| 22 |
// #embed directive; |
| 23 |
// We don't support one of the embed parameters. |
| 24 |
#elif __has_embed(__FILE__ dajwdwdjdahwk::meow(x)) != __STDC_EMBED_NOT_FOUND__ |
| 25 |
#error 9 |
| 26 |
#elif __has_embed(<media/empty>) != __STDC_EMBED_EMPTY__ |
| 27 |
#error 10 |
| 28 |
// 6.10.1p7: if the search for the resource succeeds and all embed parameters |
| 29 |
// in the embed parameter sequence specified are supported by the |
| 30 |
// implementation for the #embed directive and the resource is empty |
| 31 |
// Limiting to zero characters means the resource is empty. |
| 32 |
#elif __has_embed(<media/empty> limit(0)) != __STDC_EMBED_EMPTY__ |
| 33 |
#error 11 |
| 34 |
#elif __has_embed(<media/art.txt> limit(0)) != __STDC_EMBED_EMPTY__ |
| 35 |
#error 12 |
| 36 |
// Test that an offset past the end of the file produces an empty file. |
| 37 |
#elif __has_embed(<single_byte.txt> clang::offset(1)) != __STDC_EMBED_EMPTY__ |
| 38 |
#error 13 |
| 39 |
// Test that we apply the offset before we apply the limit. If we did this in |
| 40 |
// the reverse order, this would cause the file to be empty because we would |
| 41 |
// have limited it to 1 byte and then offset past it. |
| 42 |
#elif __has_embed(<media/art.txt> limit(1) clang::offset(12)) != __STDC_EMBED_FOUND__ |
| 43 |
#error 14 |
| 44 |
#elif __has_embed(<media/art.txt>) != __STDC_EMBED_FOUND__ |
| 45 |
#error 15 |
| 46 |
#elif __has_embed(<media/art.txt> if_empty(meow)) != __STDC_EMBED_FOUND__ |
| 47 |
#error 16 |
| 48 |
#endif |
| 49 |
|
| 50 |
// Ensure that when __has_embed returns true, the file can actually be |
| 51 |
// embedded. This was previously failing because the way in which __has_embed |
| 52 |
// would search for files was differentl from how #embed would resolve them |
| 53 |
// when the file path included relative path markers like `./` or `../`. |
| 54 |
#if __has_embed("./embed___has_embed.c") == __STDC_EMBED_FOUND__ |
| 55 |
unsigned char buffer[] = { |
| 56 |
#embed "./embed___has_embed.c" |
| 57 |
}; |
| 58 |
#else |
| 59 |
#error 17 |
| 60 |
#endif |
| 61 |
|
| 62 |
#if __has_embed(__FILE__\ |
| 63 |
) |
| 64 |
#else |
| 65 |
#error 18 |
| 66 |
#endif |
| 67 |
|
| 68 |
#define F __FI\ |
| 69 |
LE__ |
| 70 |
#if __has_embed(F) |
| 71 |
#else |
| 72 |
#error 19 |
| 73 |
#endif |
| 74 |
|
| 75 |
#if __has_embed(F\ |
| 76 |
) |
| 77 |
#else |
| 78 |
#error 20 |
| 79 |
#endif |