From: Erich Keane Date: Fri, 1 Jun 2018 13:04:26 +0000 (+0000) Subject: [OpenCL, OpenMP] Fix crash when OpenMP used in OpenCL file X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=536c74b77d4142115fa0bd520b76e27930cd83c1;p=clang [OpenCL, OpenMP] Fix crash when OpenMP used in OpenCL file Compiler crashes when omp simd is used in an OpenCL file: clang -c -fopenmp omp_simd.cl __kernel void test(global int *data, int size) { #pragma omp simd for (int i = 0; i < size; ++i) { } } The problem seems to be the check added to verify block pointers have initializers. An OMPCapturedExprDecl is created to capture ‘size’ but there is no TypeSourceInfo. The change just uses getType() directly. Patch-By: mikerice Differential Revision: https://reviews.llvm.org/D46667 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@333746 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/DeclOpenMP.h b/include/clang/AST/DeclOpenMP.h index ae7d04d370..bec3acffc4 100644 --- a/include/clang/AST/DeclOpenMP.h +++ b/include/clang/AST/DeclOpenMP.h @@ -189,8 +189,9 @@ class OMPCapturedExprDecl final : public VarDecl { void anchor() override; OMPCapturedExprDecl(ASTContext &C, DeclContext *DC, IdentifierInfo *Id, - QualType Type, SourceLocation StartLoc) - : VarDecl(OMPCapturedExpr, C, DC, StartLoc, StartLoc, Id, Type, nullptr, + QualType Type, TypeSourceInfo *TInfo, + SourceLocation StartLoc) + : VarDecl(OMPCapturedExpr, C, DC, StartLoc, StartLoc, Id, Type, TInfo, SC_None) { setImplicit(); } diff --git a/lib/AST/DeclOpenMP.cpp b/lib/AST/DeclOpenMP.cpp index a86c0ebd48..f5c3599ef6 100644 --- a/lib/AST/DeclOpenMP.cpp +++ b/lib/AST/DeclOpenMP.cpp @@ -92,13 +92,14 @@ void OMPCapturedExprDecl::anchor() {} OMPCapturedExprDecl *OMPCapturedExprDecl::Create(ASTContext &C, DeclContext *DC, IdentifierInfo *Id, QualType T, SourceLocation StartLoc) { - return new (C, DC) OMPCapturedExprDecl(C, DC, Id, T, StartLoc); + return new (C, DC) OMPCapturedExprDecl( + C, DC, Id, T, C.getTrivialTypeSourceInfo(T), StartLoc); } OMPCapturedExprDecl *OMPCapturedExprDecl::CreateDeserialized(ASTContext &C, unsigned ID) { - return new (C, ID) - OMPCapturedExprDecl(C, nullptr, nullptr, QualType(), SourceLocation()); + return new (C, ID) OMPCapturedExprDecl(C, nullptr, nullptr, QualType(), + /*TInfo=*/nullptr, SourceLocation()); } SourceRange OMPCapturedExprDecl::getSourceRange() const {