[PATCH] D53200: [OpenCL] Fix serialization of OpenCLExtensionDecls

Alexey Sachkov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 12 09:02:28 PDT 2018


AlexeySachkov created this revision.
AlexeySachkov added reviewers: Anastasia, yaxunl.

I recently discovered that adding the following code into `opencl-c.h` causes
failure of `test/Headers/opencl-c-header.cl`:

  #pragma OPENCL EXTENSION cl_my_ext : begin
  void cl_my_ext_foobarbaz();
  #pragma OPENCL EXTENSIOn cl_my_ext : end

Clang crashes at the assertion is `ASTReader::getGlobalSubmoduleID()`:

  assert(I != M.SubmoduleRemap.end() && "Invalid index into submodule index remap");

The root cause of the problem that to deserialize `OPENCL_EXTENSION_DECLS`
section `ASTReader` needs to deserialize a Decl contained in it. In turn,
deserializing a Decl requires information about whether this declaration is
part of a (sub)module, but this information is not read yet because it is
located further in a module file.


Repository:
  rC Clang

https://reviews.llvm.org/D53200

Files:
  lib/Serialization/ASTWriter.cpp


Index: lib/Serialization/ASTWriter.cpp
===================================================================
--- lib/Serialization/ASTWriter.cpp
+++ lib/Serialization/ASTWriter.cpp
@@ -5014,13 +5014,16 @@
   WriteFPPragmaOptions(SemaRef.getFPOptions());
   WriteOpenCLExtensions(SemaRef);
   WriteOpenCLExtensionTypes(SemaRef);
-  WriteOpenCLExtensionDecls(SemaRef);
   WriteCUDAPragmas(SemaRef);
 
   // If we're emitting a module, write out the submodule information.
   if (WritingModule)
     WriteSubmodules(WritingModule);
 
+  // We need to have information about submodules to correctly deserialize
+  // decls from OpenCLExtensionDecls block
+  WriteOpenCLExtensionDecls(SemaRef);
+
   Stream.EmitRecord(SPECIAL_TYPES, SpecialTypes);
 
   // Write the record containing external, unnamed definitions.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53200.169416.patch
Type: text/x-patch
Size: 808 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181012/1b9ef7d5/attachment-0001.bin>


More information about the cfe-commits mailing list