]> granicus.if.org Git - clang/commitdiff
[OpenCL, OpenMP] Fix crash when OpenMP used in OpenCL file
authorErich Keane <erich.keane@intel.com>
Fri, 1 Jun 2018 13:04:26 +0000 (13:04 +0000)
committerErich Keane <erich.keane@intel.com>
Fri, 1 Jun 2018 13:04:26 +0000 (13:04 +0000)
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

include/clang/AST/DeclOpenMP.h
lib/AST/DeclOpenMP.cpp

index ae7d04d370601030983617bd197876119245efb5..bec3acffc43326c3e2ff009e97e1803930cbad4d 100644 (file)
@@ -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();
   }
index a86c0ebd48d5fac42601b509d40daae930c6f22f..f5c3599ef6c622f1493e478a2e3707a1e16cd9a7 100644 (file)
@@ -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 {