Skip to content

Commit

Permalink
Add checked information for compound statements to AST reading/writing (
Browse files Browse the repository at this point in the history
#716)

* Add compound block checked information to ASTWriterStmt and ASTReaderStmt

* Add tests for pch checked scope AST
  • Loading branch information
kkjeer authored Nov 6, 2019
1 parent 07a5c7c commit a756721
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions clang/lib/Serialization/ASTReaderStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ void ASTStmtReader::VisitCompoundStmt(CompoundStmt *S) {
VisitStmt(S);
SmallVector<Stmt *, 16> 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);
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Serialization/ASTWriterStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
37 changes: 37 additions & 0 deletions clang/test/CheckedC/ast-dump-pch.c
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions clang/test/CheckedC/ast-dump-pch.h
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a756721

Please sign in to comment.