mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-27 12:01:18 +00:00
Implement static analysis of unformed usage on local variables. (#1831)
- An introprocedural forward analysis that checks the may-be-formed states on local variables. - Returns compilation error on usage of must-be-unformed variables. - Implemented as a pass of `ASTNode` traversal. - Currently supports detection of: function parameter, return expression and rhs of assign.
This commit is contained in:
1 parent
094311133d
commit
2f4905bf70
10 files changed
+292
-8
No files matched your search
@@ -13,7 +13,7 @@ package ExplorerTest api;
|
||||
fn Main() -> i32 {
|
||||
var x: i32;
|
||||
var y: i32;
|
||||
// CHECK: RUNTIME ERROR: {{.*}}/explorer/testdata/uninitialized/fail_local_uninitialized_assign.carbon:[[@LINE+1]]: undefined behavior: access to uninitialized value Uninit<Placeholder<x>>
|
||||
// CHECK: COMPILATION ERROR: {{.*}}/explorer/testdata/uninitialized/fail_local_uninitialized_assign.carbon:[[@LINE+1]]: use of uninitialized variable x
|
||||
y = x;
|
||||
return y;
|
||||
}
|
||||
@@ -12,7 +12,7 @@ package ExplorerTest api;
|
||||
|
||||
fn Main() -> i32 {
|
||||
var x: i32;
|
||||
// CHECK: RUNTIME ERROR: {{.*}}/explorer/testdata/uninitialized/fail_local_uninitialized_init.carbon:[[@LINE+1]]: undefined behavior: access to uninitialized value Uninit<Placeholder<x>>
|
||||
var y: i32 = x;
|
||||
// CHECK: COMPILATION ERROR: {{.*}}/explorer/testdata/uninitialized/fail_local_uninitialized_init.carbon:[[@LINE+1]]: use of uninitialized variable x
|
||||
return x;
|
||||
}
|
||||
@@ -16,6 +16,6 @@ fn AddInt(a: i32, b: i32) -> auto {
|
||||
|
||||
fn Main() -> i32 {
|
||||
var x: i32;
|
||||
// CHECK: RUNTIME ERROR: {{.*}}/explorer/testdata/uninitialized/fail_local_uninitialized_param.carbon:[[@LINE+1]]: undefined behavior: access to uninitialized value Uninit<Placeholder<x>>
|
||||
// CHECK: COMPILATION ERROR: {{.*}}/explorer/testdata/uninitialized/fail_local_uninitialized_param.carbon:[[@LINE+1]]: use of uninitialized variable x
|
||||
return AddInt(x, 2);
|
||||
}
|
||||
@@ -13,6 +13,6 @@ package ExplorerTest api;
|
||||
fn Main() -> i32 {
|
||||
var (x: i32, y: i32);
|
||||
x = 1;
|
||||
// CHECK: RUNTIME ERROR: {{.*}}/explorer/testdata/uninitialized/fail_local_uninitialized_pattern.carbon:[[@LINE+1]]: undefined behavior: access to uninitialized value Uninit<Placeholder<y>>
|
||||
// CHECK: COMPILATION ERROR: {{.*}}/explorer/testdata/uninitialized/fail_local_uninitialized_pattern.carbon:[[@LINE+1]]: use of uninitialized variable y
|
||||
return y;
|
||||
}
|
||||
@@ -12,6 +12,6 @@ package ExplorerTest api;
|
||||
|
||||
fn Main() -> i32 {
|
||||
var x: i32;
|
||||
// CHECK: RUNTIME ERROR: {{.*}}/explorer/testdata/uninitialized/fail_local_uninitialized_return.carbon:[[@LINE+1]]: undefined behavior: access to uninitialized value Uninit<Placeholder<x>>
|
||||
// CHECK: COMPILATION ERROR: {{.*}}/explorer/testdata/uninitialized/fail_local_uninitialized_return.carbon:[[@LINE+1]]: use of uninitialized variable x
|
||||
return x;
|
||||
}
|
||||
Reference in new issue
Block a user