init_llvm.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #include "common/init_llvm.h"
  5. #include "llvm/Support/TargetSelect.h"
  6. namespace Carbon {
  7. InitLLVM::InitLLVM(int& argc, char**& argv)
  8. : init_llvm_(argc, argv),
  9. // LLVM assumes that argc and argv won't change, and registers them with
  10. // an `llvm::PrettyStackTraceProgram` that will crash if an argv element
  11. // gets nulled out, which for example `testing::InitGoogleTest` does. So
  12. // make a copy of the argv that LLVM produces in order to support
  13. // mutation.
  14. args_(argv, argv + argc) {
  15. // Return our mutable copy of argv for the program to use.
  16. argc = args_.size();
  17. argv = args_.data();
  18. // `argv[argc]` is expected to be a null pointer.
  19. args_.push_back(0);
  20. llvm::setBugReportMsg(
  21. "Please report issues to "
  22. "https://github.com/carbon-language/carbon-lang/issues and include the "
  23. "crash backtrace.\n");
  24. // Initialize LLVM targets if //common:all_llvm_targets was linked in.
  25. if (InitializeTargets) {
  26. InitializeTargets();
  27. }
  28. }
  29. auto (*InitLLVM::InitializeTargets)() -> void = nullptr;
  30. } // namespace Carbon