From: Alexey Bataev Date: Thu, 12 Oct 2017 15:18:41 +0000 (+0000) Subject: [OPENMP] Fix PR34926: Fix handling of the array sections passed as X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b33432c3fd6a52f79fdf87053daca3ebaeffb4ba;p=clang [OPENMP] Fix PR34926: Fix handling of the array sections passed as function params. Codegen could crash if the array section base expression is the function parameter. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@315586 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index 798a2ef0c5..0f2e328eff 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -3349,12 +3349,7 @@ static Address emitOMPArraySectionBase(CodeGenFunction &CGF, const Expr *Base, LValue CodeGenFunction::EmitOMPArraySectionExpr(const OMPArraySectionExpr *E, bool IsLowerBound) { - QualType BaseTy; - if (auto *ASE = - dyn_cast(E->getBase()->IgnoreParenImpCasts())) - BaseTy = OMPArraySectionExpr::getBaseOriginalType(ASE); - else - BaseTy = E->getBase()->getType(); + QualType BaseTy = OMPArraySectionExpr::getBaseOriginalType(E->getBase()); QualType ResultExprTy; if (auto *AT = getContext().getAsArrayType(BaseTy)) ResultExprTy = AT->getElementType(); diff --git a/test/OpenMP/parallel_reduction_codegen.cpp b/test/OpenMP/parallel_reduction_codegen.cpp index e42776c740..c4c0ff473a 100644 --- a/test/OpenMP/parallel_reduction_codegen.cpp +++ b/test/OpenMP/parallel_reduction_codegen.cpp @@ -80,6 +80,14 @@ struct SST { // CHECK-DAG: [[REDUCTION_LOC:@.+]] = private unnamed_addr constant %{{.+}} { i32 0, i32 18, i32 0, i32 0, i8* // CHECK-DAG: [[REDUCTION_LOCK:@.+]] = common global [8 x i32] zeroinitializer +//CHECK: foo_array_sect +//CHECK: call void {{.+}}@__kmpc_fork_call( +//CHECK: ret void +void foo_array_sect(short x[1]) { +#pragma omp parallel reduction(+ : x[:]) + {} +} + template T tmain() { T t;