[PATCH] D124753: [HLSL] Set main as default entry.

Xiang Li via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 18 11:54:29 PDT 2022


python3kgae updated this revision to Diff 453747.
python3kgae added a comment.

Update to work around arc error when land.


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
@@ -6914,7 +6914,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>,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124753.453747.patch
Type: text/x-patch
Size: 2538 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220818/c7f6fbb2/attachment-0001.bin>


More information about the cfe-commits mailing list