Author: abataev Date: Mon Nov 7 12:15:02 2016 New Revision: 286129 URL: http://llvm.org/viewvc/llvm-project?rev=286129&view=rev Log: [OPENMP] Fixed codegen for __real/__imag expressions in atomic constructs.
For __real/__imag unary expressions clang emits lvalue with the associated type from the original complex expression, but not the underlying builtin integer or float type. This causes crash in codegen for atomic constructs, if __real/__imag expression are used in atomic constructs. Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp cfe/trunk/test/OpenMP/atomic_write_codegen.c Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=286129&r1=286128&r2=286129&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGExpr.cpp (original) +++ cfe/trunk/lib/CodeGen/CGExpr.cpp Mon Nov 7 12:15:02 2016 @@ -2276,13 +2276,15 @@ LValue CodeGenFunction::EmitUnaryOpLValu return LV; } - assert(E->getSubExpr()->getType()->isAnyComplexType()); + QualType T = ExprTy->castAs<ComplexType>()->getElementType(); Address Component = (E->getOpcode() == UO_Real ? emitAddrOfRealComponent(LV.getAddress(), LV.getType()) : emitAddrOfImagComponent(LV.getAddress(), LV.getType())); - return MakeAddrLValue(Component, ExprTy, LV.getAlignmentSource()); + LValue ElemLV = MakeAddrLValue(Component, T, LV.getAlignmentSource()); + ElemLV.getQuals().addQualifiers(LV.getQuals()); + return ElemLV; } case UO_PreInc: case UO_PreDec: { Modified: cfe/trunk/test/OpenMP/atomic_write_codegen.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/atomic_write_codegen.c?rev=286129&r1=286128&r2=286129&view=diff ============================================================================== --- cfe/trunk/test/OpenMP/atomic_write_codegen.c (original) +++ cfe/trunk/test/OpenMP/atomic_write_codegen.c Mon Nov 7 12:15:02 2016 @@ -78,6 +78,9 @@ float2 float2x; register int rix __asm__("esp"); int main() { +// CHECK: store atomic i32 1, i32* getelementptr inbounds ({ i32, i32 }, { i32, i32 }* @civ, i32 0, i32 1) monotonic, +#pragma omp atomic write + __imag(civ) = 1; // CHECK: load i8, i8* // CHECK: store atomic i8 #pragma omp atomic write _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits