| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-options "--embed-dir=${srcdir}/c-c++-common/cpp/embed-dir" } */ |
| 3 |
/* { dg-additional-options "-std=gnu99" { target c } } */ |
| 4 |
|
| 5 |
#if !defined(__STDC_EMBED_NOT_FOUND__) || __STDC_EMBED_NOT_FOUND__ != 0 |
| 6 |
#error "__STDC_EMBED_NOT_FOUND__ not defined or has invalid value" |
| 7 |
#endif |
| 8 |
|
| 9 |
#if __STDC_EMBED_FOUND__ != 1 |
| 10 |
#error "__STDC_EMBED_FOUND__ not defined or has invalid value" |
| 11 |
#endif |
| 12 |
|
| 13 |
#if __STDC_EMBED_EMPTY__ != 2 |
| 14 |
#error "__STDC_EMBED_EMPTY__ not defined or has invalid value" |
| 15 |
#endif |
| 16 |
|
| 17 |
#ifndef __has_embed |
| 18 |
#error "__has_embed not defined" |
| 19 |
#endif |
| 20 |
|
| 21 |
#if __has_embed (__FILE__) != __STDC_EMBED_FOUND__ |
| 22 |
#error "__has_embed fail" |
| 23 |
#endif |
| 24 |
|
| 25 |
#if __has_embed (__FILE__ limit (NONEXISTENT_MACRO) prefix (1 2 3) __suffix__ () if_empty ({})) != __STDC_EMBED_EMPTY__ |
| 26 |
#error "__has_embed fail" |
| 27 |
#endif |
| 28 |
|
| 29 |
#if __has_embed (__FILE__ __limit__ (1) __prefix__ () suffix (1 / 0) __if_empty__ ((({{[0[0{0{0(0(0)1)1}1}]]}})))) != __STDC_EMBED_FOUND__ |
| 30 |
#error "__has_embed fail" |
| 31 |
#endif |
| 32 |
|
| 33 |
#if __has_embed (__FILE__ limit (0) gnu::nonexistent ({})) != __STDC_EMBED_NOT_FOUND__ |
| 34 |
#error "__has_embed fail" |
| 35 |
#endif |
| 36 |
|
| 37 |
#if __has_embed (__FILE__ limit (0) __gnu__::__non_existent__ ({})) != __STDC_EMBED_NOT_FOUND__ |
| 38 |
#error "__has_embed fail" |
| 39 |
#endif |
| 40 |
|
| 41 |
#if __has_embed (__FILE__ limit (0) gnu::__non_existent__ ({})) != __STDC_EMBED_NOT_FOUND__ |
| 42 |
#error "__has_embed fail" |
| 43 |
#endif |
| 44 |
|
| 45 |
#if __has_embed (__FILE__ limit (0) non_existent_standard_arg (42)) != __STDC_EMBED_NOT_FOUND__ |
| 46 |
#error "__has_embed fail" |
| 47 |
#endif |
| 48 |
|
| 49 |
#if __has_embed ("non-existent-file" limit (NONEXISTENT_MACRO + 1)) != __STDC_EMBED_NOT_FOUND__ |
| 50 |
#error "__has_embed fail" |
| 51 |
#endif |
| 52 |
|
| 53 |
#if __has_embed ("embed-1.c" limit (0)) != __STDC_EMBED_EMPTY__ |
| 54 |
#error "__has_embed fail" |
| 55 |
#endif |
| 56 |
|
| 57 |
#define E1 "embed-1.c" |
| 58 |
#define E2 limit ( |
| 59 |
#define E3 1) |
| 60 |
#if __has_embed (E1 E2 E3) != __STDC_EMBED_FOUND__ |
| 61 |
#error "__has_embed fail" |
| 62 |
#endif |
| 63 |
|
| 64 |
#if __has_embed (<embed-1.c>) != __STDC_EMBED_NOT_FOUND__ |
| 65 |
#error "__has_embed fail" |
| 66 |
#endif |
| 67 |
|
| 68 |
#define E4 <embed-1.c> |
| 69 |
#define E5 limit |
| 70 |
#define E6 1) |
| 71 |
#if __has_embed ( \ |
| 72 |
E4 \ |
| 73 |
E5 ( \ |
| 74 |
E6 \ |
| 75 |
) != __STDC_EMBED_NOT_FOUND__ |
| 76 |
#error "__has_embed fail" |
| 77 |
#endif |
| 78 |
|
| 79 |
#if __has_embed ("embed-1.inc") != __STDC_EMBED_FOUND__ |
| 80 |
#error "__has_embed fail" |
| 81 |
#endif |
| 82 |
|
| 83 |
#if __has_embed ( "embed-1.inc" __limit__ ( 7 - 7 ) ) != __STDC_EMBED_EMPTY__ |
| 84 |
#error "__has_embed fail" |
| 85 |
#endif |
| 86 |
|
| 87 |
#if __has_embed (<embed-1.inc>) != __STDC_EMBED_FOUND__ |
| 88 |
#error "__has_embed fail" |
| 89 |
#endif |
| 90 |
|
| 91 |
#if __has_embed (<embed-1.inc> limit(0)) != __STDC_EMBED_EMPTY__ |
| 92 |
#error "__has_embed fail" |
| 93 |
#endif |
| 94 |
|
| 95 |
#if __has_embed ("../empty.h") != __STDC_EMBED_EMPTY__ |
| 96 |
#error "__has_embed fail" |
| 97 |
#endif |
| 98 |
|
| 99 |
#if __has_embed (<../empty.h>) != __STDC_EMBED_NOT_FOUND__ |
| 100 |
#error "__has_embed fail" |
| 101 |
#endif |
| 102 |
|
| 103 |
#if __has_embed ("../../empty.h") != __STDC_EMBED_EMPTY__ |
| 104 |
#error "__has_embed fail" |
| 105 |
#endif |
| 106 |
|
| 107 |
#if __has_embed (<../../empty.h>) != __STDC_EMBED_EMPTY__ |
| 108 |
#error "__has_embed fail" |
| 109 |
#endif |
| 110 |
|
| 111 |
#if __has_embed ("../empty.h" __limit__ (42)) != __STDC_EMBED_EMPTY__ |
| 112 |
#error "__has_embed fail" |
| 113 |
#endif |
| 114 |
|
| 115 |
#if __has_embed (<../empty.h> __limit__ (42)) != __STDC_EMBED_NOT_FOUND__ |
| 116 |
#error "__has_embed fail" |
| 117 |
#endif |
| 118 |
|
| 119 |
#if __has_embed ("../../empty.h" limit (42)) != __STDC_EMBED_EMPTY__ |
| 120 |
#error "__has_embed fail" |
| 121 |
#endif |
| 122 |
|
| 123 |
#if __has_embed (<../../empty.h> __limit__ (42)) != __STDC_EMBED_EMPTY__ |
| 124 |
#error "__has_embed fail" |
| 125 |
#endif |
| 126 |
|
| 127 |
#if 1 + (2 + (3 + (4 + (5 + (6 + (7 + (8 + (9 + (10 + (11 + (12 + (13 + (14 + \ |
| 128 |
(15 + (16 + (17 + (18 + (19 + (20 + (21 + (22 + (23 + (24 + (25 + (26 + \ |
| 129 |
__has_embed (<magna-carta.txt> limit (17 + (16 + (15 + (14 + (13 \ |
| 130 |
+ 12))))))))))))))))))))))))))))))) != 27 * 26 / 2 + __STDC_EMBED_FOUND__ |
| 131 |
#error "__has_embed fail" |
| 132 |
#endif |
| 133 |
|
| 134 |
#if 0 |
| 135 |
#if __has_embed (<non-existent-file.bin> limit (1 + 2 + 3 + 4)) != 42 |
| 136 |
#error "__has_embed fail" |
| 137 |
#endif |
| 138 |
#endif |
| 139 |
|
| 140 |
#if (0 && __has_embed (<non-existent-file.bin> limit (3))) != 0 |
| 141 |
#error "fail" |
| 142 |
#endif |
| 143 |
|
| 144 |
#if __STDC_VERSION__ >= 202311L || __cplusplus >= 201103L |
| 145 |
static_assert ( |
| 146 |
#embed <embed-1.inc> |
| 147 |
== 'a', ""); |
| 148 |
static_assert ( |
| 149 |
#embed "embed-1.inc" \ |
| 150 |
__limit__ (\ |
| 151 |
0) __if_empty__ (42) __prefix__ ( \ |
| 152 |
256 + ) __suffix__ (+ 17) |
| 153 |
== 42, ""); |
| 154 |
static_assert ( |
| 155 |
#embed "embed-1.inc" limit (42) if_empty (42) prefix (256 + ) suffix (+ 17) |
| 156 |
== 256 + 'a' + 17, ""); |
| 157 |
#endif |
| 158 |
|
| 159 |
int a = |
| 160 |
#embed __FILE__ limit (1) |
| 161 |
; |
| 162 |
int b = |
| 163 |
#embed __FILE__ if_empty (42; int c = 0) limit (0) |
| 164 |
; |
| 165 |
const unsigned char magna_carta[] = { |
| 166 |
#embed <magna-carta.txt> prefix (/* This is a prefix */) suffix (, 0) if_empty (0) |
| 167 |
}; |
| 168 |
const unsigned char d[] = { |
| 169 |
#define MAGNA_CARTA "magna-carta.txt" |
| 170 |
#define MAGNA_CARTA_PARAMS prefix (239, 187, 191,) \ |
| 171 |
suffix (, 0) limit (15) |
| 172 |
#embed MAGNA_CARTA MAGNA_CARTA_PARAMS \ |
| 173 |
\ |
| 174 |
if_empty (0{1[2[3{4(5(6)7)8}9]0]1}2) |
| 175 |
}; |
| 176 |
#ifndef __cplusplus |
| 177 |
const unsigned char e[] = { |
| 178 |
#embed MAGNA_CARTA __limit__ (42) __suffix__ (, [21] = 'X', [22] = 'X', [23] = 'X') |
| 179 |
}; |
| 180 |
#endif |
| 181 |
int f; |
| 182 |
struct S { int a; long b; unsigned short c; long long d; } g = { |
| 183 |
#embed "magna-carta.txt" limit (4) |
| 184 |
}; |
| 185 |
const unsigned char h[] = { |
| 186 |
#embed __FILE__ suffix (, 0) |
| 187 |
}; |
| 188 |
struct T { int a; }; |
| 189 |
struct U { unsigned short a; struct T b; long long c; }; |
| 190 |
struct V { unsigned long long a; struct U b; short int c; int d; }; |
| 191 |
struct V v = { |
| 192 |
#embed "magna-carta.txt" __limit__(4)__prefix__(42,)__suffix__(,-42) |
| 193 |
}; |
| 194 |
#ifndef __cplusplus |
| 195 |
const unsigned char w[] = { |
| 196 |
#embed <magna-carta.txt> prefix([0] = 42, [72] =) limit(1500) |
| 197 |
}; |
| 198 |
#endif |
| 199 |
const unsigned char x[] = { |
| 200 |
#define XIFEMPTY1 0, 1 |
| 201 |
#define XIFEMPTY2 ,3, |
| 202 |
#define XIFEMPTY3 4 |
| 203 |
#embed "../empty.h" if_empty (XIFEMPTY1,2 XIFEMPTY2 \ |
| 204 |
XIFEMPTY3) prefix (5, 6, 7, ) suffix (, 8, 9) |
| 205 |
}; |
| 206 |
const unsigned char y[] = { |
| 207 |
#embed <embed-3.c> suffix(,0) |
| 208 |
}; |
| 209 |
const unsigned char z[] = { |
| 210 |
#embed "embed-3.c" suffix(,0) |
| 211 |
}; |
| 212 |
|
| 213 |
#if 0 |
| 214 |
#embed <non-existent-file.bin> limit (3) |
| 215 |
#endif |
| 216 |
|
| 217 |
#ifdef __cplusplus |
| 218 |
#define C "C" |
| 219 |
#else |
| 220 |
#define C |
| 221 |
#endif |
| 222 |
extern C void abort (void); |
| 223 |
#ifdef __cplusplus |
| 224 |
extern C const char *strstr (const char *, const char *); |
| 225 |
#else |
| 226 |
extern C char *strstr (const char *, const char *); |
| 227 |
#endif |
| 228 |
|
| 229 |
void |
| 230 |
foo (unsigned int a, unsigned long long b, unsigned char c, int d, int e) |
| 231 |
{ |
| 232 |
if (a != 'H' || b != 'e' || c != 'n' || d != 'r' || !e) |
| 233 |
abort (); |
| 234 |
} |
| 235 |
|
| 236 |
int |
| 237 |
main () |
| 238 |
{ |
| 239 |
if (a != '/' || b != 42 || c != 0) |
| 240 |
abort (); |
| 241 |
if (sizeof (magna_carta) != 17893 + 1 |
| 242 |
/* Allow for DOS line endings instead of Unix just in case. */ |
| 243 |
&& sizeof (magna_carta) != 17939 + 1) |
| 244 |
abort (); |
| 245 |
if (!strstr ((const char *) magna_carta, "imprisonétur")) |
| 246 |
abort (); |
| 247 |
if (sizeof (d) != 3 + 15 + 1 |
| 248 |
|| d[0] != 239 || d[1] != 187 || d[2] != 191 || d[3 + 15] != 0) |
| 249 |
abort (); |
| 250 |
#ifndef __cplusplus |
| 251 |
if (sizeof (e) != 42 || e[21] != 'X' || e[22] != 'X' || e[23] != 'X') |
| 252 |
abort (); |
| 253 |
#endif |
| 254 |
f = ( |
| 255 |
#embed "magna-carta.txt" limit (4) prefix (172 + ) suffix (+ 2) |
| 256 |
); |
| 257 |
if (f != 'r' + 2) |
| 258 |
abort (); |
| 259 |
if (g.a != 'H' || g.b != 'e' || g.c != 'n' || g.d != 'r') |
| 260 |
abort (); |
| 261 |
if (!strstr ((const char *) h, "imprisonétur") |
| 262 |
|| !strstr ((const char *) h, "blah blah")) |
| 263 |
abort (); |
| 264 |
if (v.a != 42 || v.b.a != 'H' || v.b.b.a != 'e' |
| 265 |
|| v.b.c != 'n' || v.c != 'r' || v.d != -42) |
| 266 |
abort (); |
| 267 |
#ifndef __cplusplus |
| 268 |
if (sizeof (w) != 1572 || w[0] != 42 || w[1] != 0 || w[71] != 0 |
| 269 |
|| w[72] != 'H' || w[73] != 'e' || w[74] != 'n' || w[75] != 'r') |
| 270 |
abort (); |
| 271 |
#endif |
| 272 |
if (sizeof (x) != 5 || x[0] != 0 || x[1] != 1 || x[2] != 2 |
| 273 |
|| x[3] != 3 || x[4] != 4) |
| 274 |
abort (); |
| 275 |
foo ( |
| 276 |
#embed <magna-carta.txt> limit(5) |
| 277 |
); |
| 278 |
if (sizeof (y) > 100 |
| 279 |
|| !strstr ((const char *) y, "Dummy file.") |
| 280 |
|| strstr ((const char *) y, "__gnu__::__non_existent_parameter")) |
| 281 |
abort (); |
| 282 |
if (sizeof (z) < 100 |
| 283 |
|| strstr ((const char *) z, "Dummy file.") |
| 284 |
|| !strstr ((const char *) z, "__gnu__::__non_existent_parameter")) |
| 285 |
abort (); |
| 286 |
if (sizeof ( |
| 287 |
#embed "embed-1.inc" |
| 288 |
) != sizeof (int)) |
| 289 |
abort (); |
| 290 |
#ifndef __cplusplus |
| 291 |
if (_Generic ( |
| 292 |
#embed "embed-1.inc" __limit__ (1) __suffix__ (, int: 42, default: 0) |
| 293 |
) != 42) |
| 294 |
abort (); |
| 295 |
#endif |
| 296 |
#if __STDC_VERSION__ >= 202311L |
| 297 |
typeof ( |
| 298 |
#embed "embed-1.inc" limit (1) |
| 299 |
) j; |
| 300 |
if (sizeof (j) != sizeof (int)) |
| 301 |
abort (); |
| 302 |
#elif __cplusplus >= 201103L |
| 303 |
decltype ( |
| 304 |
#embed "embed-1.inc" limit (1) |
| 305 |
) j; |
| 306 |
if (sizeof (j) != sizeof (int)) |
| 307 |
abort (); |
| 308 |
#endif |
| 309 |
#if __has_embed ("embed-5.c" ds9000::element_type(short)) |
| 310 |
short meow[] = { |
| 311 |
#embed "embed-5.c" ds9000::element_type(short) |
| 312 |
}; |
| 313 |
#elif __has_embed ("embed-5.c") |
| 314 |
const unsigned char meow_bytes[] = { |
| 315 |
#embed "embed-5.c" |
| 316 |
}; |
| 317 |
short meow[sizeof (meow_bytes) / sizeof (short)] = {}; |
| 318 |
for (int i = 0; i < (int) (sizeof (meow) / sizeof (short)); i++) |
| 319 |
meow[i] = (meow_bytes[i * 2] << 8) | meow_bytes[i * 2 + 1]; |
| 320 |
#else |
| 321 |
#error "cannot find embed-5.c resource" |
| 322 |
#endif |
| 323 |
if (meow[0] != ('/' << 8) + '*') |
| 324 |
abort (); |
| 325 |
#if __has_embed("././././embed-1.c" __limit__(1)) |
| 326 |
if ( |
| 327 |
#embed "././././embed-1.c" /* This */ limit /* is */ ( /* a */ 1 /*comment*/) // . |
| 328 |
!= '/') |
| 329 |
abort (); |
| 330 |
#else |
| 331 |
#error "__has_embed fail" |
| 332 |
#endif |
| 333 |
} |