Skip to content

[HLSL] Allow narrowing in initialization lists #108035

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 1 commit into from
Sep 12, 2024

Conversation

llvm-beanz
Copy link
Collaborator

HLSL's initialization lists are extremely generous about allowing conversions. This change demotes the C++11 warning to the legacy warning when in HLSL mode.

Required for #56067

HLSL's initialization lists are _extremely_ generous about allowing
conversions. This change demotes the C++11 warning to the legacy
warning when in HLSL mode.

Required for llvm#56067
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" HLSL HLSL Language Support labels Sep 10, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 10, 2024

@llvm/pr-subscribers-hlsl

@llvm/pr-subscribers-clang

Author: Chris B (llvm-beanz)

Changes

HLSL's initialization lists are extremely generous about allowing conversions. This change demotes the C++11 warning to the legacy warning when in HLSL mode.

Required for #56067


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

2 Files Affected:

  • (modified) clang/lib/Sema/SemaInit.cpp (+1-1)
  • (modified) clang/test/AST/HLSL/vector-constructors.hlsl (+2-1)
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 7dc17187524621..8a32114a1ab313 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -9537,7 +9537,7 @@ static void DiagnoseNarrowingInInitList(Sema &S,
                       unsigned ConstRefDiagID, unsigned WarnDiagID) {
     unsigned DiagID;
     auto &L = S.getLangOpts();
-    if (L.CPlusPlus11 &&
+    if (L.CPlusPlus11 && !L.HLSL &&
         (!L.MicrosoftExt || L.isCompatibleWithMSVC(LangOptions::MSVC2015)))
       DiagID = IsConstRef ? ConstRefDiagID : DefaultDiagID;
     else
diff --git a/clang/test/AST/HLSL/vector-constructors.hlsl b/clang/test/AST/HLSL/vector-constructors.hlsl
index 905f11d9223248..9161ad110df1f1 100644
--- a/clang/test/AST/HLSL/vector-constructors.hlsl
+++ b/clang/test/AST/HLSL/vector-constructors.hlsl
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -ast-dump -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -ast-dump -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -std=hlsl202x -ast-dump -o - %s | FileCheck %s
 
 typedef float float2 __attribute__((ext_vector_type(2)));
 typedef float float3 __attribute__((ext_vector_type(3)));

@bogner
Copy link
Contributor

bogner commented Sep 10, 2024

Can we test this?

@llvm-beanz
Copy link
Collaborator Author

Can we test this?

It is tested. The modified test case adds a run line with -std=hlsl202x which fails without this change due to narrowing conversion in an initializer list.

Copy link
Contributor

@coopp coopp left a comment

Choose a reason for hiding this comment

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

looks fine. Curious, why is this extra RUN: line added? Doesn't the other one already contain the same parameters -ast-dump -o - %s | FileCheck %s ?

RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -ast-dump -o - %s | FileCheck %s

@llvm-beanz
Copy link
Collaborator Author

looks fine. Curious, why is this extra RUN: line added? Doesn't the other one already contain the same parameters -ast-dump -o - %s | FileCheck %s ?

RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -ast-dump -o - %s | FileCheck %s

The diff is a bit awkward to read, but the second run line adds -std=hlsl202x to explicitly run under 202x, which (before this change) treated narrowing conversion in initializer lists as an error.

@llvm-beanz llvm-beanz merged commit 6eb3519 into llvm:main Sep 12, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category HLSL HLSL Language Support
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants