Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/fuzz/typeck.cpp
2723 views
1
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2
#include "Luau/BuiltinDefinitions.h"
3
#include "Luau/Common.h"
4
#include "Luau/Frontend.h"
5
#include "Luau/ModuleResolver.h"
6
#include "Luau/Parser.h"
7
#include "Luau/TypeInfer.h"
8
9
#include <string>
10
11
#include <string.h>
12
13
LUAU_FASTINT(LuauTypeInferRecursionLimit)
14
LUAU_FASTINT(LuauTypeInferTypePackLoopLimit)
15
16
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size)
17
{
18
FInt::LuauTypeInferRecursionLimit.value = 100;
19
FInt::LuauTypeInferTypePackLoopLimit.value = 100;
20
21
for (Luau::FValue<bool>* flag = Luau::FValue<bool>::list; flag; flag = flag->next)
22
{
23
if (strncmp(flag->name, "Luau", 4) == 0)
24
flag->value = true;
25
}
26
27
Luau::ParseOptions options;
28
29
Luau::Allocator allocator;
30
Luau::AstNameTable names(allocator);
31
32
Luau::ParseResult parseResult = Luau::Parser::parse(reinterpret_cast<const char*>(Data), Size, names, allocator, options);
33
34
// "static" here is to accelerate fuzzing process by only creating and populating the type environment once
35
static Luau::NullFileResolver fileResolver;
36
static Luau::NullConfigResolver configResolver;
37
static Luau::Frontend frontend{&fileResolver, &configResolver};
38
static int once = (Luau::registerBuiltinGlobals(frontend, frontend.globals, false), 1);
39
(void)once;
40
static int once2 = (Luau::freeze(frontend.globals.globalTypes), 1);
41
(void)once2;
42
43
if (parseResult.errors.empty())
44
{
45
Luau::TypeChecker typeck(frontend.globals.globalScope, &frontend.moduleResolver, frontend.builtinTypes, &frontend.iceHandler);
46
47
Luau::SourceModule module;
48
module.root = parseResult.root;
49
module.mode = Luau::Mode::Nonstrict;
50
51
try
52
{
53
typeck.check(module, Luau::Mode::Nonstrict);
54
}
55
catch (std::exception&)
56
{
57
// This catches internal errors that the type checker currently (unfortunately) throws in some cases
58
}
59
}
60
61
return 0;
62
}
63
64