[clang] [HLSL] Implement 202x conforming literals (PR #91015)
https://github.com/llvm-beanz closed https://github.com/llvm/llvm-project/pull/91015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implement 202x conforming literals (PR #91015)
https://github.com/sudonatalie approved this pull request. https://github.com/llvm/llvm-project/pull/91015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implement 202x conforming literals (PR #91015)
https://github.com/damyanp approved this pull request. https://github.com/llvm/llvm-project/pull/91015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implement 202x conforming literals (PR #91015)
llvmbot wrote: @llvm/pr-subscribers-hlsl Author: Chris B (llvm-beanz) Changes This implements the HLSL 202x conforming literals feature. The feature proposal is available here: https://github.com/microsoft/hlsl-specs/blob/main/proposals/0017-conforming-literals.md The language specification for this behavior is available in (poorly rendered) HTML or PDF: https://microsoft.github.io/hlsl-specs/specs/hlsl.html#Lex.Literal.Float https://microsoft.github.io/hlsl-specs/specs/hlsl.pdf The main implementation details are: 1) Unsuffixed floating literals are `float`. 2) The integer `ll` suffix specifies `int64_t (aka long)` which is 64-bit because HLSL has no defined `long` keyword or `long long` type. Resolves #85714 --- Patch is 27.07 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/91015.diff 7 Files Affected: - (modified) clang/lib/Sema/SemaExpr.cpp (+11) - (modified) clang/test/AST/HLSL/vector-constructors.hlsl (+62-73) - (modified) clang/test/CodeGenHLSL/builtins/ScalarSwizzles.hlsl (+14-3) - (renamed) clang/test/SemaHLSL/Types/Arithmetic/literal_suffixes.hlsl (+1-4) - (added) clang/test/SemaHLSL/Types/Arithmetic/literal_suffixes_202x.hlsl (+115) - (renamed) clang/test/SemaHLSL/Types/Arithmetic/literal_suffixes_no_16bit.hlsl (+1-4) - (modified) clang/test/SemaHLSL/Types/BuiltinVector/ScalarSwizzles.hlsl (+11-2) ``diff diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 7190e50b156f7b..5b42cf65cf80ff 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -4103,6 +4103,8 @@ ExprResult Sema::ActOnNumericConstant(const Token &Tok, Scope *UDLScope) { Ty = Context.Float16Ty; else if (Literal.isFloat128) Ty = Context.Float128Ty; +else if (getLangOpts().HLSL) + Ty = Context.FloatTy; else Ty = Context.DoubleTy; @@ -4173,6 +4175,15 @@ ExprResult Sema::ActOnNumericConstant(const Token &Tok, Scope *UDLScope) { // be an unsigned int. bool AllowUnsigned = Literal.isUnsigned || Literal.getRadix() != 10; + // HLSL doesn't really have `long` or `long long`. We support the `ll` + // suffix for portability of code with C++, but both `l` and `ll` are + // 64-bit integer types, and we want the type of `1l` and `1ll` to be the + // same. + if (getLangOpts().HLSL && !Literal.isLong && Literal.isLongLong) { +Literal.isLong = true; +Literal.isLongLong = false; + } + // Check from smallest to largest, picking the smallest type we can. unsigned Width = 0; diff --git a/clang/test/AST/HLSL/vector-constructors.hlsl b/clang/test/AST/HLSL/vector-constructors.hlsl index 7861d5209b5d3e..5e0900bb623693 100644 --- a/clang/test/AST/HLSL/vector-constructors.hlsl +++ b/clang/test/AST/HLSL/vector-constructors.hlsl @@ -1,4 +1,4 @@ -// 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 -x hlsl -ast-dump -o - %s | FileCheck %s typedef float float2 __attribute__((ext_vector_type(2))); typedef float float3 __attribute__((ext_vector_type(3))); @@ -11,41 +11,36 @@ void entry() { // For the float2 vector, we just expect a conversion from constructor // parameters to an initialization list -// CHECK: VarDecl 0x{{[0-9a-fA-F]+}} col:10 used Vec2 'float2':'float __attribute__((ext_vector_type(2)))' cinit -// CHECK-NEXT: CXXFunctionalCastExpr 0x{{[0-9a-fA-F]+}} 'float2':'float __attribute__((ext_vector_type(2)))' functional cast to float2 -// CHECK-NEXT: InitListExpr 0x{{[0-9a-fA-F]+}} 'float2':'float __attribute__((ext_vector_type(2)))' -// CHECK-NEXT: ImplicitCastExpr 0x{{[0-9a-fA-F]+}} 'float' -// CHECK-NEXT: FloatingLiteral 0x{{[0-9a-fA-F]+}} 'double' 1.00e+00 -// CHECK-NEXT: ImplicitCastExpr 0x{{[0-9a-fA-F]+}} 'float' -// CHECK-NEXT: FloatingLiteral 0x{{[0-9a-fA-F]+}} 'double' 2.00e+00 +// CHECK-LABEL: VarDecl 0x{{[0-9a-fA-F]+}} {{.*}} used Vec2 'float2':'float __attribute__((ext_vector_type(2)))' cinit +// CHECK-NEXT: CXXFunctionalCastExpr 0x{{[0-9a-fA-F]+}} {{.*}} 'float2':'float __attribute__((ext_vector_type(2)))' functional cast to float2 +// CHECK-NEXT: InitListExpr 0x{{[0-9a-fA-F]+}} {{.*}} 'float2':'float __attribute__((ext_vector_type(2)))' +// CHECK-NEXT: FloatingLiteral 0x{{[0-9a-fA-F]+}} {{.*}} 'float' 1.00e+00 +// CHECK-NEXT: FloatingLiteral 0x{{[0-9a-fA-F]+}} {{.*}} 'float' 2.00e+00 // For the float 3 things get fun... // Here we expect accesses to the vec2 to provide the first and second // components using ArraySubscriptExpr -// CHECK: VarDecl 0x{{[0-9a-fA-F]+}} col:10 Vec3 'float3':'float __attribute__((ext_vector_type(3)))' cinit -// CHECK-NEXT: CXXFunctionalCastExpr 0x{{[0-9a-fA-F]+}} 'float3':'float __attribute__((ext_vector_type(3)))' functional cast to float3 -// CHECK-NEXT: InitListExpr 0x{{[0-9a-fA-F]+}} 'float3':'flo
[clang] [HLSL] Implement 202x conforming literals (PR #91015)
https://github.com/llvm-beanz edited https://github.com/llvm/llvm-project/pull/91015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implement 202x conforming literals (PR #91015)
https://github.com/llvm-beanz edited https://github.com/llvm/llvm-project/pull/91015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implement 202x conforming literals (PR #91015)
https://github.com/llvm-beanz created https://github.com/llvm/llvm-project/pull/91015 This implements the HLSL 202x conforming literals feature. The feature proposal is available here: https://github.com/microsoft/hlsl-specs/blob/main/proposals/0017-conform ing-literals.md The language specification for this behavior is available in (poorly rendered) HTML or PDF: https://microsoft.github.io/hlsl-specs/specs/hlsl.html#Lex.Literal.Float https://microsoft.github.io/hlsl-specs/specs/hlsl.pdf The main implementation details are: 1) Unsuffixed floating literals are `float`. 2) The integer `ll` suffix specifies `int64_t (aka long)` which is 64-bit because HLSL has no defined `long` keyword or `long long` type. Resolves #85714 >From 4511cd525a671e8c7ceec9ffc653b351d9b1a4d8 Mon Sep 17 00:00:00 2001 From: Chris Bieneman Date: Wed, 1 May 2024 14:10:58 -0500 Subject: [PATCH] [HLSL] Implement 202x conforming literals This implements the HLSL 202x conforming literals feature. The feature proposal is available here: https://github.com/microsoft/hlsl-specs/blob/main/proposals/0017-conform ing-literals.md The language specification for this behavior is available in (poorly rendered) HTML or PDF: https://microsoft.github.io/hlsl-specs/specs/hlsl.html#Lex.Literal.Float https://microsoft.github.io/hlsl-specs/specs/hlsl.pdf The main implementation details are: 1) Unsuffixed floating literals are `float`. 2) The integer `ll` suffix specifies `int64_t (aka long)` which is 64-bit because HLSL has no defined `long` keyword or `long long` type. Resolves #85714 --- clang/lib/Sema/SemaExpr.cpp | 11 ++ clang/test/AST/HLSL/vector-constructors.hlsl | 135 -- .../CodeGenHLSL/builtins/ScalarSwizzles.hlsl | 17 ++- .../Arithmetic}/literal_suffixes.hlsl | 5 +- .../Arithmetic/literal_suffixes_202x.hlsl | 115 +++ .../literal_suffixes_no_16bit.hlsl| 5 +- .../Types/BuiltinVector/ScalarSwizzles.hlsl | 13 +- 7 files changed, 215 insertions(+), 86 deletions(-) rename clang/test/SemaHLSL/{ => Types/Arithmetic}/literal_suffixes.hlsl (87%) create mode 100644 clang/test/SemaHLSL/Types/Arithmetic/literal_suffixes_202x.hlsl rename clang/test/SemaHLSL/{ => Types/Arithmetic}/literal_suffixes_no_16bit.hlsl (86%) diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 7190e50b156f7b..5b42cf65cf80ff 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -4103,6 +4103,8 @@ ExprResult Sema::ActOnNumericConstant(const Token &Tok, Scope *UDLScope) { Ty = Context.Float16Ty; else if (Literal.isFloat128) Ty = Context.Float128Ty; +else if (getLangOpts().HLSL) + Ty = Context.FloatTy; else Ty = Context.DoubleTy; @@ -4173,6 +4175,15 @@ ExprResult Sema::ActOnNumericConstant(const Token &Tok, Scope *UDLScope) { // be an unsigned int. bool AllowUnsigned = Literal.isUnsigned || Literal.getRadix() != 10; + // HLSL doesn't really have `long` or `long long`. We support the `ll` + // suffix for portability of code with C++, but both `l` and `ll` are + // 64-bit integer types, and we want the type of `1l` and `1ll` to be the + // same. + if (getLangOpts().HLSL && !Literal.isLong && Literal.isLongLong) { +Literal.isLong = true; +Literal.isLongLong = false; + } + // Check from smallest to largest, picking the smallest type we can. unsigned Width = 0; diff --git a/clang/test/AST/HLSL/vector-constructors.hlsl b/clang/test/AST/HLSL/vector-constructors.hlsl index 7861d5209b5d3e..5e0900bb623693 100644 --- a/clang/test/AST/HLSL/vector-constructors.hlsl +++ b/clang/test/AST/HLSL/vector-constructors.hlsl @@ -1,4 +1,4 @@ -// 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 -x hlsl -ast-dump -o - %s | FileCheck %s typedef float float2 __attribute__((ext_vector_type(2))); typedef float float3 __attribute__((ext_vector_type(3))); @@ -11,41 +11,36 @@ void entry() { // For the float2 vector, we just expect a conversion from constructor // parameters to an initialization list -// CHECK: VarDecl 0x{{[0-9a-fA-F]+}} col:10 used Vec2 'float2':'float __attribute__((ext_vector_type(2)))' cinit -// CHECK-NEXT: CXXFunctionalCastExpr 0x{{[0-9a-fA-F]+}} 'float2':'float __attribute__((ext_vector_type(2)))' functional cast to float2 -// CHECK-NEXT: InitListExpr 0x{{[0-9a-fA-F]+}} 'float2':'float __attribute__((ext_vector_type(2)))' -// CHECK-NEXT: ImplicitCastExpr 0x{{[0-9a-fA-F]+}} 'float' -// CHECK-NEXT: FloatingLiteral 0x{{[0-9a-fA-F]+}} 'double' 1.00e+00 -// CHECK-NEXT: ImplicitCastExpr 0x{{[0-9a-fA-F]+}} 'float' -// CHECK-NEXT: FloatingLiteral 0x{{[0-9a-fA-F]+}} 'double' 2.00e+00 +// CHECK-LABEL: VarDecl 0x{{[0-9a-fA-F]+}} {{.*}} used Vec2 'float2':'float __attribute__((ext_vector_type(2