Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/fuzz/linter.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/Linter.h"
6
#include "Luau/ModuleResolver.h"
7
#include "Luau/Parser.h"
8
#include "Luau/TypeInfer.h"
9
10
#include <string>
11
12
#include <string.h>
13
14
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size)
15
{
16
for (Luau::FValue<bool>* flag = Luau::FValue<bool>::list; flag; flag = flag->next)
17
{
18
if (strncmp(flag->name, "Luau", 4) == 0)
19
flag->value = true;
20
}
21
22
Luau::ParseOptions options;
23
24
Luau::Allocator allocator;
25
Luau::AstNameTable names(allocator);
26
27
Luau::ParseResult parseResult = Luau::Parser::parse(reinterpret_cast<const char*>(Data), Size, names, allocator, options);
28
29
// "static" here is to accelerate fuzzing process by only creating and populating the type environment once
30
static Luau::NullFileResolver fileResolver;
31
static Luau::NullConfigResolver configResolver;
32
static Luau::Frontend frontend{Luau::SolverMode::New, &fileResolver, &configResolver};
33
static int once = (Luau::registerBuiltinGlobals(frontend, frontend.globals, false), 1);
34
(void)once;
35
static int once2 = (Luau::freeze(frontend.globals.globalTypes), 1);
36
(void)once2;
37
38
if (parseResult.errors.empty())
39
{
40
Luau::LintOptions lintOptions;
41
lintOptions.warningMask = ~0ull;
42
43
Luau::lint(parseResult.root, names, frontend.globals.globalScope, nullptr, {}, lintOptions);
44
}
45
46
return 0;
47
}
48
49