瀏覽代碼

fix -vet warning for stack overflows not showing up

Due to the placement of this code, the warning would only ever be added
if the variable was also either unused or shadowed.
Laytan Laats 1 年之前
父節點
當前提交
b754c1e072
共有 1 個文件被更改,包括 9 次插入11 次删除
  1. 9 11
      src/checker.cpp

+ 9 - 11
src/checker.cpp

@@ -703,6 +703,15 @@ gb_internal void check_scope_usage(Checker *c, Scope *scope, u64 vet_flags) {
 			array_add(&vetted_entities, ve_unused);
 			array_add(&vetted_entities, ve_unused);
 		} else if (is_shadowed) {
 		} else if (is_shadowed) {
 			array_add(&vetted_entities, ve_shadowed);
 			array_add(&vetted_entities, ve_shadowed);
+		} else if (e->kind == Entity_Variable && (e->flags & (EntityFlag_Param|EntityFlag_Using)) == 0) {
+			i64 sz = type_size_of(e->type);
+			// TODO(bill): When is a good size warn?
+			// Is 128 KiB good enough?
+			if (sz >= 1ll<<17) {
+				gbString type_str = type_to_string(e->type);
+				warning(e->token, "Declaration of '%.*s' may cause a stack overflow due to its type '%s' having a size of %lld bytes", LIT(e->token.string), type_str, cast(long long)sz);
+				gb_string_free(type_str);
+			}
 		}
 		}
 	}
 	}
 	rw_mutex_shared_unlock(&scope->mutex);
 	rw_mutex_shared_unlock(&scope->mutex);
@@ -734,17 +743,6 @@ gb_internal void check_scope_usage(Checker *c, Scope *scope, u64 vet_flags) {
 				break;
 				break;
 			}
 			}
 		}
 		}
-
-		if (e->kind == Entity_Variable && (e->flags & (EntityFlag_Param|EntityFlag_Using)) == 0) {
-			i64 sz = type_size_of(e->type);
-			// TODO(bill): When is a good size warn?
-			// Is 128 KiB good enough?
-			if (sz >= 1ll<<17) {
-				gbString type_str = type_to_string(e->type);
-				warning(e->token, "Declaration of '%.*s' may cause a stack overflow due to its type '%s' having a size of %lld bytes", LIT(name), type_str, cast(long long)sz);
-				gb_string_free(type_str);
-			}
-		}
 	}
 	}
 
 
 	array_free(&vetted_entities);
 	array_free(&vetted_entities);