Repository: carbon-language/carbon-lang
File: toolchain/driver/compile_subcommand.cpp (C++)

Code before:
    driver_env.emitter.Emit(CompileTargetInvalid, target_error);
    return {.success = false};
  }

  std::shared_ptr<clang::CompilerInvocation> clang_invocation;
  // Build a clang invocation. We do this regardless of whether we're running
  // check, because this is essentially performing further option validation,
  // and we generally validate all options even if we're not using them for the
  // selected phases of compilation.
  // TODO: Share any arguments we specify here with the `carbon clang`
  // subcommand.
  {
    llvm::SmallVector<std::string> clang_path_and_args = {
        driver_env.installation->clang_path(),
        // Propagate the target to Clang.
        llvm::formatv("--target={0}", options_.codegen_options.target).str(),
        // Enable PIE by default, but allow it to be overridden by Clang
        // arguments. Clang's default is configurable, but we'd like our
        // defaults to be more stable.
        // TODO: Decide if we want this.
        "-fPIE",
    };
    if (driver_env.fuzzing && !options_.clang_args.empty()) {
      DisableFuzzingExternalLibraries(driver_env, "compile");
      return {.success = false};
    }
    for (auto str : options_.clang_args) {
      clang_path_and_args.push_back(str.str());
    }
    clang_invocation = BuildClangInvocation(driver_env.consumer, driver_env.fs,
                                            clang_path_and_args);
    if (!clang_invocation) {
      return {.success = false};
    }
  }

  // Find the files comprising the prelude if we are importing it.
  // TODO: Replace this with a search for library api files in a
  // package-specific search path based on the library name.
  llvm::SmallVector<std::string> prelude;
  if (options_.prelude_import && !options_.custom_core &&
      options_.phase >= CompileOptions::Phase::Check) {
    if (auto find = driver_env.installation->ReadPreludeManifest(); find.ok()) {
      prelude = std::move(*find);
    } else {
      // TODO: Change ReadPreludeManifest to produce diagnostics.
      CARBON_DIAGNOSTIC(CompilePreludeManifestError, Error, "{0}", std::string);
      driver_env.emitter.Emit(CompilePreludeManifestError,
                              PrintToString(find.error()));
      return {.success = false};
    }

Review comment (suggestion):
Maybe a comment for the future readers?
```suggestion
    if (driver_env.fuzzing && !options_.clang_args.empty()) {
      // Parsing specific Clang arguments can reach deep into
      // externel libraries that aren't fuzz clean.
      DisableFuzzingExternalLibraries(driver_env, "compile");
      return {.success = false};
    }
```

Code after:
    driver_env.emitter.Emit(CompileTargetInvalid, target_error);
    return {.success = false};
  }

  std::shared_ptr<clang::CompilerInvocation> clang_invocation;
  // Build a clang invocation. We do this regardless of whether we're running
  // check, because this is essentially performing further option validation,
  // and we generally validate all options even if we're not using them for the
  // selected phases of compilation.
  // TODO: Share any arguments we specify here with the `carbon clang`
  // subcommand.
  {
    llvm::SmallVector<std::string> clang_path_and_args = {
        driver_env.installation->clang_path(),
        // Propagate the target to Clang.
        llvm::formatv("--target={0}", options_.codegen_options.target).str(),
        // Enable PIE by default, but allow it to be overridden by Clang
        // arguments. Clang's default is configurable, but we'd like our
        // defaults to be more stable.
        // TODO: Decide if we want this.
        "-fPIE",
    };
    if (driver_env.fuzzing && !options_.clang_args.empty()) {
      // Parsing specific Clang arguments can reach deep into
      // external libraries that aren't fuzz clean.
      DisableFuzzingExternalLibraries(driver_env, "compile");
      return {.success = false};
    }
    for (auto str : options_.clang_args) {
      clang_path_and_args.push_back(str.str());
    }
    clang_invocation = BuildClangInvocation(driver_env.consumer, driver_env.fs,
                                            clang_path_and_args);
    if (!clang_invocation) {
      return {.success = false};
    }
  }

  // Find the files comprising the prelude if we are importing it.
  // TODO: Replace this with a search for library api files in a
  // package-specific search path based on the library name.
  llvm::SmallVector<std::string> prelude;
  if (options_.prelude_import && !options_.custom_core &&
      options_.phase >= CompileOptions::Phase::Check) {
    if (auto find = driver_env.installation->ReadPreludeManifest(); find.ok()) {
      prelude = std::move(*find);
    } else {
      // TODO: Change ReadPreludeManifest to produce diagnostics.
      CARBON_DIAGNOSTIC(CompilePreludeManifestError, Error, "{0}", std::string);
      driver_env.emitter.Emit(CompilePreludeManifestError,
                              PrintToString(find.error()));