Skip to content

Commit 3ccd033

Browse files
committed
Merging r345497:
------------------------------------------------------------------------ r345497 | asavonic | 2018-10-29 04:14:01 -0700 (Mon, 29 Oct 2018) | 29 lines [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: 347834
1 parent 3e4d4dd commit 3ccd033

File tree

3 files changed

+55
-36
lines changed

3 files changed

+55
-36
lines changed

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5022,13 +5022,16 @@ ASTFileSignature ASTWriter::WriteASTCore(Sema &SemaRef, StringRef isysroot,
50225022
WriteFPPragmaOptions(SemaRef.getFPOptions());
50235023
WriteOpenCLExtensions(SemaRef);
50245024
WriteOpenCLExtensionTypes(SemaRef);
5025-
WriteOpenCLExtensionDecls(SemaRef);
50265025
WriteCUDAPragmas(SemaRef);
50275026

50285027
// If we're emitting a module, write out the submodule information.
50295028
if (WritingModule)
50305029
WriteSubmodules(WritingModule);
50315030

5031+
// We need to have information about submodules to correctly deserialize
5032+
// decls from OpenCLExtensionDecls block
5033+
WriteOpenCLExtensionDecls(SemaRef);
5034+
50325035
Stream.EmitRecord(SPECIAL_TYPES, SpecialTypes);
50335036

50345037
// Write the record containing external, unnamed definitions.
Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,29 @@
11
// Test this without pch.
2-
// RUN: %clang_cc1 %s -DHEADER -DHEADER_USER -triple spir-unknown-unknown -verify -pedantic -fsyntax-only
2+
// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only
33

44
// Test with pch.
5-
// RUN: %clang_cc1 %s -DHEADER -triple spir-unknown-unknown -emit-pch -o %t -verify -pedantic
6-
// RUN: %clang_cc1 %s -DHEADER_USER -triple spir-unknown-unknown -include-pch %t -fsyntax-only -verify -pedantic
7-
8-
#if defined(HEADER) && !defined(INCLUDED)
9-
#define INCLUDED
10-
11-
#pragma OPENCL EXTENSION all : begin // expected-warning {{expected 'disable' - ignoring}}
12-
#pragma OPENCL EXTENSION all : end // expected-warning {{expected 'disable' - ignoring}}
13-
14-
#pragma OPENCL EXTENSION my_ext : begin
15-
16-
struct A {
17-
int a;
18-
};
19-
20-
typedef struct A TypedefOfA;
21-
typedef const TypedefOfA* PointerOfA;
22-
23-
void f(void);
24-
25-
__attribute__((overloadable)) void g(long x);
26-
27-
#pragma OPENCL EXTENSION my_ext : end
28-
#pragma OPENCL EXTENSION my_ext : end // expected-warning {{OpenCL extension end directive mismatches begin directive - ignoring}}
29-
30-
__attribute__((overloadable)) void g(void);
31-
32-
#endif // defined(HEADER) && !defined(INCLUDED)
33-
34-
#ifdef HEADER_USER
5+
// RUN: %clang_cc1 -x cl %S/extension-begin.h -triple spir-unknown-unknown -emit-pch -o %t.pch -pedantic
6+
// RUN: %clang_cc1 %s -triple spir-unknown-unknown -include-pch %t.pch -DIMPLICIT_INCLUDE -DUSE_PCH -fsyntax-only -verify -pedantic
7+
8+
// Test with modules
9+
// RUN: rm -rf %t.modules
10+
// RUN: mkdir -p %t.modules
11+
//
12+
// RUN: %clang_cc1 -cl-std=CL1.2 -DIMPLICIT_INCLUDE -include %S/extension-begin.h -triple spir-unknown-unknown -O0 -emit-llvm -o - -fmodules -fimplicit-module-maps -fmodules-cache-path=%t.modules %s -verify -pedantic
13+
//
14+
// RUN: rm -rf %t.modules
15+
// RUN: mkdir -p %t.modules
16+
//
17+
// RUN: %clang_cc1 -cl-std=CL2.0 -DIMPLICIT_INCLUDE -include %S/extension-begin.h -triple spir-unknown-unknown -O0 -emit-llvm -o - -fmodules -fimplicit-module-maps -fmodules-cache-path=%t.modules %s -verify -pedantic
18+
19+
#ifndef IMPLICIT_INCLUDE
20+
#include "extension-begin.h"
21+
#endif // IMPLICIT_INCLUDE
22+
#ifndef USE_PCH
23+
// expected-warning@extension-begin.h:4 {{expected 'disable' - ignoring}}
24+
// expected-warning@extension-begin.h:5 {{expected 'disable' - ignoring}}
25+
// expected-warning@extension-begin.h:21 {{OpenCL extension end directive mismatches begin directive - ignoring}}
26+
#endif // USE_PCH
3527

3628
#pragma OPENCL EXTENSION my_ext : enable
3729
void test_f1(void) {
@@ -48,9 +40,7 @@ void test_f2(void) {
4840
PointerOfA test_A_pointer; // expected-error {{use of type 'PointerOfA' (aka 'const struct A *') requires my_ext extension to be enabled}}
4941
f(); // expected-error {{use of declaration 'f' requires my_ext extension to be enabled}}
5042
g(0); // expected-error {{no matching function for call to 'g'}}
51-
// expected-note@-26 {{candidate disabled due to OpenCL extension}}
52-
// expected-note@-22 {{candidate function not viable: requires 0 arguments, but 1 was provided}}
43+
// expected-note@extension-begin.h:18 {{candidate disabled due to OpenCL extension}}
44+
// expected-note@extension-begin.h:23 {{candidate function not viable: requires 0 arguments, but 1 was provided}}
5345
}
5446

55-
#endif // HEADER_USER
56-
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#ifndef INCLUDED
2+
#define INCLUDED
3+
4+
#pragma OPENCL EXTENSION all : begin
5+
#pragma OPENCL EXTENSION all : end
6+
7+
#pragma OPENCL EXTENSION my_ext : begin
8+
9+
struct A {
10+
int a;
11+
};
12+
13+
typedef struct A TypedefOfA;
14+
typedef const __private TypedefOfA* PointerOfA;
15+
16+
void f(void);
17+
18+
__attribute__((overloadable)) void g(long x);
19+
20+
#pragma OPENCL EXTENSION my_ext : end
21+
#pragma OPENCL EXTENSION my_ext : end
22+
23+
__attribute__((overloadable)) void g(void);
24+
25+
#endif // INCLUDED
26+

0 commit comments

Comments
 (0)