Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^^^^^
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/CodeGen/CGExprComplex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
15 changes: 15 additions & 0 deletions clang/test/CodeGen/complex.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}