python3kgae updated this revision to Diff 450492. python3kgae marked an inline comment as done. python3kgae added a comment.
Rebase and add unit-test. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D124753/new/ https://reviews.llvm.org/D124753 Files: clang/include/clang/Driver/Options.td clang/unittests/Driver/ToolChainTest.cpp Index: clang/unittests/Driver/ToolChainTest.cpp =================================================================== --- clang/unittests/Driver/ToolChainTest.cpp +++ clang/unittests/Driver/ToolChainTest.cpp @@ -14,8 +14,10 @@ #include "clang/Basic/DiagnosticIDs.h" #include "clang/Basic/DiagnosticOptions.h" #include "clang/Basic/LLVM.h" +#include "clang/Basic/TargetOptions.h" #include "clang/Driver/Compilation.h" #include "clang/Driver/Driver.h" +#include "clang/Frontend/CompilerInstance.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/MC/TargetRegistry.h" #include "llvm/Support/Host.h" @@ -571,6 +573,33 @@ DiagConsumer->clear(); } +TEST(DxcModeTest, DefaultEntry) { + IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem( + new llvm::vfs::InMemoryFileSystem); + + InMemoryFileSystem->addFile("foo.hlsl", 0, + llvm::MemoryBuffer::getMemBuffer("\n")); + + const char *Args[] = {"clang", "--driver-mode=dxc", "-Tcs_6_7", "foo.hlsl"}; + + IntrusiveRefCntPtr<DiagnosticsEngine> Diags = + CompilerInstance::createDiagnostics(new DiagnosticOptions()); + + CreateInvocationOptions CIOpts; + CIOpts.Diags = Diags; + std::unique_ptr<CompilerInvocation> CInvok = + createInvocation(Args, std::move(CIOpts)); + EXPECT_TRUE(CInvok); + // Make sure default entry is "main". + EXPECT_STREQ(CInvok->getTargetOpts().HLSLEntry.c_str(), "main"); + + const char *EntryArgs[] = {"clang", "--driver-mode=dxc", "-Ebar", "-Tcs_6_7", "foo.hlsl"}; + CInvok = createInvocation(EntryArgs, std::move(CIOpts)); + EXPECT_TRUE(CInvok); + // Make sure "-E" will set entry. + EXPECT_STREQ(CInvok->getTargetOpts().HLSLEntry.c_str(), "bar"); +} + TEST(ToolChainTest, Toolsets) { // Ignore this test on Windows hosts. llvm::Triple Host(llvm::sys::getProcessTriple()); Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -6912,7 +6912,7 @@ def hlsl_entrypoint : Option<["-"], "hlsl-entry", KIND_SEPARATE>, Group<dxc_Group>, Flags<[CC1Option]>, - MarshallingInfoString<TargetOpts<"HLSLEntry">>, + MarshallingInfoString<TargetOpts<"HLSLEntry">, "\"main\"">, HelpText<"Entry point name for hlsl">; def dxc_entrypoint : Option<["--", "/", "-"], "E", KIND_JOINED_OR_SEPARATE>, Group<dxc_Group>,
Index: clang/unittests/Driver/ToolChainTest.cpp =================================================================== --- clang/unittests/Driver/ToolChainTest.cpp +++ clang/unittests/Driver/ToolChainTest.cpp @@ -14,8 +14,10 @@ #include "clang/Basic/DiagnosticIDs.h" #include "clang/Basic/DiagnosticOptions.h" #include "clang/Basic/LLVM.h" +#include "clang/Basic/TargetOptions.h" #include "clang/Driver/Compilation.h" #include "clang/Driver/Driver.h" +#include "clang/Frontend/CompilerInstance.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/MC/TargetRegistry.h" #include "llvm/Support/Host.h" @@ -571,6 +573,33 @@ DiagConsumer->clear(); } +TEST(DxcModeTest, DefaultEntry) { + IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem( + new llvm::vfs::InMemoryFileSystem); + + InMemoryFileSystem->addFile("foo.hlsl", 0, + llvm::MemoryBuffer::getMemBuffer("\n")); + + const char *Args[] = {"clang", "--driver-mode=dxc", "-Tcs_6_7", "foo.hlsl"}; + + IntrusiveRefCntPtr<DiagnosticsEngine> Diags = + CompilerInstance::createDiagnostics(new DiagnosticOptions()); + + CreateInvocationOptions CIOpts; + CIOpts.Diags = Diags; + std::unique_ptr<CompilerInvocation> CInvok = + createInvocation(Args, std::move(CIOpts)); + EXPECT_TRUE(CInvok); + // Make sure default entry is "main". + EXPECT_STREQ(CInvok->getTargetOpts().HLSLEntry.c_str(), "main"); + + const char *EntryArgs[] = {"clang", "--driver-mode=dxc", "-Ebar", "-Tcs_6_7", "foo.hlsl"}; + CInvok = createInvocation(EntryArgs, std::move(CIOpts)); + EXPECT_TRUE(CInvok); + // Make sure "-E" will set entry. + EXPECT_STREQ(CInvok->getTargetOpts().HLSLEntry.c_str(), "bar"); +} + TEST(ToolChainTest, Toolsets) { // Ignore this test on Windows hosts. llvm::Triple Host(llvm::sys::getProcessTriple()); Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -6912,7 +6912,7 @@ def hlsl_entrypoint : Option<["-"], "hlsl-entry", KIND_SEPARATE>, Group<dxc_Group>, Flags<[CC1Option]>, - MarshallingInfoString<TargetOpts<"HLSLEntry">>, + MarshallingInfoString<TargetOpts<"HLSLEntry">, "\"main\"">, HelpText<"Entry point name for hlsl">; def dxc_entrypoint : Option<["--", "/", "-"], "E", KIND_JOINED_OR_SEPARATE>, Group<dxc_Group>,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits