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