rayanht/SPIRVSmith

View on GitHub

Showing 19 of 35 total issues

File recondition.py has 482 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from abc import ABC
from dataclasses import dataclass
from dataclasses import field
from inspect import isclass
from typing import Generic
Severity: Minor
Found in src/recondition.py - About 7 hrs to fix

    Function resolve_operands has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
    Open

    def resolve_operands(
        opcode_class: type[OpCode],
        operands: list[str],
        opcode_lookup_table: dict[str, OpCode],
    ) -> tuple[OpCode | str | int | float, ...]:
    Severity: Minor
    Found in src/shader_parser.py - About 5 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    File context.py has 361 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import inspect
    import random
    from dataclasses import dataclass
    from dataclasses import field
    from types import NoneType
    Severity: Minor
    Found in src/context.py - About 4 hrs to fix

      File shader_utils.py has 354 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      import random
      import subprocess
      import tempfile
      from dataclasses import field
      from enum import Enum
      Severity: Minor
      Found in src/shader_utils.py - About 4 hrs to fix

        Function start has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
        Open

            def start(self):
                MP_pool: Pool = multiprocessing.Pool(4, init_MP_pool)
                thread_pool_executor: ThreadPoolExecutor = ThreadPoolExecutor(max_workers=4)
        
                if self.config.misc.broadcast_generated_shaders:
        Severity: Minor
        Found in src/fuzzing_client.py - About 2 hrs to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function recondition has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

            def recondition(
                context: Context,
                opcode: UndefOpCodeVulnerableOpCode,
            ) -> ReconditioningEffects:
                if not isclass(opcode):
        Severity: Minor
        Found in src/recondition.py - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function fuzz has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def fuzz(cls, context: "Context") -> FuzzResult[Self]:
                (
                    source_type,
                    destination_type,
                    source_constraint,
        Severity: Minor
        Found in src/operators/__init__.py - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function fuzz_block has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

        def fuzz_block(
            context: "Context",
            exit_label: Optional[OpLabel],
            limiter: Optional[int] = 4096,
        ) -> tuple[OpCode]:
        Severity: Minor
        Found in src/function.py - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function fuzz has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def fuzz(cls, context: "Context") -> FuzzResult[Self]:
                (
                    source_type,
                    destination_type,
                    source_constraint,
        Severity: Minor
        Found in src/operators/__init__.py - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function gen_shader has 28 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def gen_shader(self) -> SPIRVShader:
                execution_model = ExecutionModel.GLCompute
                context: Context = Context.create_global_context(execution_model, self.config)
                void_type: OpTypeVoid = OpTypeVoid()
                main_type: OpTypeFunction = OpTypeFunction(
        Severity: Minor
        Found in src/fuzzing_client.py - About 1 hr to fix

          Function gen_constants has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              def gen_constants(self):
                  n_constants = self.config.limits.n_constants
                  n_scalars = (
                      self.config.strategy.w_scalar_constant
                      * n_constants
          Severity: Minor
          Found in src/context.py - About 1 hr to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function to_spasm has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              def to_spasm(self, context: "Context") -> str:
                  attrs = self.members()
                  if self.__class__.__name__ == "OpStore":
                      pass
                  if isinstance(self, VoidOp):
          Severity: Minor
          Found in src/__init__.py - About 1 hr to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function resolve_attribute_spasm has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              def resolve_attribute_spasm(self, attr, context: "Context") -> str:
                  if (
                      attr.__class__.__name__ == "Context"
                      or attr is None
                      or attr.__class__.__name__ == "EmptyType"
          Severity: Minor
          Found in src/__init__.py - About 1 hr to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Avoid deeply nested control flow statements.
          Open

                                      if resolved_operand == "None":
                                          resolved_operand = "NONE"
                                      resolved_operand = enum_class(resolved_operand)
          Severity: Major
          Found in src/shader_parser.py - About 45 mins to fix

            Function create_on_demand_numerical_constant has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                def create_on_demand_numerical_constant(
            Severity: Minor
            Found in src/context.py - About 35 mins to fix

              Function is_interesting has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

              def is_interesting(spv_file_path: str, n_reports: int) -> int:
                  if validate_spv_file(spv_file_path).exit_code != 0:
                      return 1
                  with NamedTemporaryFile(suffix=".spasm") as disassembled_spasm_file:
                      if not disassemble_spv_file(spv_file_path, disassembled_spasm_file.name):
              Severity: Minor
              Found in interestingness.py - About 35 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Avoid too many return statements within this function.
              Open

                      return 1
              Severity: Major
              Found in interestingness.py - About 30 mins to fix

                Function gen_global_variables has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    def gen_global_variables(self):
                        n = len(self.globals)
                        for i in range(self.rng.randint(1, 3)):
                            variable = self.create_on_demand_variable(StorageClass.StorageBuffer)
                            if len(self.globals) != n:
                Severity: Minor
                Found in src/context.py - About 25 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Function gen_types has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    def gen_types(self):
                        for _ in range(self.config.limits.n_types - 1):
                            try:
                                fuzzed_type: FuzzResult = Type.fuzz(self)
                            except (RecursionError, AbortFuzzing):
                Severity: Minor
                Found in src/context.py - About 25 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Severity
                Category
                Status
                Source
                Language