llvm / llvm/llvm-project

Clang reject valid code when explict cast to _Atomic _Complex in BinExpr

Open
#190,035 2 comments 0 reactions 0 assignees View on GitHub
clang:frontend rejects-valid
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Clang rejects a valid complex binary op when explicitly casting to `_Atomic _Complex`

```c
void explicit_cast_to_atomic_complex() {
_Atomic _Complex float a;
_Complex float b;
a += (_Atomic _Complex float) b;
}
```

Or even if b type is atomic

```
void explicit_cast_to_atomic_complex() {
_Atomic _Complex float a;
_Atomic _Complex float b;
a += (_Atomic _Complex float) b;
}
```

Godbolt: https://godbolt.org/z/ET84bfjhG

Output:

```
invalid operands to binary expression ('_Atomic(_Complex double)' and '_Atomic(_Complex double)')
```

Accepted by clang

```
void explicit_cast_to_atomic_complex() {
_Atomic _Complex float a;
_Complex float b;
a += b;
}
```

Godbolt: https://godbolt.org/z/cGTazb16T

And it accepts it if we remove the explicit cast, I guess the problem is related to `AtomicUnqualified` when checking equality in Sema for this bin op

Contributor guide

Open the contributing guide

Research direction

Start by compiling the two `_Atomic _Complex` reproductions from the issue with Clang and compare them with the accepted uncast example. Then inspect Clang's Sema handling of atomic type equality in binary-expression checking, particularly the suspected `AtomicUnqualified` path. Done means both explicitly cast examples compile without the invalid-operands diagnostic while existing behavior remains intact.

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
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.