diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 05d6203453c2..7fd2b4f53934 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -2635,6 +2635,9 @@ def fsycl_host_compiler_options_EQ : Joined<["-"], "fsycl-host-compiler-options= def fno_sycl_use_footer : Flag<["-"], "fno-sycl-use-footer">, Flags<[CoreOption]>, HelpText<"Disable usage of the integration footer during SYCL enabled " "compilations.">; +def fsycl_footer_path_EQ : Joined<["-"], "fsycl-footer-path=">, + Flags<[CoreOption]>, HelpText<"Specify the location of the temporary " + "source file with the included integration footer.">; def fsyntax_only : Flag<["-"], "fsyntax-only">, Flags<[NoXarchOption,CoreOption,CC1Option,FC1Option]>, Group; def ftabstop_EQ : Joined<["-"], "ftabstop=">, Group; diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index fb2ec73acaf4..64ad2b449032 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -6753,6 +6753,32 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA, &JA); } + // Redirect output for the generated source + integration footer. + if (isa(JA)) { + if (Arg *A = C.getArgs().getLastArg(options::OPT_fsycl_footer_path_EQ)) { + SmallString<128> OutName(A->getValue()); + StringRef BaseName = llvm::sys::path::filename(BaseInput); + if (isSaveTempsEnabled()) { + // Retain the location specified by the user with -save-temps. + const char *Suffix = types::getTypeTempSuffix(JA.getType()); + std::string::size_type End = std::string::npos; + if (!types::appendSuffixForType(JA.getType())) + End = BaseName.rfind('.'); + SmallString<128> Suffixed(BaseName.substr(0, End)); + Suffixed += OffloadingPrefix; + Suffixed += '.'; + Suffixed += Suffix; + llvm::sys::path::append(OutName, Suffixed.c_str()); + } else { + std::string TmpName = + GetTemporaryPath(llvm::sys::path::stem(BaseName), + types::getTypeTempSuffix(JA.getType())); + llvm::sys::path::append(OutName, llvm::sys::path::filename(TmpName)); + } + return C.addTempFile(C.getArgs().MakeArgString(OutName)); + } + } + // Default to writing to stdout? if (AtTopLevel && !CCGenDiagnostics && HasPreprocessOutput(JA)) { return "-"; diff --git a/clang/test/Driver/sycl-int-footer.cpp b/clang/test/Driver/sycl-int-footer.cpp index 3b03febcfb43..e1e9e62199ff 100644 --- a/clang/test/Driver/sycl-int-footer.cpp +++ b/clang/test/Driver/sycl-int-footer.cpp @@ -60,3 +60,9 @@ // COMMON-PHASES: [[#OFFLOAD+9]]: file-table-tform, {[[#OFFLOAD+6]], [[#OFFLOAD+8]]}, tempfiletable, (device-sycl) // COMMON-PHASES: [[#OFFLOAD+10]]: clang-offload-wrapper, {[[#OFFLOAD+9]]}, object, (device-sycl) // COMMON-PHASES: [[#OFFLOAD+11]]: offload, "host-sycl (x86_64-{{.*}})" {[[#OFFLOAD+4]]}, "device-sycl (spir64-unknown-unknown-sycldevice)" {[[#OFFLOAD+10]]}, image + +/// Test for -fsycl-footer-path= +// RUN: %clangxx -fsycl -fsycl-footer-path=dummy_dir %s -### 2>&1 \ +// RUN: | FileCheck -check-prefix FOOTER_PATH %s +// FOOTER_PATH: append-file{{.*}} "--output=dummy_dir{{(/|\\\\)}}[[APPENDEDSRC:.+\.cpp]]" +// FOOTER_PATH: clang{{.*}} "-x" "c++" "dummy_dir{{(/|\\\\)}}[[APPENDEDSRC]]"