Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang-cl does not support concatenation of predefined identifiers #63563

Closed
RIscRIpt opened this issue Jun 27, 2023 · 1 comment
Closed

clang-cl does not support concatenation of predefined identifiers #63563

RIscRIpt opened this issue Jun 27, 2023 · 1 comment
Labels

Comments

@RIscRIpt
Copy link
Member

According to MSDN __FUNCDNAME__, __FUNCSIG__, and __FUNCTION__ are non-expandible macros defined as string literals. So, they may be concatenated with other string literals (Compiler Explorer link):

extern "C" int printf(const char*, ...);

void F() {
    printf("Function name: " __FUNCTION__ "\n");
    printf("Decorated function name: " __FUNCDNAME__ "\n");
    printf("Function signature: " __FUNCSIG__ "\n");
}

Currently clang in ms-compatible mode does not support this.

Relevant issue: #12161

@RIscRIpt
Copy link
Member Author

I've tried to tackle this problem in two approaches:

  1. Make expansion of predefined literals directly in StringLiteralParser, however I stumbled upon a fact that I need access to AST in Lex (which is unreasonable to link them together; namely I needed access to PredefinedExpr::ComputeName).
  2. Replace tokens of predefined literals in in Sema::ActOnStringLiteral with string-literal tokens (from scratch buffer).

Yes, (2) feels hacky, but I couldn't came up with any other approach, and unfortunately, it seems that support of this MSFT extension doesn't fit well into the current architecture of clang. Anyways, I've submitted my patch for review; feel free to reject it.

searlmc1 pushed a commit to ROCm/llvm-project that referenced this issue Sep 6, 2023
Predefined identifiers like __FUNCTION__ are treated like string
literals in MSVC, which means they can be concatentated together with
an adjacent string literal. Clang now supports this behavior as well,
in Microsoft extensions mode.

Fixes llvm#63563
Differential Revision: https://reviews.llvm.org/D153914

Change-Id: I0ad452508b78acdd189f612eb8e70b4be93b7df6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants