llvm / llvm/llvm-project

clang incorrectly expands trigraphs when pasting tokens

Open
#158,360 5 comments 0 reactions 0 assignees View on GitHub
clang:frontend confirmed
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

This program prints `|`, but it should print `??!`.

```c
#include

#define PASTE(X, Y) X ## Y

int main(void) {
printf("%ls\n", PASTE(L, "??\
!"));
}
```

After pasting the tokens `L` and `"??!"`, clang incorrectly expands the trigraph inside of the second token.

https://godbolt.org/z/s7esnTdjz

Contributor guide

Open the contributing guide

Research direction

Start by compiling and running the provided program, then inspect clang's preprocessor handling of trigraphs during token pasting. Trace the handling of the pasted L and string tokens and add a regression test covering the example, with completion shown by the program producing the expected ??! output.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.