Added generating CFGAutomaticObjDtors for exception variable in catch statement.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@115266 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Marcin Swiderski 2010-10-01 01:46:52 +00:00
Родитель 47575f1f77
Коммит 0e97bcbee9
2 изменённых файлов: 53 добавлений и 0 удалений

Просмотреть файл

@ -2154,6 +2154,18 @@ CFGBlock* CFGBuilder::VisitCXXCatchStmt(CXXCatchStmt* CS) {
// CXXCatchStmt are treated like labels, so they are the first statement in a // CXXCatchStmt are treated like labels, so they are the first statement in a
// block. // block.
// Save local scope position because in case of exception variable ScopePos
// won't be restored when traversing AST.
SaveAndRestore<LocalScope::const_iterator> save_scope_pos(ScopePos);
// Create local scope for possible exception variable.
// Store scope position. Add implicit destructor.
if (VarDecl* VD = CS->getExceptionDecl()) {
LocalScope::const_iterator BeginScopePos = ScopePos;
addLocalScopeForVarDecl(VD);
addAutomaticObjDtors(ScopePos, BeginScopePos, CS);
}
if (CS->getHandlerBlock()) if (CS->getHandlerBlock())
addStmt(CS->getHandlerBlock()); addStmt(CS->getHandlerBlock());

Просмотреть файл

@ -138,6 +138,18 @@ void test_for_jumps() {
A f; A f;
} }
void test_catch_const_ref() {
try {
} catch (const A& e) {
}
}
void test_catch_copy() {
try {
} catch (A e) {
}
}
// CHECK: [ B2 (ENTRY) ] // CHECK: [ B2 (ENTRY) ]
// CHECK: Predecessors (0): // CHECK: Predecessors (0):
// CHECK: Successors (1): B1 // CHECK: Successors (1): B1
@ -726,3 +738,32 @@ void test_for_jumps() {
// CHECK: [ B0 (EXIT) ] // CHECK: [ B0 (EXIT) ]
// CHECK: Predecessors (2): B1 B5 // CHECK: Predecessors (2): B1 B5
// CHECK: Successors (0): // CHECK: Successors (0):
// CHECK: [ B3 (ENTRY) ]
// CHECK: Predecessors (0):
// CHECK: Successors (1): B0
// CHECK: [ B1 ]
// CHECK: T: try ...
// CHECK: Predecessors (0):
// CHECK: Successors (2): B2 B0
// CHECK: [ B2 ]
// CHECK: catch (const A &e):
// CHECK: Predecessors (1): B1
// CHECK: Successors (1): B0
// CHECK: [ B0 (EXIT) ]
// CHECK: Predecessors (3): B2 B1 B3
// CHECK: Successors (0):
// CHECK: [ B3 (ENTRY) ]
// CHECK: Predecessors (0):
// CHECK: Successors (1): B0
// CHECK: [ B1 ]
// CHECK: T: try ...
// CHECK: Predecessors (0):
// CHECK: Successors (2): B2 B0
// CHECK: [ B2 ]
// CHECK: catch (A e):
// CHECK: 1: .~A() (Implicit destructor)
// CHECK: Predecessors (1): B1
// CHECK: Successors (1): B0
// CHECK: [ B0 (EXIT) ]
// CHECK: Predecessors (3): B2 B1 B3
// CHECK: Successors (0):