From: Alexey Bataev Date: Mon, 10 Apr 2017 19:16:45 +0000 (+0000) Subject: [OPENMP] Fix for PR32333: Crash in call of outlined Function. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b3ed1c7687c43eccf0c84a1b6f06238d49838f65;p=clang [OPENMP] Fix for PR32333: Crash in call of outlined Function. If the type of the captured variable is a pointer(s) to variably modified type, this type was not processed correctly. Need to drill into the type, find the innermost variably modified array type and convert it to canonical parameter type. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@299868 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGStmtOpenMP.cpp b/lib/CodeGen/CGStmtOpenMP.cpp index 71d8ea2714..22269e42c7 100644 --- a/lib/CodeGen/CGStmtOpenMP.cpp +++ b/lib/CodeGen/CGStmtOpenMP.cpp @@ -227,6 +227,17 @@ static Address castValueFromUintptr(CodeGenFunction &CGF, QualType DstType, return TmpAddr; } +static QualType getCanonicalParamType(ASTContext &C, QualType T) { + if (T->isLValueReferenceType()) { + return C.getLValueReferenceType( + getCanonicalParamType(C, T.getNonReferenceType()), + /*SpelledAsLValue=*/false); + } + if (T->isPointerType()) + return C.getPointerType(getCanonicalParamType(C, T->getPointeeType())); + return C.getCanonicalParamType(T); +} + llvm::Function * CodeGenFunction::GenerateOpenMPCapturedStmtFunction(const CapturedStmt &S) { assert( @@ -266,13 +277,8 @@ CodeGenFunction::GenerateOpenMPCapturedStmtFunction(const CapturedStmt &S) { II = &getContext().Idents.get("vla"); } if (ArgType->isVariablyModifiedType()) { - bool IsReference = ArgType->isLValueReferenceType(); ArgType = - getContext().getCanonicalParamType(ArgType.getNonReferenceType()); - if (IsReference && !ArgType->isPointerType()) { - ArgType = getContext().getLValueReferenceType( - ArgType, /*SpelledAsLValue=*/false); - } + getCanonicalParamType(getContext(), ArgType.getNonReferenceType()); } Args.push_back(ImplicitParamDecl::Create(getContext(), nullptr, FD->getLocation(), II, ArgType)); diff --git a/test/OpenMP/vla_crash.c b/test/OpenMP/vla_crash.c new file mode 100644 index 0000000000..50dcf06870 --- /dev/null +++ b/test/OpenMP/vla_crash.c @@ -0,0 +1,22 @@ +// RUN: %clang_cc1 -verify -triple powerpc64le-unknown-linux-gnu -fopenmp -x c -emit-llvm %s -o - | FileCheck %s +// expected-no-diagnostics + +int a; + +// CHECK-LABEL: foo +void foo() { + int(*b)[a]; + int *(**c)[a]; + // CHECK: [[B:%.+]] = alloca i32*, + // CHECK: [[C:%.+]] = alloca i32***, + // CHECK: @__kmpc_global_thread_num + // CHECK: call void @__kmpc_serialized_parallel + // CHECK: call void [[OUTLINED:@[^(]+]](i32* %{{[^,]+}}, i32* %{{[^,]+}}, i64 %{{[^,]+}}, i32** [[B]], i64 %{{[^,]+}}, i32**** [[C]]) + // CHECK: call void @__kmpc_end_serialized_parallel + // CHECK: ret void +#pragma omp parallel if (0) + b[0][0] = c[0][a][0][a]; +} + +// CHECK: define internal void [[OUTLINED]](i32* {{[^,]+}}, i32* {{[^,]+}}, i64 {{[^,]+}}, i32** {{[^,]+}}, i64 {{[^,]+}}, i32**** {{[^,]+}}) +