diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp b/clang/lib/Driver/ToolChains/HLSL.cpp --- a/clang/lib/Driver/ToolChains/HLSL.cpp +++ b/clang/lib/Driver/ToolChains/HLSL.cpp @@ -188,5 +188,11 @@ Opts.getOption(options::OPT_dxil_validator_version), DefaultValidatorVer); } + // If entry is not set explicitly, default is main. + if (!DAL->hasArg(options::OPT_hlsl_entrypoint)) { + const StringRef DefaultEntry = "main"; + DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_hlsl_entrypoint), + DefaultEntry); + } return DAL; } diff --git a/clang/test/CodeGenHLSL/entry_default.hlsl b/clang/test/CodeGenHLSL/entry_default.hlsl new file mode 100644 --- /dev/null +++ b/clang/test/CodeGenHLSL/entry_default.hlsl @@ -0,0 +1,10 @@ +// RUN: %clang --driver-mode=dxc -Tcs_6_1 -fcgl -Fo - %s | FileCheck %s + +// Make sure main is default entry. +// Make sure not mangle entry. +// CHECK:define void @main() +// Make sure add function attribute. +// CHECK:"dx.shader"="compute" +[numthreads(1, 1, 1)] void main() { + +}