From cf36334305b82dc36f7a2423382ccd8b21bb4eae Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Mon, 15 Feb 2016 12:43:51 -0800 Subject: 2659 - disallow dynamic arrays in recipes The rule is: every 'local' variable in a recipe must have a fixed size. Arrays can only be directly used in a recipe if their type includes a size. But we haven't been warning about this, and attempts to use array variables could cause silent memory corruption. (Hopefully this is the last hole in our type system.) --- 047check_type_by_name.cc | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to '047check_type_by_name.cc') diff --git a/047check_type_by_name.cc b/047check_type_by_name.cc index 88c406c7..74f61e24 100644 --- a/047check_type_by_name.cc +++ b/047check_type_by_name.cc @@ -55,8 +55,20 @@ void check_type(map& type, map& type_n } if (!contains_key(type_name, x.name)) put(type_name, x.name, x.properties.at(0).second); - if (!types_strictly_match(type[x.name], x.type)) + if (!types_strictly_match(type[x.name], x.type)) { raise_error << maybe(get(Recipe, r).name) << x.name << " used with multiple types\n" << end(); + return; + } + if (type_name[x.name]->value == "array") { + if (!type_name[x.name]->right) { + raise_error << maybe(get(Recipe, r).name) << x.name << " can't be just an array. What is it an array of?\n" << end(); + return; + } + if (!type_name[x.name]->right->right) { + raise_error << get(Recipe, r).name << " can't determine the size of array variable " << x.name << ". Either allocate it separately and make the type of " << x.name << " address:shared:..., or specify the length of the array in the type of " << x.name << ".\n" << end(); + return; + } + } } :(scenario transform_fills_in_missing_types) @@ -93,3 +105,10 @@ recipe main [ *y <- copy 67 ] +error: main: unknown type charcter in 'y:address:shared:charcter <- new character:type' + +:(scenario array_type_without_size_fails) +% Hide_errors = true; +recipe main [ + x:array:number <- merge 2, 12, 13 +] ++error: main can't determine the size of array variable x. Either allocate it separately and make the type of x address:shared:..., or specify the length of the array in the type of x. -- cgit 1.4.1-2-gfad0 ion value='committer'>committer
blob: 1e41e69315ec6de2587553c9f75cac8daa9f7ec4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22