[clang] [clang-tools-extra] Reland [clang][Sema, Lex, Parse] Preprocessor embed in C and C++ (PR #95802)
Jakub JelĂnek via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 15 17:01:27 PDT 2024
jakubjelinek wrote:
@ThePhD @AaronBallman @cor3ntin
Joseph Myers raised an interesting question whether the tokens in embed-parameter-sequence are macro expanded or not.
Consider
```c
#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)
```
The first #embed is I hope clear in that it is the #embed pp-tokens new-line case where everything gets macro expanded.
The second case is less clear, the filename part matches the " q-char-sequence " case, but LIMIT suffix(THIS) PRE ) is not valid embed-parameter-sequence, so shouldn't it be expanded too?
And the last case by strict reading shouldn't be macro expanded because it is valid embed-parameter-sequence, still
both the the.phd branch and clang trunk and also my GCC patchset handle it as prefix (4) suffix(, 1, 2, 3).
Would in that reading #embed "/etc/passwd" LIMIT suffix(THIS) be valid too and thus not macro expanded and thus later invalid?
And, if embed-parameter-sequence tokens are macro expanded only sometimes, what should happen say with
#define ARG 2) if_empty (1
#embed "file" limit (ARG)
?
On
```c
#define A "/etc/passwd" limit (1) ) + (0
#if __has_embed (A)
int i;
#endif
```
also all 3 compilers agree and happily use the closing ) from the macro to use the ) from the macro expansion for the closing ) of __has_embed and continue through to the rest of the expression. Or is __has_embed supposed to be always macro expanded?
https://github.com/llvm/llvm-project/pull/95802
More information about the cfe-commits
mailing list