-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support out of order destruction of static_vars
- Loading branch information
1 parent
aa1a8d9
commit a872c83
Showing
4 changed files
with
239 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
FUNC_DECL | ||
SCALAR_TYPE (VOID) | ||
VAR (arg0) | ||
STMT_BLOCK | ||
DECL_STMT | ||
SCALAR_TYPE (INT) | ||
VAR (var0) | ||
VAR_EXPR | ||
VAR (arg0) | ||
DECL_STMT | ||
SCALAR_TYPE (INT) | ||
VAR (y_1) | ||
NO_INITIALIZATION | ||
DECL_STMT | ||
SCALAR_TYPE (INT) | ||
VAR (c_2) | ||
VAR_EXPR | ||
VAR (var0) | ||
IF_STMT | ||
EQUALS_EXPR | ||
INT_CONST (0) | ||
VAR_EXPR | ||
VAR (c_2) | ||
STMT_BLOCK | ||
DECL_STMT | ||
SCALAR_TYPE (FLOAT) | ||
VAR (c_3) | ||
FLOAT_CONST (2) | ||
STMT_BLOCK | ||
IF_STMT | ||
EQUALS_EXPR | ||
INT_CONST (1) | ||
VAR_EXPR | ||
VAR (c_2) | ||
STMT_BLOCK | ||
DECL_STMT | ||
SCALAR_TYPE (FLOAT) | ||
VAR (c_4) | ||
FLOAT_CONST (3) | ||
STMT_BLOCK | ||
IF_STMT | ||
EQUALS_EXPR | ||
INT_CONST (2) | ||
VAR_EXPR | ||
VAR (c_2) | ||
STMT_BLOCK | ||
DECL_STMT | ||
SCALAR_TYPE (FLOAT) | ||
VAR (c_5) | ||
FLOAT_CONST (5) | ||
STMT_BLOCK | ||
DECL_STMT | ||
SCALAR_TYPE (FLOAT) | ||
VAR (c_6) | ||
FLOAT_CONST (2) | ||
void bar (int arg0) { | ||
int var0 = arg0; | ||
int y_1; | ||
int c_2 = var0; | ||
if (0 == c_2) { | ||
float c_3 = 2.0f; | ||
} else { | ||
if (1 == c_2) { | ||
float c_4 = 3.0f; | ||
} else { | ||
if (2 == c_2) { | ||
float c_5 = 5.0f; | ||
} else { | ||
float c_6 = 2.0f; | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
FUNC_DECL | ||
SCALAR_TYPE (VOID) | ||
VAR (arg0) | ||
STMT_BLOCK | ||
DECL_STMT | ||
SCALAR_TYPE (INT) | ||
VAR (var0) | ||
VAR_EXPR | ||
VAR (arg0) | ||
DECL_STMT | ||
SCALAR_TYPE (INT) | ||
VAR (var1) | ||
NO_INITIALIZATION | ||
DECL_STMT | ||
SCALAR_TYPE (INT) | ||
VAR (var2) | ||
VAR_EXPR | ||
VAR (var0) | ||
IF_STMT | ||
EQUALS_EXPR | ||
INT_CONST (0) | ||
VAR_EXPR | ||
VAR (var2) | ||
STMT_BLOCK | ||
DECL_STMT | ||
SCALAR_TYPE (FLOAT) | ||
VAR (var3) | ||
FLOAT_CONST (2) | ||
STMT_BLOCK | ||
IF_STMT | ||
EQUALS_EXPR | ||
INT_CONST (1) | ||
VAR_EXPR | ||
VAR (var2) | ||
STMT_BLOCK | ||
DECL_STMT | ||
SCALAR_TYPE (FLOAT) | ||
VAR (var4) | ||
FLOAT_CONST (3) | ||
STMT_BLOCK | ||
IF_STMT | ||
EQUALS_EXPR | ||
INT_CONST (2) | ||
VAR_EXPR | ||
VAR (var2) | ||
STMT_BLOCK | ||
DECL_STMT | ||
SCALAR_TYPE (FLOAT) | ||
VAR (var5) | ||
FLOAT_CONST (5) | ||
STMT_BLOCK | ||
DECL_STMT | ||
SCALAR_TYPE (FLOAT) | ||
VAR (var6) | ||
FLOAT_CONST (2) | ||
void bar (int arg0) { | ||
int var0 = arg0; | ||
int var1; | ||
int var2 = var0; | ||
if (0 == var2) { | ||
float var3 = 2.0f; | ||
} else { | ||
if (1 == var2) { | ||
float var4 = 3.0f; | ||
} else { | ||
if (2 == var2) { | ||
float var5 = 5.0f; | ||
} else { | ||
float var6 = 2.0f; | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include "blocks/c_code_generator.h" | ||
#include "builder/builder.h" | ||
#include "builder/builder_context.h" | ||
#include "builder/dyn_var.h" | ||
#include "builder/static_var.h" | ||
#include "builder/lib/utils.h" | ||
#include <iostream> | ||
using builder::dyn_var; | ||
using builder::static_var; | ||
|
||
static static_var<int> magic(dyn_var<int> x, int range) { | ||
for (static_var<int> y = 0; y < range; y++) { | ||
if (y == x) return y; | ||
} | ||
return 0; | ||
} | ||
|
||
|
||
float arr[] = {2.0, 3.0, 5.0}; | ||
|
||
|
||
static void bar(dyn_var<int> x) { | ||
/* Test out of order deinitialization of static variables and arrays */ | ||
|
||
auto sv1 = new static_var<int>(); | ||
auto sv2 = new static_var<int>(); | ||
|
||
auto sva1 = new static_var<int[]>(); | ||
sva1->resize(5); | ||
auto sva2 = new static_var<int[]>(); | ||
sva2->resize(5); | ||
|
||
|
||
dyn_var<int> y; | ||
|
||
delete sv1; | ||
delete sv2; | ||
delete sva1; | ||
delete sva2; | ||
|
||
|
||
// Test case that breaks without out of order deinitialization | ||
static_var<int> z = magic(x, 3); | ||
dyn_var<float> c = arr[z]; | ||
|
||
|
||
|
||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
builder::builder_context context; | ||
auto ast = context.extract_function_ast(bar, "bar"); | ||
ast->dump(std::cout, 0); | ||
block::c_code_generator::generate_code(ast, std::cout, 0); | ||
return 0; | ||
} |