diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp index 119fc9db42ce..1455eaf47e5d 100644 --- a/clang/lib/Serialization/ASTReaderStmt.cpp +++ b/clang/lib/Serialization/ASTReaderStmt.cpp @@ -161,6 +161,8 @@ void ASTStmtReader::VisitCompoundStmt(CompoundStmt *S) { VisitStmt(S); SmallVector Stmts; unsigned NumStmts = Record.readInt(); + S->setCheckedSpecifiers((CheckedScopeSpecifier)Record.readInt()); + S->setWrittenCheckedSpecifiers((CheckedScopeSpecifier)Record.readInt()); while (NumStmts--) Stmts.push_back(Record.readSubStmt()); S->setStmts(Stmts); diff --git a/clang/lib/Serialization/ASTWriterStmt.cpp b/clang/lib/Serialization/ASTWriterStmt.cpp index db834d95a4c7..579855fd8bba 100644 --- a/clang/lib/Serialization/ASTWriterStmt.cpp +++ b/clang/lib/Serialization/ASTWriterStmt.cpp @@ -80,6 +80,8 @@ void ASTStmtWriter::VisitNullStmt(NullStmt *S) { void ASTStmtWriter::VisitCompoundStmt(CompoundStmt *S) { VisitStmt(S); Record.push_back(S->size()); + Record.push_back(S->getCheckedSpecifier()); + Record.push_back(S->getWrittenCheckedSpecifier()); for (auto *CS : S->body()) Record.AddStmt(CS); Record.AddSourceLocation(S->getLBracLoc()); diff --git a/clang/test/CheckedC/ast-dump-pch.c b/clang/test/CheckedC/ast-dump-pch.c new file mode 100644 index 000000000000..ddcde2b11fc1 --- /dev/null +++ b/clang/test/CheckedC/ast-dump-pch.c @@ -0,0 +1,37 @@ +// Tests for serialization/deserialization of checked scopes. +// This makes sure AST serialization/deserialization accounts for +// checked scope specifiers and written checked scope specifiers. +// +// RUN: %clang_cc1 -fcheckedc-extension -emit-pch -o %t %S/ast-dump-pch.h +// RUN: %clang_cc1 -fcheckedc-extension -ast-dump-all -include-pch %t %s | FileCheck %s + +// CHECK: FunctionDecl +// CHECK: f1 +// CHECK-NEXT: CompoundStmt +// CHECK-NOT: {{_Checked|_Unchecked|checking-state}} +// CHECK-NEXT: CompoundStmt +// CHECK: _Checked checking-state bounds-and-types +// CHECK: CompoundStmt +// CHECK: _Checked _Bounds_only checking-state bounds +// CHECK: CompoundStmt +// CHECK: _Unchecked +// CHECK: CompoundStmt +// CHECK-NOT: {{_Checked|_Unchecked|checking-state}} + +// CHECK-NEXT: FunctionDecl +// CHECK: f2 +// CHECK-NEXT: CompoundStmt +// CHECK: _Checked checking-state bounds-and-types + +// CHECK-NEXT: FunctionDecl +// CHECK: f3 +// CHECK-NEXT: CompoundStmt +// CHECK: _Checked _Bounds_only checking-state bounds + +// CHECK-NEXT: FunctionDecl +// CHECK: f4 +// CHECK-NEXT: CompoundStmt +// CHECK: _Unchecked +// CHECK-NOT {{checking-state}} + +// TODO: GitHub issue #704: add function declarations with checked scope specifiers \ No newline at end of file diff --git a/clang/test/CheckedC/ast-dump-pch.h b/clang/test/CheckedC/ast-dump-pch.h new file mode 100644 index 000000000000..8bc4ccda1bfd --- /dev/null +++ b/clang/test/CheckedC/ast-dump-pch.h @@ -0,0 +1,16 @@ +// Used with the ast-dump-pch.c test + +void f1(void) { + _Checked { int a = 0; } + _Checked _Bounds_only {int b = 0; } + _Unchecked {} + {} +} + +void f2(void) _Checked {} + +void f3(void) _Checked _Bounds_only {} + +void f4(void) _Unchecked {} + +// TODO: GitHub issue #704: add function declarations with checked scope specifiers \ No newline at end of file