[OpenCL] Fix serialization of OpenCLExtensionDecls
authorAndrew Savonichev <andrew.savonichev@intel.com>
Mon, 29 Oct 2018 11:14:01 +0000 (11:14 +0000)
committerAndrew Savonichev <andrew.savonichev@intel.com>
Mon, 29 Oct 2018 11:14:01 +0000 (11:14 +0000)
commit52d674d97499325d2c77dbcb67262c0cd1cde0b2
treee8d1d56e0c7588a1090aa5f23709bbfeb7a7abe8
parent7a0841ef2f597d3f7bc36385288aedbd781cb80c
[OpenCL] Fix serialization of OpenCLExtensionDecls

Summary:
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.

Reviewers: Anastasia, yaxunl, JDevlieghere

Reviewed By: Anastasia

Subscribers: sidorovd, cfe-commits, asavonic

Differential Revision: https://reviews.llvm.org/D53200

llvm-svn: 345497
clang/lib/Serialization/ASTWriter.cpp
clang/test/SemaOpenCL/extension-begin.cl
clang/test/SemaOpenCL/extension-begin.h [new file with mode: 0644]