Issue 120822
Summary Off-by-one error in _expression_ mangling of parameter reference in lambda
Labels clang, c++14, miscompilation
Assignees
Reporter hubert-reinterpretcast
    According to the Itanium C++ ABI, the _expression_ mangling for a function parameter involves a number `L` where `L` is `1` when referencing a parameter of the current function declarator within its parameter declaration clause.

In the case where `L` is one, the parameter reference is represented with a prefix of `fL0p` (that is with the value of `L` - 1 after the "L").

Consider the source below.

The value of `L` should be `1`; however, the mangling used for `x` is `_ZZZ1fvENKUlT_DtfL1p_EE_clIiEEDaS_S0_E1x` (with `fL1p` instead of the expected `fL0p`). Oddly enough, the typeinfo string for the closure type (`Z1fvEUlT_DtfL0p_EE_`) has `fL0p` as expected.

GCC has an off-by-one error in the opposite direction: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118144
Online compiler link: https://godbolt.org/z/51E9Yjvxf

### SOURCE (`<stdin>`)
```cpp
inline auto f() {
  return [](auto p, decltype(p)) {
    static int x = 0;
 return &x;
  };
}
void g() { throw f(); }
auto h() { return f()(0, 0); }
```

### COMPILER INVOCATION
```
clang++ -std=c++17 -xc++ - -O -S -emit-llvm -o -
```

### ACTUAL COMPILER OUTPUT (partial)
```
  ret ptr @_ZZZ1fvENKUlT_DtfL1p_EE_clIiEEDaS_S0_E1x
```

### EXPECTED COMPILER OUTPUT (partial)
```
  ret ptr @_ZZZ1fvENKUlT_DtfL0p_EE_clIiEEDaS_S0_E1x
```

### COMPILER VERSION INFO (`clang++ -v`)
```
clang version 20.0.0git (https://github.com/llvm/llvm-project.git 44514316bd5ef656076b6baaf6bccb298d98f0ea)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/wandbox/clang-head/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/13
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/14
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/14
Candidate multilib: .;@m64
Selected multilib: .;@m64
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to