mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 20:01:14 +01:00
Right now we expect crashes on invalid parses, we just don't try to handle it in general even though the long-term intent is we should handle semantics for bad parses. However, in theory, we should be correctly handling code that parses as valid and that's probably more interesting to fix bugs for. So this starts trying to fuzz that space of valid parses. Fuzzer corpus is based on explorer tests, with one merge run.
151 lines
3.9 KiB
Python
151 lines
3.9 KiB
Python
# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
# Exceptions. See /LICENSE for license information.
|
|
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
load("//bazel/fuzzing:rules.bzl", "cc_fuzz_test")
|
|
load("//bazel/sh_run:rules.bzl", "glob_sh_run")
|
|
load("//testing/file_test:rules.bzl", "file_test")
|
|
|
|
package(default_visibility = ["//visibility:public"])
|
|
|
|
cc_library(
|
|
name = "semantics_builtin_kind",
|
|
srcs = ["semantics_builtin_kind.cpp"],
|
|
hdrs = ["semantics_builtin_kind.h"],
|
|
textual_hdrs = ["semantics_builtin_kind.def"],
|
|
deps = ["//common:enum_base"],
|
|
)
|
|
|
|
cc_library(
|
|
name = "semantics_node_kind",
|
|
srcs = ["semantics_node_kind.cpp"],
|
|
hdrs = ["semantics_node_kind.h"],
|
|
textual_hdrs = ["semantics_node_kind.def"],
|
|
deps = ["//common:enum_base"],
|
|
)
|
|
|
|
cc_library(
|
|
name = "semantics_node",
|
|
srcs = ["semantics_node.cpp"],
|
|
hdrs = ["semantics_node.h"],
|
|
deps = [
|
|
":semantics_builtin_kind",
|
|
":semantics_node_kind",
|
|
"//common:check",
|
|
"//common:ostream",
|
|
"//toolchain/common:index_base",
|
|
"//toolchain/parser:parse_tree",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_library(
|
|
name = "semantics_node_stack",
|
|
srcs = ["semantics_node_stack.cpp"],
|
|
hdrs = ["semantics_node_stack.h"],
|
|
deps = [
|
|
":semantics_node",
|
|
"//common:check",
|
|
"//common:ostream",
|
|
"//common:vlog",
|
|
"//toolchain/parser:parse_node_kind",
|
|
"//toolchain/parser:parse_tree",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_library(
|
|
name = "semantics_ir",
|
|
srcs = [
|
|
"semantics_ir.cpp",
|
|
"semantics_context.cpp",
|
|
"semantics_node_block_stack.cpp",
|
|
"semantics_declaration_name_stack.cpp",
|
|
] +
|
|
# Glob handler files to avoid missing anyway.
|
|
glob([
|
|
"semantics_handle*.cpp",
|
|
]),
|
|
hdrs = [
|
|
"semantics_context.h",
|
|
"semantics_declaration_name_stack.h",
|
|
"semantics_ir.h",
|
|
"semantics_node_block_stack.h",
|
|
],
|
|
deps = [
|
|
":semantics_builtin_kind",
|
|
":semantics_node",
|
|
":semantics_node_kind",
|
|
":semantics_node_stack",
|
|
"//common:check",
|
|
"//common:ostream",
|
|
"//common:vlog",
|
|
"//toolchain/common:pretty_stack_trace_function",
|
|
"//toolchain/diagnostics:diagnostic_kind",
|
|
"//toolchain/lexer:numeric_literal",
|
|
"//toolchain/lexer:token_kind",
|
|
"//toolchain/lexer:tokenized_buffer",
|
|
"//toolchain/parser:parse_node_kind",
|
|
"//toolchain/parser:parse_tree",
|
|
"//toolchain/parser:parse_tree_node_location_translator",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_test(
|
|
name = "semantics_ir_test",
|
|
size = "small",
|
|
srcs = ["semantics_ir_test.cpp"],
|
|
deps = [
|
|
"//testing/util:gtest_main",
|
|
"//testing/util:test_raw_ostream",
|
|
"//toolchain/common:yaml_test_helpers",
|
|
"//toolchain/driver",
|
|
"@com_google_googletest//:gtest",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
file_test(
|
|
name = "semantics_file_test",
|
|
srcs = ["semantics_file_test.cpp"],
|
|
tests = glob(["testdata/**/*.carbon"]),
|
|
deps = [
|
|
"//toolchain/driver:driver_file_test_base",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_fuzz_test(
|
|
name = "semantics_fuzzer",
|
|
size = "small",
|
|
srcs = ["semantics_fuzzer.cpp"],
|
|
corpus = glob(["fuzzer_corpus/*"]),
|
|
deps = [
|
|
"//toolchain/driver",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
glob_sh_run(
|
|
args = [
|
|
"$(location //toolchain/driver:carbon)",
|
|
"dump",
|
|
"semantics-ir",
|
|
],
|
|
data = ["//toolchain/driver:carbon"],
|
|
file_exts = ["carbon"],
|
|
)
|
|
|
|
glob_sh_run(
|
|
args = [
|
|
"$(location //toolchain/driver:carbon)",
|
|
"-v",
|
|
"dump",
|
|
"semantics-ir",
|
|
],
|
|
data = ["//toolchain/driver:carbon"],
|
|
file_exts = ["carbon"],
|
|
run_ext = "verbose",
|
|
)
|