[clang] b8b036a - [HLSL] Treat `main` as any other function (#110546)

via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 1 05:36:40 PDT 2024


Author: Chris B
Date: 2024-10-01T07:36:36-05:00
New Revision: b8b036a7fe5b6e7ec306e3b80367e22d157a492b

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

LOG: [HLSL] Treat `main` as any other function (#110546)

HLSL doesn't distinguish `main` from any other function. It does treat
entry points special, but they're not required to be called `main` so we
have a different attribute annotation to mark them.

At the moment this change really just changes the mangling of functions
named `main` in the Itanium mangling.

Fixes #110517

---------

Co-authored-by: Farzon Lotfi <1802579+farzonl at users.noreply.github.com>

Added: 
    

Modified: 
    clang/lib/AST/Decl.cpp
    clang/test/CodeGenHLSL/builtins/wave_get_lane_index_do_while.hlsl
    clang/test/Options/enable_16bit_types_validation_spirv.hlsl

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index a14b1b33d35efc..84ef9f74582ef6 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -3302,6 +3302,7 @@ bool FunctionDecl::isImmediateFunction() const {
 
 bool FunctionDecl::isMain() const {
   return isNamed(this, "main") && !getLangOpts().Freestanding &&
+         !getLangOpts().HLSL &&
          (getDeclContext()->getRedeclContext()->isTranslationUnit() ||
           isExternC());
 }

diff  --git a/clang/test/CodeGenHLSL/builtins/wave_get_lane_index_do_while.hlsl b/clang/test/CodeGenHLSL/builtins/wave_get_lane_index_do_while.hlsl
index 9481b0d60a2723..6b053dc6add1f2 100644
--- a/clang/test/CodeGenHLSL/builtins/wave_get_lane_index_do_while.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/wave_get_lane_index_do_while.hlsl
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
 // RUN:   spirv-pc-vulkan-library %s -emit-llvm -disable-llvm-passes -o - | FileCheck %s
 
-// CHECK: define spir_func void @main() [[A0:#[0-9]+]] {
+// CHECK: define spir_func void @{{.*main.*}}() [[A0:#[0-9]+]] {
 void main() {
 // CHECK: entry:
 // CHECK:   %[[CT_ENTRY:[0-9]+]] = call token @llvm.experimental.convergence.entry()

diff  --git a/clang/test/Options/enable_16bit_types_validation_spirv.hlsl b/clang/test/Options/enable_16bit_types_validation_spirv.hlsl
index aeb7a8369f4034..aad8836db1062b 100644
--- a/clang/test/Options/enable_16bit_types_validation_spirv.hlsl
+++ b/clang/test/Options/enable_16bit_types_validation_spirv.hlsl
@@ -4,7 +4,7 @@
 // SPIRV: error: '-fnative-half-type' option requires target HLSL Version >= 2018, but HLSL Version is 'hlsl2016'
 
 // valid: "spirv-unknown-vulkan-library"
-// valid: define spir_func void @main() #0 {
+// valid: define spir_func void @{{.*main.*}}() #0 {
 
 [numthreads(1,1,1)]
 void main()


        


More information about the cfe-commits mailing list