diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 923b61cc0e61b..ca7928f1f510e 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -4638,10 +4638,14 @@ def image__base : Separate<["-"], "image_base">; def include_ : JoinedOrSeparate<["-", "--"], "include">, Group, EnumName<"include">, MetaVarName<"">, HelpText<"Include file before parsing">, Visibility<[ClangOption, CC1Option]>; -def include_footer : Separate<["-"], "include-footer">, Group, +def include_internal_footer : Separate<["-"], "include-internal-footer">, Group, Visibility<[CC1Option]>, HelpText<"Name of the footer integration file">, MetaVarName<"">, MarshallingInfoString>; +def include_internal_header : Separate<["-"], "include-internal-header">, Group, + Visibility<[CC1Option]>, + HelpText<"Name of the header integration file">, MetaVarName<"">, + MarshallingInfoString>; def include_pch : Separate<["-"], "include-pch">, Group, Visibility<[ClangOption, CC1Option]>, HelpText<"Include precompiled header file">, MetaVarName<"">, diff --git a/clang/include/clang/Lex/PreprocessorOptions.h b/clang/include/clang/Lex/PreprocessorOptions.h index fc98c15c3fc9b..6773d98a8548b 100644 --- a/clang/include/clang/Lex/PreprocessorOptions.h +++ b/clang/include/clang/Lex/PreprocessorOptions.h @@ -68,6 +68,7 @@ class PreprocessorOptions { std::vector> Macros; std::vector Includes; std::string IncludeFooter; + std::string IncludeHeader; std::vector MacroIncludes; /// Perform extra checks when loading PCM files for mutable file systems. diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index a7f8a61402533..16c1ac10aeda2 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -5734,7 +5734,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, // action to determine this. if (types::getPreprocessedType(Input.getType()) != types::TY_INVALID && !Header.empty()) { - CmdArgs.push_back("-include"); + // Add the -include-internal-header option to add the integration header + CmdArgs.push_back("-include-internal-header"); CmdArgs.push_back(Args.MakeArgString(Header)); // When creating dependency information, filter out the generated // header file. @@ -5746,11 +5747,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("-fsycl-enable-int-header-diags"); } - // Add the -include-footer option to add the integration footer StringRef Footer = D.getIntegrationFooter(Input.getBaseInput()); if (types::getPreprocessedType(Input.getType()) != types::TY_INVALID && !Args.hasArg(options::OPT_fno_sycl_use_footer) && !Footer.empty()) { - CmdArgs.push_back("-include-footer"); + // Add the -include-internal-footer option to add the integration footer + CmdArgs.push_back("-include-internal-footer"); CmdArgs.push_back(Args.MakeArgString(Footer)); // When creating dependency information, filter out the generated // integration footer file. diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index 23d3c2d753789..b8de1082b8933 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -1663,6 +1663,13 @@ void clang::InitializePreprocessor(Preprocessor &PP, AddImplicitInclude(Builder, Path); } + // Process -include-internal-header directive. + if (!LangOpts.SYCLIsDevice) { + if (!InitOpts.IncludeHeader.empty()) { + AddImplicitInclude(Builder, InitOpts.IncludeHeader); + } + } + // Instruct the preprocessor to skip the preamble. PP.setSkipMainFilePreamble(InitOpts.PrecompiledPreambleBytes.first, InitOpts.PrecompiledPreambleBytes.second); diff --git a/clang/lib/Frontend/PrintPreprocessedOutput.cpp b/clang/lib/Frontend/PrintPreprocessedOutput.cpp index df69f18e0efb3..127c5da8e10c8 100644 --- a/clang/lib/Frontend/PrintPreprocessedOutput.cpp +++ b/clang/lib/Frontend/PrintPreprocessedOutput.cpp @@ -265,11 +265,24 @@ void PrintPPOutputPPCallbacks::WriteFooterContent(StringRef CodeFooter) { *OS << '\n'; } +static bool is_separator(char value) { return value == '\\'; } + void PrintPPOutputPPCallbacks::WriteLineInfo(unsigned LineNo, const char *Extra, unsigned ExtraLen) { startNewLineIfNeeded(); + if (PP.getLangOpts().isSYCL()) { + StringRef CurFilenameWithNoLeadingDotSlash = + llvm::sys::path::remove_leading_dotbackslash_only(CurFilename.str()); + if ((CurFilenameWithNoLeadingDotSlash == + PP.getPreprocessorOpts().IncludeFooter) || + CurFilenameWithNoLeadingDotSlash == + PP.getPreprocessorOpts().IncludeHeader) { + CurFilename = ""; + } + } + // Emit #line directives or GNU line markers depending on what mode we're in. if (UseLineDirectives) { *OS << "#line" << ' ' << LineNo << ' ' << '"'; @@ -288,6 +301,7 @@ void PrintPPOutputPPCallbacks::WriteLineInfo(unsigned LineNo, else if (FileType == SrcMgr::C_ExternCSystem) OS->write(" 3 4", 4); } + *OS << '\n'; } @@ -913,8 +927,6 @@ static void PrintIncludeFooter(Preprocessor &PP, SourceLocation Loc, return; FileID FooterFileID = SourceMgr.ComputeValidFooterFileID(Footer); StringRef FooterContentBuffer = SourceMgr.getBufferData(FooterFileID); - // print out the name of the integration footer. - Callbacks->WriteFooterInfo(Footer); SmallVector FooterContentArr; FooterContentBuffer.split(FooterContentArr, '\r'); // print out the content of the integration footer. @@ -1185,15 +1197,6 @@ void clang::DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS, PrintPreprocessedTokens(PP, Tok, Callbacks); *OS << '\n'; - if (!PP.getPreprocessorOpts().IncludeFooter.empty() && - !PP.IncludeFooterProcessed) { - assert(PP.getLangOpts().SYCLIsHost && - "The 'include-footer' is expected in host compilation only"); - SourceLocation Loc = Tok.getLocation(); - PrintIncludeFooter(PP, Loc, PP.getPreprocessorOpts().IncludeFooter, - Callbacks); - } - // Remove the handlers we just added to leave the preprocessor in a sane state // so that it can be reused (for example by a clang::Parser instance). PP.RemovePragmaHandler(MicrosoftExtHandler.get()); diff --git a/clang/test/CodeGenSYCL/debug-info-file-checksum.cpp b/clang/test/CodeGenSYCL/debug-info-file-checksum.cpp index 5d62761a4f33a..ec6e6348035cf 100644 --- a/clang/test/CodeGenSYCL/debug-info-file-checksum.cpp +++ b/clang/test/CodeGenSYCL/debug-info-file-checksum.cpp @@ -16,8 +16,8 @@ // COMP1-SAME: checksumkind: CSK_MD5, checksum: "259269f735d83ec32c46a11352458493") // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsycl-is-host \ -// RUN: -include %t.header.h -dependency-filter %t.header.h \ -// RUN: -include-footer %t.footer.h -dependency-filter %t.footer.h \ +// RUN: -include-internal-header %t.header.h -dependency-filter %t.header.h \ +// RUN: -include-internal-footer %t.footer.h -dependency-filter %t.footer.h \ // RUN: -main-file-name %S/Inputs/checksum.cpp \ // RUN: -gcodeview -debug-info-kind=limited -emit-llvm -O0 -o - \ // RUN: "%S/Inputs/checksum.cpp" \ diff --git a/clang/test/Driver/sycl-int-footer-old-model.cpp b/clang/test/Driver/sycl-int-footer-old-model.cpp index caa6000fad90c..256a5cee95686 100644 --- a/clang/test/Driver/sycl-int-footer-old-model.cpp +++ b/clang/test/Driver/sycl-int-footer-old-model.cpp @@ -2,19 +2,17 @@ // RUN: %clangxx -fsycl --no-offload-new-driver -I cmdline/dir -include dummy.h %/s -### 2>&1 \ // RUN: | FileCheck -check-prefix FOOTER %s -DSRCDIR=%/S -DCMDDIR=cmdline/dir // FOOTER: clang{{.*}} "-fsycl-is-device"{{.*}} "-fsycl-int-header=[[INTHEADER:.+\.h]]" "-fsycl-int-footer=[[INTFOOTER:.+\h]]" "-sycl-std={{.*}}"{{.*}} "-include" "dummy.h" -// FOOTER: clang{{.*}} "-include" "[[INTHEADER]]" +// FOOTER: clang{{.*}} "-include-internal-header" "[[INTHEADER]]" // FOOTER-SAME: "-dependency-filter" "[[INTHEADER]]" -// FOOTER-SAME: "-include-footer" "[[INTFOOTER]]" -// FOOTER-SAME: "-dependency-filter" "[[INTFOOTER]]" // FOOTER-SAME: "-fsycl-is-host"{{.*}} "-main-file-name" "[[SRCFILE:.+\cpp]]" {{.*}} "-include" "dummy.h"{{.*}} "-I" "cmdline/dir" /// Preprocessed file creation with integration footer // RUN: %clangxx -fsycl --no-offload-new-driver -E %/s -### 2>&1 \ // RUN: | FileCheck -check-prefix FOOTER_PREPROC_GEN %s // FOOTER_PREPROC_GEN: clang{{.*}} "-fsycl-is-device"{{.*}} "-fsycl-int-header=[[INTHEADER:.+\.h]]" "-fsycl-int-footer=[[INTFOOTER:.+\h]]" "-sycl-std={{.*}}" "-o" "[[PREPROC_DEVICE:.+\.ii]]" -// FOOTER_PREPROC_GEN: clang{{.*}} "-include" "[[INTHEADER]]" -// FOOTER_PREPROC_GEN: "-dependency-filter" "[[INTHEADER]]" -// FOOTER_PREPROC_GEN-SAME: "-include-footer" "[[INTFOOTER]]" +// FOOTER_PREPROC_GEN: clang{{.*}} "-include-internal-header" "[[INTHEADER]]" +// FOOTER_PREPROC_GEN-SAME: "-dependency-filter" "[[INTHEADER]]" +// FOOTER_PREPROC_GEN-SAME: "-include-internal-footer" "[[INTFOOTER]]" // FOOTER_PREPROC_GEN-SAME: "-dependency-filter" "[[INTFOOTER]]" // FOOTER_PREPROC_GEN-SAME: "-fsycl-is-host"{{.*}} "-E"{{.*}} "-o" "[[PREPROC_HOST:.+\.ii]]" @@ -31,7 +29,7 @@ // RUN: | FileCheck -check-prefix NO-FOOTER --implicit-check-not "-fsycl-int-footer" %s // NO-FOOTER: clang{{.*}} "-fsycl-is-device"{{.*}} "-fsycl-int-header=[[INTHEADER:.+\.h]]" "-sycl-std={{.*}}" // NO-FOOTER-NOT: append-file -// NO-FOOTER: clang{{.*}} "-include" "[[INTHEADER]]"{{.*}} "-fsycl-is-host" +// NO-FOOTER: clang{{.*}} "-include-internal-header" "[[INTHEADER]]"{{.*}} "-fsycl-is-host" /// Check phases without integration footer // RUN: %clangxx -fsycl --no-offload-new-driver -fno-sycl-instrument-device-code -fno-sycl-device-lib=all -fno-sycl-use-footer -target x86_64-unknown-linux-gnu %s -ccc-print-phases 2>&1 \ @@ -69,7 +67,7 @@ // RUN: | FileCheck -check-prefix FOOTER_PATH %s // FOOTER_PATH: clang{{.*}} "-fsycl-is-device" // FOOTER_PATH-SAME: "-fsycl-int-footer=dummy_dir{{(/|\\\\)}}{{.*}}-footer-{{.*}}.h" -// FOOTER_PATH: clang{{.*}} "-include-footer" "dummy_dir{{(/|\\\\)}}{{.*}}-footer-{{.*}}.h" +// FOOTER_PATH: clang{{.*}} "-include-internal-footer" "dummy_dir{{(/|\\\\)}}{{.*}}-footer-{{.*}}.h" /// Check behaviors for dependency generation diff --git a/clang/test/Driver/sycl-int-footer.cpp b/clang/test/Driver/sycl-int-header-footer.cpp similarity index 90% rename from clang/test/Driver/sycl-int-footer.cpp rename to clang/test/Driver/sycl-int-header-footer.cpp index 8186e41de65bc..4bddfcfecd92e 100644 --- a/clang/test/Driver/sycl-int-footer.cpp +++ b/clang/test/Driver/sycl-int-header-footer.cpp @@ -1,17 +1,20 @@ /// Check compilation tool steps when using the integration footer // RUN: %clangxx -fsycl --offload-new-driver -I cmdline/dir -include dummy.h %/s -### 2>&1 \ // RUN: | FileCheck -check-prefix FOOTER %s -DSRCDIR=%/S -DCMDDIR=cmdline/dir + // FOOTER: clang{{.*}} "-fsycl-is-device"{{.*}} "-fsycl-int-header=[[INTHEADER:.+\.h]]" "-fsycl-int-footer=[[INTFOOTER:.+\h]]" "-sycl-std={{.*}}"{{.*}} "-include" "dummy.h" -// FOOTER: clang{{.*}} "-include" "[[INTHEADER]]" +// FOOTER: clang{{.*}} "-include-internal-header" "[[INTHEADER]]" // FOOTER-SAME: "-fsycl-is-host"{{.*}} "-include" "dummy.h"{{.*}} "-I" "cmdline/dir" -// FOOTER-NOT: "-include" "[[INTHEADER]]" +// FOOTER-NOT: "-include-internal-header" "[[INTHEADER]]" /// Preprocessed file creation with integration footer // RUN: %clangxx -fsycl --offload-new-driver -E %/s -### 2>&1 \ // RUN: | FileCheck -check-prefix FOOTER_PREPROC_GEN %s // FOOTER_PREPROC_GEN: clang{{.*}} "-fsycl-is-device"{{.*}} "-fsycl-int-header=[[INTHEADER:.+\.h]]" "-fsycl-int-footer=[[INTFOOTER:.+\h]]" "-sycl-std={{.*}}" "-o" "[[PREPROC_DEVICE:.+\.ii]]" -// FOOTER_PREPROC_GEN: clang{{.*}} "-include" "[[INTHEADER]]" -// FOOTER_PREPROC_GEN-SAME: "-include-footer" "[[INTFOOTER]]" +// FOOTER_PREPROC_GEN: clang{{.*}} "-include-internal-header" "[[INTHEADER]]" +// FOOTER_PREPROC_GEN-SAME: "-dependency-filter" "[[INTHEADER]]" +// FOOTER_PREPROC_GEN-SAME: "-include-internal-footer" "[[INTFOOTER]]" +// FOOTER_PREPROC_GEN-SAME: "-dependency-filter" "[[INTFOOTER]]" // FOOTER_PREPROC_GEN-SAME: "-fsycl-is-host"{{.*}} "-E"{{.*}} "-o" "-" /// Preprocessed file use with integration footer @@ -24,7 +27,7 @@ // RUN: %clangxx -fsycl --offload-new-driver -fno-sycl-use-footer %s -### 2>&1 \ // RUN: | FileCheck -check-prefix NO-FOOTER --implicit-check-not "-fsycl-int-footer" %s // NO-FOOTER: clang{{.*}} "-fsycl-is-device"{{.*}} "-fsycl-int-header=[[INTHEADER:.+\.h]]" "-sycl-std={{.*}}" -// NO-FOOTER: clang{{.*}} "-include" "[[INTHEADER]]"{{.*}} "-fsycl-is-host"{{.*}} "-o" +// NO-FOOTER: clang{{.*}} "-include-internal-header" "[[INTHEADER]]"{{.*}} "-fsycl-is-host"{{.*}} "-o" /// Check phases without integration footer // RUN: %clangxx -fsycl --offload-new-driver -fno-sycl-instrument-device-code -fno-sycl-device-lib=all -fno-sycl-use-footer -target x86_64-unknown-linux-gnu %s -ccc-print-phases 2>&1 \ @@ -58,7 +61,7 @@ // RUN: | FileCheck -check-prefix FOOTER_PATH %s // FOOTER_PATH: clang{{.*}} "-fsycl-is-device" // FOOTER_PATH-SAME: "-fsycl-int-footer=dummy_dir{{(/|\\\\)}}{{.*}}-footer-{{.*}}.h" -// FOOTER_PATH: clang{{.*}} "-include-footer" "dummy_dir{{(/|\\\\)}}{{.*}}-footer-{{.*}}.h" +// FOOTER_PATH: clang{{.*}} "-include-internal-footer" "dummy_dir{{(/|\\\\)}}{{.*}}-footer-{{.*}}.h" /// Check behaviors for dependency generation // RUN: %clangxx -fsycl --offload-new-driver -MD -c %s -### 2>&1 \ diff --git a/clang/test/Driver/sycl-offload-aot.cpp b/clang/test/Driver/sycl-offload-aot.cpp index ed3aea3e7600a..6e1d2a3ed4ade 100644 --- a/clang/test/Driver/sycl-offload-aot.cpp +++ b/clang/test/Driver/sycl-offload-aot.cpp @@ -138,7 +138,7 @@ // CHK-TOOLS-GEN: clang{{.*}} "-triple" "spir64_gen-unknown-unknown" // CHK-TOOLS-CPU: clang{{.*}} "-triple" "spir64_x86_64-unknown-unknown" // CHK-TOOLS-AOT: "-fsycl-is-device"{{.*}} "-fsycl-int-header=[[INPUT1:.+\-header.+\.h]]" "-fsycl-int-footer={{.*}}"{{.*}} "-o" "[[OUTPUT1:.+\.bc]]" -// CHK-TOOLS-AOT: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} "-include" "[[INPUT1]]" {{.*}} "-o" "[[OUTPUT7:.+\.o]] +// CHK-TOOLS-AOT: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} "-include-internal-header" "[[INPUT1]]" {{.*}} "-o" "[[OUTPUT7:.+\.o]] // CHK-TOOLS-AOT: llvm-link{{.*}} "[[OUTPUT1]]" "-o" "[[OUTPUT2:.+\.bc]]" // CHK-TOOLS-FPGA: sycl-post-link{{.*}} "-o" "[[OUTPUT2_T:.+\.table]]" "[[OUTPUT2]]" // CHK-TOOLS-GEN: sycl-post-link{{.*}} "-o" "[[OUTPUT2_T:.+\.table]]" "[[OUTPUT2]]" diff --git a/clang/test/Driver/sycl-offload-header-check.cpp b/clang/test/Driver/sycl-offload-header-check.cpp index acb84ec93830d..43f03d56a064e 100644 --- a/clang/test/Driver/sycl-offload-header-check.cpp +++ b/clang/test/Driver/sycl-offload-header-check.cpp @@ -11,5 +11,5 @@ // RUN: FileCheck --check-prefix=CHECK-HEADER %s // CHECK-HEADER: clang{{.*}} "-fsycl-int-header=[[HEADER:.+\.h]]" // CHECK-HEADER: {{.*}} "-internal-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl{{[/\\]+}}stl_wrappers" -// CHECK-HEADER-NOT: clang{{.*}} "-include" "[[HEADER]]" -// CHECK-HEADER: clang{{.*}} "-include" "{{.*}}_dirname{{.+}}.h" +// CHECK-HEADER-NOT: clang{{.*}} "-include-internal-header" "[[HEADER]]" +// CHECK-HEADER: clang{{.*}} "-include-internal-header" "{{.*}}_dirname{{.+}}.h" diff --git a/clang/test/Driver/sycl-offload-new-driver.c b/clang/test/Driver/sycl-offload-new-driver.c index 7fd76f88aa922..33e1a9476ba49 100644 --- a/clang/test/Driver/sycl-offload-new-driver.c +++ b/clang/test/Driver/sycl-offload-new-driver.c @@ -27,7 +27,7 @@ // RUN: %clangxx -### --target=x86_64-unknown-linux-gnu -fsycl -fsycl-targets=spir64 --offload-new-driver %s 2>&1 | FileCheck -check-prefix=CHK-FLOW %s // CHK-FLOW: clang{{.*}} "-cc1" "-triple" "spir64-unknown-unknown" "-aux-triple" "x86_64-unknown-linux-gnu" "-fsycl-is-device" {{.*}} "-fsycl-int-header=[[HEADER:.*]].h" "-fsycl-int-footer=[[FOOTER:.*]].h" {{.*}} "--offload-new-driver" {{.*}} "-o" "[[CC1DEVOUT:.*]]" "-x" "c++" "[[INPUT:.*]]" // CHK-FLOW-NEXT: clang-offload-packager{{.*}} "-o" "[[PACKOUT:.*]]" "--image=file=[[CC1DEVOUT]],triple=spir64-unknown-unknown,arch=,kind=sycl{{.*}}" -// CHK-FLOW-NEXT: clang{{.*}} "-cc1" "-triple" "x86_64-unknown-linux-gnu" {{.*}} "-include" "[[HEADER]].h" "-dependency-filter" "[[HEADER]].h" {{.*}} "-fsycl-is-host"{{.*}} "--offload-new-driver" {{.*}} "-fembed-offload-object=[[PACKOUT]]" {{.*}} "-o" "[[CC1FINALOUT:.*]]" "-x" "c++" "[[INPUT]]" +// CHK-FLOW-NEXT: clang{{.*}} "-cc1" "-triple" "x86_64-unknown-linux-gnu" {{.*}} "-include-internal-header" "[[HEADER]].h" "-dependency-filter" "[[HEADER]].h" {{.*}} "-include-internal-footer" "[[FOOTER]].h" "-dependency-filter" "[[FOOTER]].h" "-fsycl-is-host"{{.*}} "--offload-new-driver" {{.*}} "-fembed-offload-object=[[PACKOUT]]" {{.*}} "-o" "[[CC1FINALOUT:.*]]" "-x" "c++" "[[INPUT]]" // CHK-FLOW-NEXT: clang-linker-wrapper{{.*}} "--host-triple=x86_64-unknown-linux-gnu"{{.*}} "--linker-path={{.*}}/ld" {{.*}} "[[CC1FINALOUT]]" /// Verify options passed to clang-linker-wrapper diff --git a/clang/test/Driver/sycl-offload-old-model.c b/clang/test/Driver/sycl-offload-old-model.c index 685ada6119c93..521755d7a7fd2 100644 --- a/clang/test/Driver/sycl-offload-old-model.c +++ b/clang/test/Driver/sycl-offload-old-model.c @@ -180,7 +180,7 @@ // RUN: %clang -target x86_64-unknown-linux-gnu -fsycl --no-offload-new-driver -c %s -### 2>&1 \ // RUN: | FileCheck %s -check-prefix=CHK-INT-HEADER // CHK-INT-HEADER: clang{{.*}} "-fsycl-is-device"{{.*}} "-fsycl-int-header=[[INPUT1:.+\-header.+\.h]]" "-fsycl-int-footer={{.*}}"{{.*}} "-o" "[[OUTPUT1:.+\.bc]]" -// CHK-INT-HEADER: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} "-include" "[[INPUT1]]" "-dependency-filter" "[[INPUT1]]" {{.*}} "-o" "[[OUTPUT2:.+\.o]]" +// CHK-INT-HEADER: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} "-include-internal-header" "[[INPUT1]]" "-dependency-filter" "[[INPUT1]]" {{.*}} "-o" "[[OUTPUT2:.+\.o]]" // CHK-INT-HEADER: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown,host-x86_64-unknown-linux-gnu" {{.*}} "-input=[[OUTPUT1]]" "-input=[[OUTPUT2]]" /// ########################################################################### @@ -710,7 +710,7 @@ // RUN: %clang_cl -fsycl --no-offload-new-driver /Fosomefile.obj -c %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=FO-CHECK %s // FO-CHECK: clang{{.*}} "-fsycl-int-header=[[HEADER:.+\.h]]" "-fsycl-int-footer={{.*}}"{{.*}} "-o" "[[OUTPUT1:.+\.bc]]" -// FO-CHECK: clang{{.*}} "-include" "[[HEADER]]" {{.*}} "-o" "[[OUTPUT2:.+\.obj]]" +// FO-CHECK: clang{{.*}} "-include-internal-header" "[[HEADER]]" {{.*}} "-o" "[[OUTPUT2:.+\.obj]]" // FO-CHECK: clang-offload-bundler{{.*}} "-output=somefile.obj" "-input=[[OUTPUT1]]" "-input=[[OUTPUT2]]" /// passing of a library should not trigger the unbundler diff --git a/clang/test/Driver/sycl-offload-save-temps-old-model.cpp b/clang/test/Driver/sycl-offload-save-temps-old-model.cpp index 68b821b1b58d4..8fab2697a290e 100644 --- a/clang/test/Driver/sycl-offload-save-temps-old-model.cpp +++ b/clang/test/Driver/sycl-offload-save-temps-old-model.cpp @@ -9,7 +9,7 @@ // RUN: | FileCheck %s --check-prefixes=CHK-FSYCL-SAVE-TEMPS,CHK-FSYCL-SAVE-TEMPS-CONFL // CHK-FSYCL-SAVE-TEMPS: clang{{.*}} "-fsycl-is-device"{{.*}} "-o" "[[DEVICE_BASE_NAME:[a-z0-9-]+]].ii" // CHK-FSYCL-SAVE-TEMPS: clang{{.*}} "-fsycl-is-device"{{.*}} "-fsycl-int-header=[[HEADER_NAME:.+\-header.+\.h]]" "-fsycl-int-footer={{.*}}"{{.*}} "-o" "[[DEVICE_BASE_NAME]].bc"{{.*}} "[[DEVICE_BASE_NAME]].ii" -// CHK-FSYCL-SAVE-TEMPS: clang{{.*}} "-include" "[[HEADER_NAME]]"{{.*}} "-fsycl-is-host"{{.*}} "-o" "[[HOST_BASE_NAME:[a-z0-9_-]+]].ii" +// CHK-FSYCL-SAVE-TEMPS: clang{{.*}} "-include-internal-header" "[[HEADER_NAME]]"{{.*}} "-fsycl-is-host"{{.*}} "-o" "[[HOST_BASE_NAME:[a-z0-9_-]+]].ii" // CHK-FSYCL-SAVE-TEMPS: clang{{.*}} "-o" "[[HOST_BASE_NAME:.*]].bc"{{.*}} "[[HOST_BASE_NAME:[a-z0-9_-]+]].ii" // CHK-FSYCL-SAVE-TEMPS: clang{{.*}} "-o" "[[HOST_BASE_NAME:.*]].s"{{.*}} "[[HOST_BASE_NAME]].bc" // CHK-FSYCL-SAVE-TEMPS: clang{{.*}} "-o" "[[HOST_BASE_NAME:.*]].o"{{.*}} "[[HOST_BASE_NAME]].s" diff --git a/clang/test/Driver/sycl-offload-save-temps.cpp b/clang/test/Driver/sycl-offload-save-temps.cpp index 2dd98598b2646..560d7d6d7da73 100644 --- a/clang/test/Driver/sycl-offload-save-temps.cpp +++ b/clang/test/Driver/sycl-offload-save-temps.cpp @@ -10,7 +10,7 @@ // CHK-FSYCL-SAVE-TEMPS: clang{{.*}} "-fsycl-is-device"{{.*}} "-o" "[[DEVICE_BASE_NAME:[a-z0-9-]+]].ii" // CHK-FSYCL-SAVE-TEMPS: clang{{.*}} "-fsycl-is-device"{{.*}} "-fsycl-int-header=[[HEADER_NAME:.+\-header.+\.h]]" "-fsycl-int-footer={{.*}}"{{.*}} "-o" "[[DEVICE_BASE_NAME]].bc"{{.*}} "[[DEVICE_BASE_NAME]].ii" // CHK-FSYCL-SAVE-TEMPS: clang-offload-packager{{.*}} -// CHK-FSYCL-SAVE-TEMPS: clang{{.*}} "-include" "[[HEADER_NAME]]"{{.*}} "-fsycl-is-host"{{.*}} "-o" "[[HOST_BASE_NAME:[a-z0-9_-]+]].ii" +// CHK-FSYCL-SAVE-TEMPS: clang{{.*}} "-include-internal-header" "[[HEADER_NAME]]"{{.*}} "-fsycl-is-host"{{.*}} "-o" "[[HOST_BASE_NAME:[a-z0-9_-]+]].ii" // CHK-FSYCL-SAVE-TEMPS: clang{{.*}} "-o" "[[HOST_BASE_NAME:.*]].bc"{{.*}} "[[HOST_BASE_NAME:[a-z0-9_-]+]].ii" // CHK-FSYCL-SAVE-TEMPS: clang{{.*}} "-o" "[[HOST_BASE_NAME:.*]].s"{{.*}} "[[HOST_BASE_NAME]].bc" // CHK-FSYCL-SAVE-TEMPS: clang{{.*}} "-o" "[[HOST_BASE_NAME:.*]].o"{{.*}} "[[HOST_BASE_NAME]].s" diff --git a/clang/test/Driver/sycl-offload.c b/clang/test/Driver/sycl-offload.c index 4a11b7022c5f7..5f60bbaa48898 100644 --- a/clang/test/Driver/sycl-offload.c +++ b/clang/test/Driver/sycl-offload.c @@ -169,7 +169,7 @@ // RUN: %clang -target x86_64-unknown-linux-gnu -fsycl --offload-new-driver -c %s -### 2>&1 \ // RUN: | FileCheck %s -check-prefix=CHK-INT-HEADER // CHK-INT-HEADER: clang{{.*}} "-fsycl-is-device"{{.*}} "-fsycl-int-header=[[INPUT1:.+\-header.+\.h]]" "-fsycl-int-footer={{.*}}" -// CHK-INT-HEADER: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} "-include" "[[INPUT1]]" "-dependency-filter" "[[INPUT1]]" +// CHK-INT-HEADER: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} "-include-internal-header" "[[INPUT1]]" "-dependency-filter" "[[INPUT1]]" /// ########################################################################### @@ -427,7 +427,7 @@ // RUN: %clang_cl -fsycl --offload-new-driver /Fosomefile.obj -c %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=FO-CHECK %s // FO-CHECK: clang{{.*}} "-fsycl-int-header=[[HEADER:.+\.h]]" "-fsycl-int-footer={{.*}}" -// FO-CHECK: clang{{.*}} "-include" "[[HEADER]]" {{.*}} "-o" "somefile.obj" +// FO-CHECK: clang{{.*}} "-include-internal-header" "[[HEADER]]" {{.*}} "-o" "somefile.obj" /// passing of a library should not trigger the unbundler // RUN: touch %t.a diff --git a/clang/test/Driver/sycl-preprocess-old-model.cpp b/clang/test/Driver/sycl-preprocess-old-model.cpp index 48817c8ba58e3..446731cda3bfe 100644 --- a/clang/test/Driver/sycl-preprocess-old-model.cpp +++ b/clang/test/Driver/sycl-preprocess-old-model.cpp @@ -7,7 +7,7 @@ // RUN: | FileCheck -check-prefix PREPROC_ONLY %s // PREPROC_ONLY: clang{{.*}} "-fsycl-is-device"{{.*}} "-E"{{.*}} "-o" "[[DEVICE_OUT:.+\.ii]]" // PREPROC_ONLY: clang{{.*}} "-fsycl-is-device"{{.*}} "-fsycl-int-header=[[INTHEADER:.+\.h]]" "-fsycl-int-footer=[[INTFOOTER:.+\.h]]"{{.*}} "-fsyntax-only" -// PREPROC_ONLY: clang{{.*}} "-include" "[[INTHEADER]]"{{.*}} "-include-footer" "[[INTFOOTER]]"{{.*}} "-fsycl-is-host"{{.*}} "-o" "[[HOST_OUT:.+\.ii]]" +// PREPROC_ONLY: clang{{.*}} "-include-internal-header" "[[INTHEADER]]"{{.*}} "-include-internal-footer" "[[INTFOOTER]]"{{.*}} "-fsycl-is-host"{{.*}} "-o" "[[HOST_OUT:.+\.ii]]" /// When compiling from preprocessed file, no integration header is expected // RUN: touch %t.ii diff --git a/clang/test/Driver/sycl-preprocess.cpp b/clang/test/Driver/sycl-preprocess.cpp index 4ffc60c8dbaa4..e8975e7370387 100644 --- a/clang/test/Driver/sycl-preprocess.cpp +++ b/clang/test/Driver/sycl-preprocess.cpp @@ -6,7 +6,7 @@ // RUN: %clang_cl -fsycl --offload-new-driver -P -Fi%t_output.ii %s -### 2>&1 \ // RUN: | FileCheck -check-prefix PREPROC_ONLY %s // PREPROC_ONLY: clang{{.*}} "-fsycl-is-device"{{.*}} "-fsycl-int-header=[[INTHEADER:.+\.h]]" "-fsycl-int-footer=[[INTFOOTER:.+\.h]]"{{.*}} "-E" -// PREPROC_ONLY: clang{{.*}} "-include" "[[INTHEADER]]"{{.*}} "-include-footer" "[[INTFOOTER]]"{{.*}} "-fsycl-is-host"{{.*}} "-o" "[[HOST_OUT:.+\.ii]]" +// PREPROC_ONLY: clang{{.*}} "-include-internal-header" "[[INTHEADER]]"{{.*}} "-include-internal-footer" "[[INTFOOTER]]"{{.*}} "-fsycl-is-host"{{.*}} "-o" "[[HOST_OUT:.+\.ii]]" /// When compiling from preprocessed file, no integration header is expected // RUN: touch %t.ii diff --git a/clang/test/Preprocessor/sycl-int-footer.cpp b/clang/test/Preprocessor/sycl-int-footer.cpp index 8c6f07a1556fe..935915e64e63c 100644 --- a/clang/test/Preprocessor/sycl-int-footer.cpp +++ b/clang/test/Preprocessor/sycl-int-footer.cpp @@ -2,45 +2,23 @@ // file. // RUN: %clang_cc1 -E -fsycl-is-host %S/Inputs/checkfooter1.cpp \ -// RUN: -include %S/Inputs/file1.h -include-footer %S/Inputs/file2.h \ +// RUN: -include-internal-header %S/Inputs/file1.h \ +// RUN: -include-internal-footer %S/Inputs/file2.h \ // RUN: | FileCheck %s -check-prefix CHECKFOOTER1 // RUN: %clang_cc1 -E -fsycl-is-host %S/Inputs/checkfooter2.cpp \ -// RUN: -include %S/Inputs/header.h -include-footer %S/Inputs/footer.h \ +// RUN: -include-internal-header %S/Inputs/header.h \ +// RUN: -include-internal-footer %S/Inputs/footer.h \ // RUN: | FileCheck %s -check-prefix CHECKFOOTER2 // CHECKFOOTER1: # 1 "[[INPUTFILE1:.+\.cpp]]" -// CHECKFOOTER1: # 1 "[[INTHEADER1:.+\.h]]" 1 -// CHECKFOOTER1: int file1() { -// CHECKFOOTER1: return 1; -// CHECKFOOTER1: } -// CHECKFOOTER1: # 1 "[[INPUTFILE2:.+\.cpp]]" 2 -// CHECKFOOTER1-NEXT: int main() { -// CHECKFOOTER1-NEXT: int i = 0; -// CHECKFOOTER1-NEXT: return i++; -// CHECKFOOTER1-NEXT: } -// CHECKFOOTER1: # 1 "[[INTFOOTER1:.+\.h]]" 1 -// CHECKFOOTER1-NEXT: int file2() { -// CHECKFOOTER1-NEXT: return 2; -// CHECKFOOTER1-NEXT: } +// CHECKFOOTER1: int main() { +// CHECKFOOTER1: int i = 0; +// CHECKFOOTER1: return i++; +// CHECKFOOTER1:} // CHECKFOOTER2: # 1 "[[INPUTFILE_CF2:.+\.cpp]]" -// CHECKFOOTER2: # 1 "[[INTHEADER:.+\.h]]" 1 -// CHECKFOOTER2-NEXT: # 1 "[[INTHEADER3:.+\.h]]" 1 -// CHECKFOOTER2-NEXT: # 1 "[[INTHEADER4:.+\.h]]" 1 -// CHECKFOOTER2: void foo3(); -// CHECKFOOTER2-NEXT: # 2 "[[INTHEADER3]]" 2 -// CHECKFOOTER2: int bar(int size); -// CHECKFOOTER2: # 2 "[[INTHEADER2:.+\.h]]" 2 -// CHECKFOOTER2: void foo() { -// CHECKFOOTER2-NEXT: bar(22); -// CHECKFOOTER2-NEXT: } // CHECKFOOTER2: # 1 "[[INPUTFILE_CF2:.+\.cpp]]" // CHECKFOOTER2-NEXT: int main() { // CHECKFOOTER2-NEXT: foo(); // CHECKFOOTER2-NEXT: } -// CHECKFOOTER2: # 1 "[[INTFOOTER2:.+\.h]]" 1 -// CHECKFOOTER2-NEXT: # 1 "[[INTFOOTER3:.+\.h]]" 1 -// CHECKFOOTER2: # 2 "[[INTFOOTER2]]" 2 -// CHECKFOOTER2: void foo2(void); -// CHECKFOOTER2: # 4 "[[INPUTFILE_CF2]]" 2 diff --git a/llvm/include/llvm/Support/Path.h b/llvm/include/llvm/Support/Path.h index ce69f32b6cc81..56913437221a7 100644 --- a/llvm/include/llvm/Support/Path.h +++ b/llvm/include/llvm/Support/Path.h @@ -201,6 +201,12 @@ bool replace_path_prefix(SmallVectorImpl &Path, StringRef OldPrefix, /// @result The cleaned-up \a path. StringRef remove_leading_dotslash(StringRef path, Style style = Style::native); +/// Remove redundant leading ".\\" pieces and consecutive separators. +/// +/// @param path Input path. +/// @result The cleaned-up \a path. +StringRef remove_leading_dotbackslash_only(StringRef path); + /// In-place remove any './' and optionally '../' components from a path. /// /// @param path processed path diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp index 4db9bc80b415b..40eb60eddfaa4 100644 --- a/llvm/lib/Support/Path.cpp +++ b/llvm/lib/Support/Path.cpp @@ -711,6 +711,13 @@ StringRef remove_leading_dotslash(StringRef Path, Style style) { return Path; } +StringRef remove_leading_dotbackslash_only(StringRef Path) { + // Remove leading ".\\". + if (Path.size() > 2 && Path[0] == '.' && Path[1] == '\\') + Path = Path.substr(2); + return Path; +} + // Remove path traversal components ("." and "..") when possible, and // canonicalize slashes. bool remove_dots(SmallVectorImpl &the_path, bool remove_dot_dot,