[clang] 140b0bf - [HLSL] Set main as default entry.

Xiang Li via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 18 11:57:42 PDT 2022


Author: Xiang Li
Date: 2022-08-18T11:57:36-07:00
New Revision: 140b0bf89902845be14a4a710289bee49e0d1fc5

URL: https://github.com/llvm/llvm-project/commit/140b0bf89902845be14a4a710289bee49e0d1fc5
DIFF: https://github.com/llvm/llvm-project/commit/140b0bf89902845be14a4a710289bee49e0d1fc5.diff

LOG: [HLSL] Set main as default entry.

When there's no -E option, use main as entry function.

Reviewed By: beanz

Differential Revision: https://reviews.llvm.org/D124753

Added: 
    

Modified: 
    clang/include/clang/Driver/Options.td
    clang/unittests/Driver/ToolChainTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 7c91b91eeddf4..a5dfeec4fd463 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6919,7 +6919,7 @@ def enable_16bit_types : DXCFlag<"enable-16bit-types">, Alias<fnative_half_type>
 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>,

diff  --git a/clang/unittests/Driver/ToolChainTest.cpp b/clang/unittests/Driver/ToolChainTest.cpp
index 64bc616523f05..e1c4e4eb2f55b 100644
--- a/clang/unittests/Driver/ToolChainTest.cpp
+++ b/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 @@ TEST(DxcModeTest, ValidatorVersionValidation) {
   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());


        


More information about the cfe-commits mailing list