llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

clang-cl does not support concatenation of predefined identifiers

Open RIscRIpt opened this issue 2 years ago • 1 comments

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 avatar Jun 27 '23 20:06 RIscRIpt

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.

RIscRIpt avatar Jun 27 '23 20:06 RIscRIpt