[PATCH] D155572: [clang][Interp] Start implementing binary operators for complex types

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 14 08:01:32 PDT 2023


aaron.ballman added a comment.

In D155572#4645995 <https://reviews.llvm.org/D155572#4645995>, @tbaeder wrote:

> In D155572#4542484 <https://reviews.llvm.org/D155572#4542484>, @aaron.ballman wrote:
>
>> In D155572#4541403 <https://reviews.llvm.org/D155572#4541403>, @tbaeder wrote:
>>
>>> In D155572#4539457 <https://reviews.llvm.org/D155572#4539457>, @aaron.ballman wrote:
>>>
>>>> Is this intended to not handle all the binary operators in this patch?
>>>
>>> Yes, just a subset for now.
>>>
>>>> And also, is this intended to only impact initializers?
>>>
>>> Yes, due to problems with (non-)initializers. This should work after https://reviews.llvm.org/D156027 though.
>>
>> Okay, thanks for confirmation! The only outstanding thing is adding coverage for typedef types:
>>
>>   using Frobble = float;
>>   using Bobble = _Complex float;
>>   using Gobble = _Complex Frobble;
>>   
>>   constexpr _Complex Frobble A = { 13.0, 2.0 };
>>   constexpr Bobble B = { 2.0, 1.0  };
>>   constexpr Gobble C = { 3.0, 5.0 };
>>   constexpr _Complex float D = A - B;
>>   constexpr _Complex float E = C - B;
>>   static_assert(__real(D) == 11.0, "");
>>   static_assert(__imag(D) == 1.0, "");
>>   static_assert(__real(E) == 1.0, "");
>>   static_assert(__imag(E) == 4.0, "");
>
> https://godbolt.org/z/59c8Y4sqz - Is that even supposed to work?

Hmmm, I think the answer is "no"... and "maybe." `_Complex` can only be followed by `float`, `double`, or `long double` specifically per the C standard. However, we also support `_Complex int` (and others) as an extension, which starts to make `_Complex` look more like `_Atomic` in that it augments an existing type, and so typedefs seem quite reasonable.

But that's not your issue to worry about. Instead, let's go with this test:

  using Bobble = _Complex float;
  
  constexpr _Complex float A = { 13.0, 2.0 };
  constexpr Bobble B = { 2.0, 1.0  };
  constexpr _Complex float D = A - B;
  static_assert(__real(D) == 11.0, "");
  static_assert(__imag(D) == 1.0, "");

https://godbolt.org/z/Mrxfjzrnz


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155572/new/

https://reviews.llvm.org/D155572



More information about the cfe-commits mailing list