Skip to content

Fix TypeCoupledDeclRefInfo (de-)serialization bug #10009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/include/clang/Serialization/ASTRecordWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class ASTRecordWriter
void writeTypeCoupledDeclRefInfo(TypeCoupledDeclRefInfo Info) {
writeDeclRef(Info.getDecl());
writeBool(Info.isDeref());
writeBool(Info.isMember());
}

/// Emit a source range.
Expand Down
5 changes: 4 additions & 1 deletion clang/lib/Serialization/ASTReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9276,7 +9276,10 @@ DeclarationNameInfo ASTRecordReader::readDeclarationNameInfo() {
}

TypeCoupledDeclRefInfo ASTRecordReader::readTypeCoupledDeclRefInfo() {
return TypeCoupledDeclRefInfo(readDeclAs<ValueDecl>(), readBool());
ValueDecl *D = readDeclAs<ValueDecl>();
bool IsDeref = readBool();
bool IsMember = readBool();
return TypeCoupledDeclRefInfo(D, IsDeref, IsMember);
}

void ASTRecordReader::readQualifierInfo(QualifierInfo &Info) {
Expand Down
3 changes: 0 additions & 3 deletions clang/test/APINotes/boundssafety-errors.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// rdar://144275431: Clang module support for TypeCoupledDeclRefInfo is broken on Linux
// REQUIRES: system-darwin

// RUN: rm -rf %t && mkdir -p %t
// RUN: split-file %s %t/Headers
// 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
Expand Down
3 changes: 0 additions & 3 deletions clang/test/APINotes/boundssafety.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// rdar://144275431: Clang module support for TypeCoupledDeclRefInfo is broken on Linux
// REQUIRES: system-darwin

// RUN: rm -rf %t && mkdir -p %t
// 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

Expand Down
3 changes: 0 additions & 3 deletions clang/test/APINotes/boundssafety.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// rdar://144275431: Clang module support for TypeCoupledDeclRefInfo is broken on Linux
// REQUIRES: system-darwin

// RUN: rm -rf %t && mkdir -p %t

// 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
Expand Down
1 change: 0 additions & 1 deletion clang/test/BoundsSafety/Modules/count-assign.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// REQUIRES: system-darwin
// RUN: rm -rf %t
// 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
// 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
Expand Down
1 change: 0 additions & 1 deletion clang/test/BoundsSafety/PCH/count-assign-with-pch.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// REQUIRES: system-darwin
// Test without pch.
// RUN: %clang_cc1 -fbounds-safety -include %s -fsyntax-only -verify %s

Expand Down
59 changes: 59 additions & 0 deletions clang/test/BoundsSafety/PCH/nested-struct-member-count.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Test without pch.
// RUN: %clang_cc1 -fbounds-safety -include %s %s -ast-dump 2>&1 | FileCheck %s

// Test with pch.
// RUN: %clang_cc1 -fbounds-safety -emit-pch -o %t %s
// RUN: %clang_cc1 -fbounds-safety -include-pch %t %s -ast-dump 2>&1 | FileCheck %s

#ifndef HEADER
#define HEADER
#include <ptrcheck.h>

struct Inner {
int dummy;
int len;
};

struct Outer {
struct Inner hdr;
char fam[__counted_by(hdr.len)];
};

#else

char access(struct Outer *bar, int index) {
return bar->fam[index];
}

// CHECK: -FunctionDecl [[func_access:0x[^ ]+]] {{.+}} access
// CHECK: |-ParmVarDecl [[var_bar:0x[^ ]+]]
// CHECK: |-ParmVarDecl [[var_index:0x[^ ]+]]
// CHECK: `-CompoundStmt
// CHECK: `-ReturnStmt
// CHECK: `-ImplicitCastExpr {{.+}} 'char' <LValueToRValue>
// CHECK: `-ArraySubscriptExpr
// CHECK: |-MaterializeSequenceExpr {{.+}} <Unbind>
// CHECK: | |-MaterializeSequenceExpr {{.+}} <Bind>
// CHECK: | | |-BoundsSafetyPointerPromotionExpr {{.+}} 'char *__bidi_indexable'
// CHECK: | | | |-ImplicitCastExpr {{.+}} 'char *' <ArrayToPointerDecay>
// CHECK: | | | | `-MemberExpr {{.+}} ->fam
// CHECK: | | | | `-OpaqueValueExpr [[ove:0x[^ ]+]] {{.*}} 'struct Outer *__single'
// CHECK: | | | |-GetBoundExpr {{.+}} upper
// CHECK: | | | | `-BoundsSafetyPointerPromotionExpr {{.+}} 'struct Outer *__bidi_indexable'
// CHECK: | | | | |-OpaqueValueExpr [[ove]] {{.*}} 'struct Outer *__single'
// CHECK: | | | | |-BinaryOperator {{.+}} 'char *' '+'
// CHECK: | | | | | |-ImplicitCastExpr {{.+}} 'char *' <ArrayToPointerDecay>
// CHECK: | | | | | | `-MemberExpr {{.+}} ->fam
// CHECK: | | | | | | `-OpaqueValueExpr [[ove]] {{.*}} 'struct Outer *__single'
// CHECK: | | | | | `-ImplicitCastExpr {{.+}} 'int' <LValueToRValue>
// CHECK: | | | | | `-MemberExpr {{.+}} .len
// CHECK: | | | | | `-MemberExpr {{.+}} ->hdr
// CHECK: | | | | | `-OpaqueValueExpr [[ove]] {{.*}} 'struct Outer *__single'
// CHECK: | | `-OpaqueValueExpr [[ove]]
// CHECK: | | `-ImplicitCastExpr {{.+}} 'struct Outer *__single' <LValueToRValue>
// CHECK: | | `-DeclRefExpr {{.+}} [[var_bar]]
// CHECK: | `-OpaqueValueExpr [[ove]] {{.*}} 'struct Outer *__single'
// CHECK: `-ImplicitCastExpr {{.+}} 'int' <LValueToRValue>
// CHECK: `-DeclRefExpr {{.+}} [[var_index]]

#endif