Skip to content

[HLSL] Change clang Driver Options to not set CXXOperatorNames #126758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 12, 2025

Conversation

farzonl
Copy link
Member

@farzonl farzonl commented Feb 11, 2025

  • Disable CXXOperatorNames for HLSL
  • Add tests to confirm we can use the alt names as functions

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like the wrong place to put this test. We don't need actual codegen here, we just need to make sure it parses.

I'd put this under SemaHLSL and instead use a run line like:

// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library %s -ast-dump | FileCheck %s

Restricting test cases to only running the parts of the compiler that are strictly required to verify correctness of a change reduces the time it takes to run the test. While in isolation for a single test that may only be shaving off fractions of a second, in aggregate across the entire test suite it can have a huge impact.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it ok to keep the tests as check-label? Tests are still passing with Label? Or should this change to // CHECK: FunctionDecl {{.*}} NAME void () Which is how it seems other tests are setup.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CHECK-LABEL doesn't actually change how the matching is performed (see: https://llvm.org/docs/CommandGuide/FileCheck.html#the-check-label-directive). Notably:

It is treated identically to a normal CHECK directive except that FileCheck makes an additional assumption that a line matched by the directive cannot also be matched by any other check present in match-filename;...

Whether you use CHECK or CHECK-LABEL here doesn't really matter, but the strings you are matching on are too simple, you should be verifying that they are FunctionDecls not just that the string and appears on a line.

@llvmbot llvmbot added clang Clang issues not falling into any other category HLSL HLSL Language Support labels Feb 11, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 11, 2025

@llvm/pr-subscribers-hlsl

@llvm/pr-subscribers-clang

Author: Farzon Lotfi (farzonl)

Changes
  • Disable CXXOperatorNames for HLSL
  • Add tests to confirm we can use the alt names as functions

Full diff: https://github.com/llvm/llvm-project/pull/126758.diff

2 Files Affected:

  • (modified) clang/include/clang/Driver/Options.td (+1-1)
  • (added) clang/test/CodeGenHLSL/use-cxx-alt-operator-names.hlsl (+41)
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 1cf62ab46613456..618815db2843404 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3397,7 +3397,7 @@ def fno_objc_weak : Flag<["-"], "fno-objc-weak">, Group<f_Group>,
 def fno_omit_frame_pointer : Flag<["-"], "fno-omit-frame-pointer">, Group<f_Group>,
   Visibility<[ClangOption, FlangOption]>;
 defm operator_names : BoolFOption<"operator-names",
-  LangOpts<"CXXOperatorNames">, Default<cplusplus.KeyPath>,
+  LangOpts<"CXXOperatorNames">, Default<!strconcat(cplusplus.KeyPath, " && !",hlsl.KeyPath)>,
   NegFlag<SetFalse, [], [ClangOption, CC1Option],
           "Do not treat C++ operator name keywords as synonyms for operators">,
   PosFlag<SetTrue>>;
diff --git a/clang/test/CodeGenHLSL/use-cxx-alt-operator-names.hlsl b/clang/test/CodeGenHLSL/use-cxx-alt-operator-names.hlsl
new file mode 100644
index 000000000000000..8ae253a9f3c06cb
--- /dev/null
+++ b/clang/test/CodeGenHLSL/use-cxx-alt-operator-names.hlsl
@@ -0,0 +1,41 @@
+
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s  \
+// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s
+
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
+// RUN: spirv-unknown-vulkan-compute %s \
+// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s
+
+// CHECK-LABEL: and
+void and() {}
+
+// CHECK-LABEL: and_eq
+void and_eq() {}
+
+// CHECK-LABEL: bitand
+void bitand() {}
+
+// CHECK-LABEL: bitor
+void bitor() {}
+
+// CHECK-LABEL: compl
+void compl() {}
+
+// CHECK-LABEL: not
+void not() {}
+
+// CHECK-LABEL: not_eq
+void not_eq() {}
+
+// CHECK-LABEL: or
+void or() {}
+
+// CHECK-LABEL: or_eq
+void or_eq() {}
+
+// CHECK-LABEL: xor
+void xor() {}
+
+// CHECK-LABEL: xor_eq
+void xor_eq() {}

Copy link
Contributor

@V-FEXrt V-FEXrt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@farzonl farzonl merged commit 767b15f into llvm:main Feb 12, 2025
8 checks passed
@farzonl farzonl deleted the hlsl-disable-alt-operator-names branch February 12, 2025 14:21
@llvm-ci
Copy link
Collaborator

llvm-ci commented Feb 12, 2025

LLVM Buildbot has detected a new failure on builder flang-aarch64-out-of-tree running on linaro-flang-aarch64-out-of-tree while building clang at step 7 "build-flang-unified-tree".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/53/builds/12221

Here is the relevant piece of the build log for the reference
Step 7 (build-flang-unified-tree) failure: build (failure)
...
1034.131 [26/35/15] Linking CXX executable unittests/Evaluate/logical.test
1034.204 [26/34/16] Linking CXX executable unittests/Evaluate/real.test
1034.456 [26/33/17] Linking CXX executable unittests/Evaluate/expression.test
1038.603 [26/32/18] Linking CXX executable unittests/Evaluate/intrinsics.test
1038.640 [26/31/19] Linking CXX executable unittests/Evaluate/folding.test
1057.584 [26/30/20] Building CXX object lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/SimplifyRegionLite.cpp.o
1059.523 [26/29/21] Building CXX object lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/ExternalNameConversion.cpp.o
1059.548 [26/28/22] Building CXX object lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/StackReclaim.cpp.o
1059.938 [26/27/23] Building CXX object lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/MemRefDataFlowOpt.cpp.o
1060.246 [26/26/24] Building CXX object lib/Optimizer/Passes/CMakeFiles/flangPasses.dir/Pipelines.cpp.o
FAILED: lib/Optimizer/Passes/CMakeFiles/flangPasses.dir/Pipelines.cpp.o 
/usr/local/bin/c++ -DFLANG_INCLUDE_TESTS=1 -DFLANG_LITTLE_ENDIAN=1 -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/tcwg-buildbot/worker/flang-aarch64-out-of-tree/build_flang/lib/Optimizer/Passes -I/home/tcwg-buildbot/worker/flang-aarch64-out-of-tree/llvm-project/flang/lib/Optimizer/Passes -I/home/tcwg-buildbot/worker/flang-aarch64-out-of-tree/llvm-project/flang/include -I/home/tcwg-buildbot/worker/flang-aarch64-out-of-tree/build_flang/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-out-of-tree/llvm-project/mlir/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-out-of-tree/build_llvm/tools/mlir/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-out-of-tree/llvm-project/llvm/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-out-of-tree/build_llvm/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-out-of-tree/llvm-project/clang/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-out-of-tree/build_llvm/tools/clang/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Werror -Wno-deprecated-copy -Wno-string-conversion -Wno-ctad-maybe-unsupported -Wno-unused-command-line-argument -Wstring-conversion           -Wcovered-switch-default -Wno-nested-anon-types -O3 -DNDEBUG -std=c++17   -D_GNU_SOURCE -D_DEBUG -D_GLIBCXX_ASSERTIONS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT lib/Optimizer/Passes/CMakeFiles/flangPasses.dir/Pipelines.cpp.o -MF lib/Optimizer/Passes/CMakeFiles/flangPasses.dir/Pipelines.cpp.o.d -o lib/Optimizer/Passes/CMakeFiles/flangPasses.dir/Pipelines.cpp.o -c /home/tcwg-buildbot/worker/flang-aarch64-out-of-tree/llvm-project/flang/lib/Optimizer/Passes/Pipelines.cpp
../llvm-project/flang/lib/Optimizer/Passes/Pipelines.cpp:329:27: error: missing field 'tuneCPU' initializer [-Werror,-Wmissing-field-initializers]
  329 |        config.UnsafeFPMath}));
      |                           ^
1 error generated.
1060.503 [26/25/25] Building CXX object lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/CharacterConversion.cpp.o
1060.515 [26/24/26] Building CXX object lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/VScaleAttr.cpp.o
1061.107 [26/23/27] Building CXX object lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/CompilerGeneratedNames.cpp.o
1061.215 [26/22/28] Building CXX object lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/FunctionAttr.cpp.o
1062.154 [26/21/29] Building CXX object lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/AlgebraicSimplification.cpp.o
1062.971 [26/20/30] Building CXX object lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/LoopVersioning.cpp.o
1064.891 [26/19/31] Building CXX object lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/AnnotateConstant.cpp.o
1065.574 [26/18/32] Building CXX object lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/ControlFlowConverter.cpp.o
1065.603 [26/17/33] Building CXX object lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/MemoryAllocation.cpp.o
1065.670 [26/16/34] Building CXX object lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/AssumedRankOpConversion.cpp.o
1065.910 [26/15/35] Building CXX object lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/AffinePromotion.cpp.o
1065.966 [26/14/36] Building CXX object lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/AddAliasTags.cpp.o
1068.371 [26/13/37] Building CXX object lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/ConstantArgumentGlobalisation.cpp.o
1069.630 [26/12/38] Building CXX object lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/AffineDemotion.cpp.o
1070.104 [26/11/39] Building CXX object lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/AddDebugInfo.cpp.o
1070.182 [26/10/40] Building CXX object lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/AbstractResult.cpp.o
1072.016 [26/9/41] Building CXX object lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/SimplifyIntrinsics.cpp.o
1072.879 [26/8/42] Building CXX object lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/StackArrays.cpp.o
1072.950 [26/7/43] Building CXX object lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/ArrayValueCopy.cpp.o
1123.307 [26/6/44] Building CXX object lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/PolymorphicOpConversion.cpp.o
1128.408 [26/5/45] Building CXX object tools/tco/CMakeFiles/tco.dir/tco.cpp.o
1129.606 [26/4/46] Building CXX object tools/fir-opt/CMakeFiles/fir-opt.dir/fir-opt.cpp.o
1142.382 [26/3/47] Building CXX object tools/flang-driver/CMakeFiles/flang.dir/driver.cpp.o
1156.624 [26/2/48] Building CXX object lib/FrontendTool/CMakeFiles/flangFrontendTool.dir/ExecuteCompilerInvocation.cpp.o
1259.294 [26/1/49] Building CXX object tools/bbc/CMakeFiles/bbc.dir/bbc.cpp.o
ninja: build stopped: subcommand failed.

flovent pushed a commit to flovent/llvm-project that referenced this pull request Feb 13, 2025
…126758)

- Disable `CXXOperatorNames` for HLSL
- Add tests to confirm we can use the alt names as functions
joaosaffran pushed a commit to joaosaffran/llvm-project that referenced this pull request Feb 14, 2025
…126758)

- Disable `CXXOperatorNames` for HLSL
- Add tests to confirm we can use the alt names as functions
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Feb 24, 2025
…126758)

- Disable `CXXOperatorNames` for HLSL
- Add tests to confirm we can use the alt names as functions
@damyanp damyanp moved this to Closed in HLSL Support Apr 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category HLSL HLSL Language Support
Projects
Status: Closed
Development

Successfully merging this pull request may close these issues.

5 participants