Skip to content

Commit 6aa0c1e

Browse files
committed
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 50ca8c0 commit 6aa0c1e

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
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) {
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)