Skip to content

Commit aeb1272

Browse files
authored
Fix TypeCoupledDeclRefInfo (de-)serialization bug (swiftlang#10009)
* Unguard tests that were crashing on Linux * Fix TypeCoupledDeclRefInfo (de-)serialization bug There were two issues here: 1) Deserialization relied on a specific argument evaluation order, which is unspecified. 2) IsMember was not (de-)serialized.
1 parent dd47f01 commit aeb1272

File tree

8 files changed

+64
-12
lines changed

8 files changed

+64
-12
lines changed

clang/include/clang/Serialization/ASTRecordWriter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ class ASTRecordWriter
149149
void writeTypeCoupledDeclRefInfo(TypeCoupledDeclRefInfo Info) {
150150
writeDeclRef(Info.getDecl());
151151
writeBool(Info.isDeref());
152+
writeBool(Info.isMember());
152153
}
153154

154155
/// Emit a source range.

clang/lib/Serialization/ASTReader.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9276,7 +9276,10 @@ DeclarationNameInfo ASTRecordReader::readDeclarationNameInfo() {
92769276
}
92779277

92789278
TypeCoupledDeclRefInfo ASTRecordReader::readTypeCoupledDeclRefInfo() {
9279-
return TypeCoupledDeclRefInfo(readDeclAs<ValueDecl>(), readBool());
9279+
ValueDecl *D = readDeclAs<ValueDecl>();
9280+
bool IsDeref = readBool();
9281+
bool IsMember = readBool();
9282+
return TypeCoupledDeclRefInfo(D, IsDeref, IsMember);
92809283
}
92819284

92829285
void ASTRecordReader::readQualifierInfo(QualifierInfo &Info) {

clang/test/APINotes/boundssafety-errors.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// rdar://144275431: Clang module support for TypeCoupledDeclRefInfo is broken on Linux
2-
// REQUIRES: system-darwin
3-
41
// RUN: rm -rf %t && mkdir -p %t
52
// RUN: split-file %s %t/Headers
63
// RUN: not %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fsyntax-only -fapinotes-modules -I %t/Headers -fexperimental-bounds-safety-attributes %t/Headers/SemaErrors.c 2>&1 | FileCheck %s

clang/test/APINotes/boundssafety.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// rdar://144275431: Clang module support for TypeCoupledDeclRefInfo is broken on Linux
2-
// REQUIRES: system-darwin
3-
41
// RUN: rm -rf %t && mkdir -p %t
52
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fsyntax-only -fapinotes-modules -I %S/Inputs/Headers -F %S/Inputs/Frameworks -fexperimental-bounds-safety-attributes %s -ast-dump -ast-dump-filter asdf | FileCheck %s
63

clang/test/APINotes/boundssafety.m

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// rdar://144275431: Clang module support for TypeCoupledDeclRefInfo is broken on Linux
2-
// REQUIRES: system-darwin
3-
41
// RUN: rm -rf %t && mkdir -p %t
52

63
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fsyntax-only -fapinotes-modules -I %S/Inputs/Headers -F %S/Inputs/Frameworks -fexperimental-bounds-safety-attributes %s -ast-dump -ast-dump-filter asdf | FileCheck %s

clang/test/BoundsSafety/Modules/count-assign.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// REQUIRES: system-darwin
21
// RUN: rm -rf %t
32
// RUN: %clang_cc1 -fbounds-safety -fmodules -fno-implicit-modules -x c -I%S/Inputs/count-assign -emit-module %S/Inputs/count-assign/module.modulemap -fmodule-name=ca -o %t/count-assign.pcm
43
// RUN: %clang_cc1 -fbounds-safety -fmodules -fno-implicit-modules -x c -I%S/Inputs/count-assign -ast-dump-all -o - %s -fmodule-file=%t/count-assign.pcm | FileCheck %s

clang/test/BoundsSafety/PCH/count-assign-with-pch.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// REQUIRES: system-darwin
21
// Test without pch.
32
// RUN: %clang_cc1 -fbounds-safety -include %s -fsyntax-only -verify %s
43

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Test without pch.
2+
// RUN: %clang_cc1 -fbounds-safety -include %s %s -ast-dump 2>&1 | FileCheck %s
3+
4+
// Test with pch.
5+
// RUN: %clang_cc1 -fbounds-safety -emit-pch -o %t %s
6+
// RUN: %clang_cc1 -fbounds-safety -include-pch %t %s -ast-dump 2>&1 | FileCheck %s
7+
8+
#ifndef HEADER
9+
#define HEADER
10+
#include <ptrcheck.h>
11+
12+
struct Inner {
13+
int dummy;
14+
int len;
15+
};
16+
17+
struct Outer {
18+
struct Inner hdr;
19+
char fam[__counted_by(hdr.len)];
20+
};
21+
22+
#else
23+
24+
char access(struct Outer *bar, int index) {
25+
return bar->fam[index];
26+
}
27+
28+
// CHECK: -FunctionDecl [[func_access:0x[^ ]+]] {{.+}} access
29+
// CHECK: |-ParmVarDecl [[var_bar:0x[^ ]+]]
30+
// CHECK: |-ParmVarDecl [[var_index:0x[^ ]+]]
31+
// CHECK: `-CompoundStmt
32+
// CHECK: `-ReturnStmt
33+
// CHECK: `-ImplicitCastExpr {{.+}} 'char' <LValueToRValue>
34+
// CHECK: `-ArraySubscriptExpr
35+
// CHECK: |-MaterializeSequenceExpr {{.+}} <Unbind>
36+
// CHECK: | |-MaterializeSequenceExpr {{.+}} <Bind>
37+
// CHECK: | | |-BoundsSafetyPointerPromotionExpr {{.+}} 'char *__bidi_indexable'
38+
// CHECK: | | | |-ImplicitCastExpr {{.+}} 'char *' <ArrayToPointerDecay>
39+
// CHECK: | | | | `-MemberExpr {{.+}} ->fam
40+
// CHECK: | | | | `-OpaqueValueExpr [[ove:0x[^ ]+]] {{.*}} 'struct Outer *__single'
41+
// CHECK: | | | |-GetBoundExpr {{.+}} upper
42+
// CHECK: | | | | `-BoundsSafetyPointerPromotionExpr {{.+}} 'struct Outer *__bidi_indexable'
43+
// CHECK: | | | | |-OpaqueValueExpr [[ove]] {{.*}} 'struct Outer *__single'
44+
// CHECK: | | | | |-BinaryOperator {{.+}} 'char *' '+'
45+
// CHECK: | | | | | |-ImplicitCastExpr {{.+}} 'char *' <ArrayToPointerDecay>
46+
// CHECK: | | | | | | `-MemberExpr {{.+}} ->fam
47+
// CHECK: | | | | | | `-OpaqueValueExpr [[ove]] {{.*}} 'struct Outer *__single'
48+
// CHECK: | | | | | `-ImplicitCastExpr {{.+}} 'int' <LValueToRValue>
49+
// CHECK: | | | | | `-MemberExpr {{.+}} .len
50+
// CHECK: | | | | | `-MemberExpr {{.+}} ->hdr
51+
// CHECK: | | | | | `-OpaqueValueExpr [[ove]] {{.*}} 'struct Outer *__single'
52+
// CHECK: | | `-OpaqueValueExpr [[ove]]
53+
// CHECK: | | `-ImplicitCastExpr {{.+}} 'struct Outer *__single' <LValueToRValue>
54+
// CHECK: | | `-DeclRefExpr {{.+}} [[var_bar]]
55+
// CHECK: | `-OpaqueValueExpr [[ove]] {{.*}} 'struct Outer *__single'
56+
// CHECK: `-ImplicitCastExpr {{.+}} 'int' <LValueToRValue>
57+
// CHECK: `-DeclRefExpr {{.+}} [[var_index]]
58+
59+
#endif

0 commit comments

Comments
 (0)