-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[clang] Fixed a crash when explicitly casting to atomic complex #172163
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
base: main
Are you sure you want to change the base?
[clang] Fixed a crash when explicitly casting to atomic complex #172163
Conversation
|
@llvm/pr-subscribers-clang-codegen Author: Amr Hesham (AmrDeveloper) ChangesFixed a crash when explicitly casting a scalar to an atomic complex. Issue: #114885 Full diff: https://github.com/llvm/llvm-project/pull/172163.diff 3 Files Affected:
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index feaf92ad4415f..16f983fe82ddd 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -800,6 +800,7 @@ Crash and bug fixes
containing a single colon. (#GH167905)
- Fixed a crash when parsing malformed #pragma clang loop vectorize_width(4,8,16)
by diagnosing invalid comma-separated argument lists. (#GH166325)
+- Fixed a crash when explicitly casting a scalar to an atomic complex. (#GH114885)
Improvements
^^^^^^^^^^^^
diff --git a/clang/lib/CodeGen/CGExprComplex.cpp b/clang/lib/CodeGen/CGExprComplex.cpp
index e5815ef1130dc..c8f8bda5d567e 100644
--- a/clang/lib/CodeGen/CGExprComplex.cpp
+++ b/clang/lib/CodeGen/CGExprComplex.cpp
@@ -533,6 +533,8 @@ ComplexPairTy ComplexExprEmitter::EmitScalarToComplexCast(llvm::Value *Val,
QualType DestType,
SourceLocation Loc) {
// Convert the input element to the element type of the complex.
+ if (DestType->isAtomicType())
+ DestType = DestType->castAs<AtomicType>()->getValueType();
DestType = DestType->castAs<ComplexType>()->getElementType();
Val = CGF.EmitScalarConversion(Val, SrcType, DestType, Loc);
diff --git a/clang/test/CodeGen/complex.c b/clang/test/CodeGen/complex.c
index 91fc9dda72f72..c2f95b93e3016 100644
--- a/clang/test/CodeGen/complex.c
+++ b/clang/test/CodeGen/complex.c
@@ -593,3 +593,18 @@ void imag_on_scalar_with_type_promotion() {
_Float16 _Complex a;
_Float16 b = __real__(__imag__ a);
}
+
+// CHECK-LABEL: define dso_local void @explicit_cast_scalar_to_atomic_complex(
+// CHECK-SAME: ) #[[ATTR0]] {
+// CHECK-NEXT: [[ENTRY:.*:]]
+// CHECK-NEXT: [[A:%.*]] = alloca { float, float }, align 8
+// CHECK-NEXT: [[A_REALP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[A]], i32 0, i32 0
+// CHECK-NEXT: [[A_IMAGP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[A]], i32 0, i32 1
+// CHECK-NEXT: store float 2.000000e+00, ptr [[A_REALP]], align 8
+// CHECK-NEXT: store float 0.000000e+00, ptr [[A_IMAGP]], align 4
+// CHECK-NEXT: ret void
+//
+void explicit_cast_scalar_to_atomic_complex() {
+ _Atomic _Complex float a = (_Atomic _Complex float)2.0f;
+}
+
|
|
@llvm/pr-subscribers-clang Author: Amr Hesham (AmrDeveloper) ChangesFixed a crash when explicitly casting a scalar to an atomic complex. Issue: #114885 Full diff: https://github.com/llvm/llvm-project/pull/172163.diff 3 Files Affected:
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index feaf92ad4415f..16f983fe82ddd 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -800,6 +800,7 @@ Crash and bug fixes
containing a single colon. (#GH167905)
- Fixed a crash when parsing malformed #pragma clang loop vectorize_width(4,8,16)
by diagnosing invalid comma-separated argument lists. (#GH166325)
+- Fixed a crash when explicitly casting a scalar to an atomic complex. (#GH114885)
Improvements
^^^^^^^^^^^^
diff --git a/clang/lib/CodeGen/CGExprComplex.cpp b/clang/lib/CodeGen/CGExprComplex.cpp
index e5815ef1130dc..c8f8bda5d567e 100644
--- a/clang/lib/CodeGen/CGExprComplex.cpp
+++ b/clang/lib/CodeGen/CGExprComplex.cpp
@@ -533,6 +533,8 @@ ComplexPairTy ComplexExprEmitter::EmitScalarToComplexCast(llvm::Value *Val,
QualType DestType,
SourceLocation Loc) {
// Convert the input element to the element type of the complex.
+ if (DestType->isAtomicType())
+ DestType = DestType->castAs<AtomicType>()->getValueType();
DestType = DestType->castAs<ComplexType>()->getElementType();
Val = CGF.EmitScalarConversion(Val, SrcType, DestType, Loc);
diff --git a/clang/test/CodeGen/complex.c b/clang/test/CodeGen/complex.c
index 91fc9dda72f72..c2f95b93e3016 100644
--- a/clang/test/CodeGen/complex.c
+++ b/clang/test/CodeGen/complex.c
@@ -593,3 +593,18 @@ void imag_on_scalar_with_type_promotion() {
_Float16 _Complex a;
_Float16 b = __real__(__imag__ a);
}
+
+// CHECK-LABEL: define dso_local void @explicit_cast_scalar_to_atomic_complex(
+// CHECK-SAME: ) #[[ATTR0]] {
+// CHECK-NEXT: [[ENTRY:.*:]]
+// CHECK-NEXT: [[A:%.*]] = alloca { float, float }, align 8
+// CHECK-NEXT: [[A_REALP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[A]], i32 0, i32 0
+// CHECK-NEXT: [[A_IMAGP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[A]], i32 0, i32 1
+// CHECK-NEXT: store float 2.000000e+00, ptr [[A_REALP]], align 8
+// CHECK-NEXT: store float 0.000000e+00, ptr [[A_IMAGP]], align 4
+// CHECK-NEXT: ret void
+//
+void explicit_cast_scalar_to_atomic_complex() {
+ _Atomic _Complex float a = (_Atomic _Complex float)2.0f;
+}
+
|
|
I was thinking of a utility or helper function to getComplexElementType because we have in many places casting type to complex directly without checking if it has an AtomicType wrapper, for example ComplexPairTy ComplexExprEmitter::EmitComplexToComplexCast(ComplexPairTy Val,
QualType SrcType,
QualType DestType,
SourceLocation Loc) {
// Get the src/dest element type.
SrcType = SrcType->castAs<ComplexType>()->getElementType();
DestType = DestType->castAs<ComplexType>()->getElementType(); |
You could use this syntax. |
Fixed a crash when explicitly casting a scalar to an atomic complex.
resolve: #114885