Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -3567,6 +3567,8 @@ HelpText<"Print the registered targets">; def print_rocm_search_dirs : Flag<["-", "--"], "print-rocm-search-dirs">, HelpText<"Print the paths used for finding ROCm installation">; +def print_runtime_dir : Flag<["-", "--"], "print-runtime-dir">, + HelpText<"Print the directory pathname containing clangs runtime libraries">; def private__bundle : Flag<["-"], "private_bundle">; def pthreads : Flag<["-"], "pthreads">; defm pthread : BoolOption<"", "pthread", Index: clang/lib/Driver/Driver.cpp =================================================================== --- clang/lib/Driver/Driver.cpp +++ clang/lib/Driver/Driver.cpp @@ -1824,6 +1824,15 @@ return false; } + if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) { + if (auto RuntimePath = TC.getRuntimePath()) { + llvm::outs() << *RuntimePath << '\n'; + return false; + } + llvm::outs() << TC.getCompilerRTPath() << '\n'; + return false; + } + // FIXME: The following handlers should use a callback mechanism, we don't // know what the client would like to do. if (Arg *A = C.getArgs().getLastArg(options::OPT_print_file_name_EQ)) { Index: clang/test/Driver/immediate-options.c =================================================================== --- clang/test/Driver/immediate-options.c +++ clang/test/Driver/immediate-options.c @@ -17,3 +17,15 @@ // Allow unspecified output because the value of CLANG_RESOURCE_DIR is unknown. // RUN: %clang -print-resource-dir | FileCheck %s -check-prefix=PRINT-RESOURCE-DIR // PRINT-RESOURCE-DIR: {{.+}} + +// Default resource-dir layout +// RUN: %clang -print-runtime-dir --target=x86_64-pc-windows-msvc \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: | FileCheck --check-prefix=PRINT-RUNTIME-DIR %s +// PRINT-RUNTIME-DIR: lib{{/|\\}}windows + +// Per target dir layout +// RUN: %clang -print-runtime-dir --target=x86_64-pc-windows-msvc \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ +// RUN: | FileCheck --check-prefix=PRINT-RUNTIME-DIR-PER-TARGET %s +// PRINT-RUNTIME-DIR-PER-TARGET: lib{{/|\\}}x86_64-pc-windows-msvc