-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Clang] [Sema] Fix bug in _Complex float
+int
arithmetic
#83063
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5418bec
[Clang] [Sema] Remove incorrect int-to-complex-float conversion
Sirraide 15325bd
Merge branch 'main' into complex-float
Sirraide 322b22a
[Clang] Update release notes
Sirraide d049edb
[NFC] Update comments and rename function
Sirraide 0645428
[Clang] Use -ast-dump to check for FloatingRealToComplex casts
Sirraide File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
// RUN: %clang_cc1 %s -O0 -emit-llvm -triple x86_64-unknown-unknown -o - | FileCheck %s --check-prefix=X86 | ||
// RUN: %clang_cc1 %s -O0 -triple x86_64-unknown-unknown -fsyntax-only -ast-dump | FileCheck %s --check-prefix=AST | ||
|
||
// Check that for 'F _Complex + int' (F = real floating-point type), we emit an | ||
// implicit cast from 'int' to 'F', but NOT to 'F _Complex' (i.e. that we do | ||
// 'F _Complex + F', NOT 'F _Complex + F _Complex'), and likewise for -/*. | ||
|
||
// AST-NOT: FloatingRealToComplex | ||
|
||
float _Complex add_float_ci(float _Complex a, int b) { | ||
// X86-LABEL: @add_float_ci | ||
// X86: [[I:%.*]] = sitofp i32 {{%.*}} to float | ||
// X86: fadd float {{.*}}, [[I]] | ||
// X86-NOT: fadd | ||
return a + b; | ||
} | ||
|
||
float _Complex add_float_ic(int a, float _Complex b) { | ||
// X86-LABEL: @add_float_ic | ||
// X86: [[I:%.*]] = sitofp i32 {{%.*}} to float | ||
// X86: fadd float [[I]] | ||
// X86-NOT: fadd | ||
return a + b; | ||
} | ||
|
||
float _Complex sub_float_ci(float _Complex a, int b) { | ||
// X86-LABEL: @sub_float_ci | ||
// X86: [[I:%.*]] = sitofp i32 {{%.*}} to float | ||
// X86: fsub float {{.*}}, [[I]] | ||
// X86-NOT: fsub | ||
return a - b; | ||
} | ||
|
||
float _Complex sub_float_ic(int a, float _Complex b) { | ||
// X86-LABEL: @sub_float_ic | ||
// X86: [[I:%.*]] = sitofp i32 {{%.*}} to float | ||
// X86: fsub float [[I]] | ||
// X86: fneg | ||
// X86-NOT: fsub | ||
return a - b; | ||
} | ||
|
||
float _Complex mul_float_ci(float _Complex a, int b) { | ||
// X86-LABEL: @mul_float_ci | ||
// X86: [[I:%.*]] = sitofp i32 {{%.*}} to float | ||
// X86: fmul float {{.*}}, [[I]] | ||
// X86: fmul float {{.*}}, [[I]] | ||
// X86-NOT: fmul | ||
return a * b; | ||
} | ||
|
||
float _Complex mul_float_ic(int a, float _Complex b) { | ||
// X86-LABEL: @mul_float_ic | ||
// X86: [[I:%.*]] = sitofp i32 {{%.*}} to float | ||
// X86: fmul float [[I]] | ||
// X86: fmul float [[I]] | ||
// X86-NOT: fmul | ||
return a * b; | ||
} | ||
|
||
float _Complex div_float_ci(float _Complex a, int b) { | ||
// X86-LABEL: @div_float_ci | ||
// X86: [[I:%.*]] = sitofp i32 {{%.*}} to float | ||
// X86: fdiv float {{.*}}, [[I]] | ||
// X86: fdiv float {{.*}}, [[I]] | ||
// X86-NOT: @__divsc3 | ||
return a / b; | ||
} | ||
|
||
// There is no good way of doing this w/o converting the 'int' to a complex | ||
// number, so we expect complex division here. | ||
float _Complex div_float_ic(int a, float _Complex b) { | ||
// X86-LABEL: @div_float_ic | ||
// X86: [[I:%.*]] = sitofp i32 {{%.*}} to float | ||
// X86: call {{.*}} @__divsc3(float {{.*}} [[I]], float noundef 0.{{0+}}e+00, float {{.*}}, float {{.*}}) | ||
return a / b; | ||
} | ||
|
||
double _Complex add_double_ci(double _Complex a, int b) { | ||
// X86-LABEL: @add_double_ci | ||
// X86: [[I:%.*]] = sitofp i32 {{%.*}} to double | ||
// X86: fadd double {{.*}}, [[I]] | ||
// X86-NOT: fadd | ||
return a + b; | ||
} | ||
|
||
double _Complex add_double_ic(int a, double _Complex b) { | ||
// X86-LABEL: @add_double_ic | ||
// X86: [[I:%.*]] = sitofp i32 {{%.*}} to double | ||
// X86: fadd double [[I]] | ||
// X86-NOT: fadd | ||
return a + b; | ||
} | ||
|
||
double _Complex sub_double_ci(double _Complex a, int b) { | ||
// X86-LABEL: @sub_double_ci | ||
// X86: [[I:%.*]] = sitofp i32 {{%.*}} to double | ||
// X86: fsub double {{.*}}, [[I]] | ||
// X86-NOT: fsub | ||
return a - b; | ||
} | ||
|
||
double _Complex sub_double_ic(int a, double _Complex b) { | ||
// X86-LABEL: @sub_double_ic | ||
// X86: [[I:%.*]] = sitofp i32 {{%.*}} to double | ||
// X86: fsub double [[I]] | ||
// X86: fneg | ||
// X86-NOT: fsub | ||
return a - b; | ||
} | ||
|
||
double _Complex mul_double_ci(double _Complex a, int b) { | ||
// X86-LABEL: @mul_double_ci | ||
// X86: [[I:%.*]] = sitofp i32 {{%.*}} to double | ||
// X86: fmul double {{.*}}, [[I]] | ||
// X86: fmul double {{.*}}, [[I]] | ||
// X86-NOT: fmul | ||
return a * b; | ||
} | ||
|
||
double _Complex mul_double_ic(int a, double _Complex b) { | ||
// X86-LABEL: @mul_double_ic | ||
// X86: [[I:%.*]] = sitofp i32 {{%.*}} to double | ||
// X86: fmul double [[I]] | ||
// X86: fmul double [[I]] | ||
// X86-NOT: fmul | ||
return a * b; | ||
} | ||
|
||
double _Complex div_double_ci(double _Complex a, int b) { | ||
// X86-LABEL: @div_double_ci | ||
// X86: [[I:%.*]] = sitofp i32 {{%.*}} to double | ||
// X86: fdiv double {{.*}}, [[I]] | ||
// X86: fdiv double {{.*}}, [[I]] | ||
// X86-NOT: @__divdc3 | ||
Sirraide marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return a / b; | ||
} | ||
|
||
// There is no good way of doing this w/o converting the 'int' to a complex | ||
// number, so we expect complex division here. | ||
double _Complex div_double_ic(int a, double _Complex b) { | ||
// X86-LABEL: @div_double_ic | ||
// X86: [[I:%.*]] = sitofp i32 {{%.*}} to double | ||
// X86: call {{.*}} @__divdc3(double {{.*}} [[I]], double noundef 0.{{0+}}e+00, double {{.*}}, double {{.*}}) | ||
return a / b; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// RUN: %clang_cc1 -verify %s | ||
// expected-no-diagnostics | ||
|
||
// This tests evaluation of _Complex arithmetic at compile time. | ||
|
||
#define APPROX_EQ(a, b) ( \ | ||
__builtin_fabs(__real (a) - __real (b)) < 0.0001 && \ | ||
__builtin_fabs(__imag (a) - __imag (b)) < 0.0001 \ | ||
) | ||
|
||
#define EVAL(a, b) _Static_assert(a == b, "") | ||
#define EVALF(a, b) _Static_assert(APPROX_EQ(a, b), "") | ||
|
||
// _Complex float + _Complex float | ||
void a() { | ||
EVALF((2.f + 3i) + (4.f + 5i), 6.f + 8i); | ||
EVALF((2.f + 3i) - (4.f + 5i), -2.f - 2i); | ||
EVALF((2.f + 3i) * (4.f + 5i), -7.f + 22i); | ||
EVALF((2.f + 3i) / (4.f + 5i), 0.5609f + 0.0487i); | ||
|
||
EVALF((2. + 3i) + (4. + 5i), 6. + 8i); | ||
EVALF((2. + 3i) - (4. + 5i), -2. - 2i); | ||
EVALF((2. + 3i) * (4. + 5i), -7. + 22i); | ||
EVALF((2. + 3i) / (4. + 5i), .5609 + .0487i); | ||
} | ||
|
||
// _Complex int + _Complex int | ||
void b() { | ||
EVAL((2 + 3i) + (4 + 5i), 6 + 8i); | ||
EVAL((2 + 3i) - (4 + 5i), -2 - 2i); | ||
EVAL((2 + 3i) * (4 + 5i), -7 + 22i); | ||
EVAL((8 + 30i) / (4 + 5i), 4 + 1i); | ||
} | ||
|
||
// _Complex float + float | ||
void c() { | ||
EVALF((2.f + 4i) + 3.f, 5.f + 4i); | ||
EVALF((2.f + 4i) - 3.f, -1.f + 4i); | ||
EVALF((2.f + 4i) * 3.f, 6.f + 12i); | ||
EVALF((2.f + 4i) / 2.f, 1.f + 2i); | ||
|
||
EVALF(3.f + (2.f + 4i), 5.f + 4i); | ||
EVALF(3.f - (2.f + 4i), 1.f - 4i); | ||
EVALF(3.f * (2.f + 4i), 6.f + 12i); | ||
EVALF(3.f / (2.f + 4i), .3f - 0.6i); | ||
|
||
EVALF((2. + 4i) + 3., 5. + 4i); | ||
EVALF((2. + 4i) - 3., -1. + 4i); | ||
EVALF((2. + 4i) * 3., 6. + 12i); | ||
EVALF((2. + 4i) / 2., 1. + 2i); | ||
|
||
EVALF(3. + (2. + 4i), 5. + 4i); | ||
EVALF(3. - (2. + 4i), 1. - 4i); | ||
EVALF(3. * (2. + 4i), 6. + 12i); | ||
EVALF(3. / (2. + 4i), .3 - 0.6i); | ||
} | ||
|
||
// _Complex int + int | ||
void d() { | ||
EVAL((2 + 4i) + 3, 5 + 4i); | ||
EVAL((2 + 4i) - 3, -1 + 4i); | ||
EVAL((2 + 4i) * 3, 6 + 12i); | ||
EVAL((2 + 4i) / 2, 1 + 2i); | ||
|
||
EVAL(3 + (2 + 4i), 5 + 4i); | ||
EVAL(3 - (2 + 4i), 1 - 4i); | ||
EVAL(3 * (2 + 4i), 6 + 12i); | ||
EVAL(20 / (2 + 4i), 2 - 4i); | ||
} | ||
|
||
// _Complex float + int | ||
void e() { | ||
EVALF((2.f + 4i) + 3, 5.f + 4i); | ||
EVALF((2.f + 4i) - 3, -1.f + 4i); | ||
EVALF((2.f + 4i) * 3, 6.f + 12i); | ||
EVALF((2.f + 4i) / 2, 1.f + 2i); | ||
|
||
EVALF(3 + (2.f + 4i), 5.f + 4i); | ||
EVALF(3 - (2.f + 4i), 1.f - 4i); | ||
EVALF(3 * (2.f + 4i), 6.f + 12i); | ||
EVALF(3 / (2.f + 4i), .3f - 0.6i); | ||
|
||
EVALF((2. + 4i) + 3, 5. + 4i); | ||
EVALF((2. + 4i) - 3, -1. + 4i); | ||
EVALF((2. + 4i) * 3, 6. + 12i); | ||
EVALF((2. + 4i) / 2, 1. + 2i); | ||
|
||
EVALF(3 + (2. + 4i), 5. + 4i); | ||
EVALF(3 - (2. + 4i), 1. - 4i); | ||
EVALF(3 * (2. + 4i), 6. + 12i); | ||
EVALF(3 / (2. + 4i), .3 - 0.6i); | ||
} | ||
|
||
// _Complex int + float | ||
void f() { | ||
EVALF((2 + 4i) + 3.f, 5.f + 4i); | ||
EVALF((2 + 4i) - 3.f, -1.f + 4i); | ||
EVALF((2 + 4i) * 3.f, 6.f + 12i); | ||
EVALF((2 + 4i) / 2.f, 1.f + 2i); | ||
|
||
EVALF(3.f + (2 + 4i), 5.f + 4i); | ||
EVALF(3.f - (2 + 4i), 1.f - 4i); | ||
EVALF(3.f * (2 + 4i), 6.f + 12i); | ||
EVALF(3.f / (2 + 4i), .3f - 0.6i); | ||
|
||
EVALF((2 + 4i) + 3., 5. + 4i); | ||
EVALF((2 + 4i) - 3., -1. + 4i); | ||
EVALF((2 + 4i) * 3., 6. + 12i); | ||
EVALF((2 + 4i) / 2., 1. + 2i); | ||
|
||
EVALF(3. + (2 + 4i), 5. + 4i); | ||
EVALF(3. - (2 + 4i), 1. - 4i); | ||
EVALF(3. * (2 + 4i), 6. + 12i); | ||
EVALF(3. / (2 + 4i), .3 - 0.6i); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.