[all-commits] [llvm/llvm-project] 69afb9: [Clang] [Sema] Fix bug in `_Complex float`+`int` a...
Sirraide via All-commits
all-commits at lists.llvm.org
Wed Mar 13 09:39:44 PDT 2024
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 69afb9d7875d79fdacaaa2f22b5ee3a06faf5373
https://github.com/llvm/llvm-project/commit/69afb9d7875d79fdacaaa2f22b5ee3a06faf5373
Author: Sirraide <aeternalmail at gmail.com>
Date: 2024-03-13 (Wed, 13 Mar 2024)
Changed paths:
M clang/docs/ReleaseNotes.rst
M clang/lib/Sema/SemaExpr.cpp
A clang/test/CodeGen/complex-math-mixed.c
M clang/test/CodeGen/volatile.cpp
A clang/test/Sema/complex-arithmetic.c
Log Message:
-----------
[Clang] [Sema] Fix bug in `_Complex float`+`int` arithmetic (#83063)
C23 6.3.1.8 ‘Usual arithmetic conversions’ p1 states (emphasis mine):
> Otherwise, if the corresponding real type of either operand is
`float`, the other operand is converted, *without change of type
domain*, to a type whose corresponding real type is `float`.
‘type domain’ here refers to `_Complex` vs real (i.e. non-`_Complex`);
there is another clause that states the same for `double`.
Consider the following code:
```c++
_Complex float f;
int x;
f / x;
```
After talking this over with @AaronBallman, we came to the conclusion
that `x` should be converted to `float` and *not* `_Complex float` (that
is, we should perform a division of `_Complex float / float`, and *not*
`_Complex float / _Complex float`; the same also applies to `-+*`). This
was already being done correctly for cases where `x` was already a
`float`; it’s just mixed `_Complex float`+`int` operations that
currently suffer from this problem.
This pr removes the extra `FloatingRealToComplex` conversion that we
were erroneously inserting and adds some tests to make sure we’re
actually doing `_Complex float / float` and not `_Complex float /
_Complex float` (and analogously for `double` and `-+*`).
The only exception here is `float / _Complex float`, which calls a
library function (`__divsc3`) that takes 4 `float`s, so we end up having
to convert the `float` to a `_Complex float` after all (and analogously
for `double`); I don’t believe there is a way around this.
Lastly, we were also missing tests for `_Complex` arithmetic at compile
time, so this adds some tests for that as well.
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list