Skip to content

Commit 8c32076

Browse files
authored
Merge branch 'main' into fix/100394
2 parents 31bbcd5 + 0bc02b9 commit 8c32076

File tree

94 files changed

+3100
-380
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+3100
-380
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ C++23 Feature Support
172172
- Removed the restriction to literal types in constexpr functions in C++23 mode.
173173

174174
- Extend lifetime of temporaries in mem-default-init for P2718R0. Clang now fully
175-
supported `P2718R0 Lifetime extension in range-based for loops <https://wg21.link/P2718R0>`_.
175+
supports `P2718R0 Lifetime extension in range-based for loops <https://wg21.link/P2718R0>`_.
176176

177177
C++20 Feature Support
178178
^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/Basic/Builtins.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4745,6 +4745,12 @@ def HLSLCross: LangBuiltin<"HLSL_LANG"> {
47454745
let Prototype = "void(...)";
47464746
}
47474747

4748+
def HLSLDegrees : LangBuiltin<"HLSL_LANG"> {
4749+
let Spellings = ["__builtin_hlsl_elementwise_degrees"];
4750+
let Attributes = [NoThrow, Const];
4751+
let Prototype = "void(...)";
4752+
}
4753+
47484754
def HLSLDotProduct : LangBuiltin<"HLSL_LANG"> {
47494755
let Spellings = ["__builtin_hlsl_dot"];
47504756
let Attributes = [NoThrow, Const];

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18755,6 +18755,16 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
1875518755
CGM.getHLSLRuntime().getNormalizeIntrinsic(), ArrayRef<Value *>{X},
1875618756
nullptr, "hlsl.normalize");
1875718757
}
18758+
case Builtin::BI__builtin_hlsl_elementwise_degrees: {
18759+
Value *X = EmitScalarExpr(E->getArg(0));
18760+
18761+
assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
18762+
"degree operand must have a float representation");
18763+
18764+
return Builder.CreateIntrinsic(
18765+
/*ReturnType=*/X->getType(), CGM.getHLSLRuntime().getDegreesIntrinsic(),
18766+
ArrayRef<Value *>{X}, nullptr, "hlsl.degrees");
18767+
}
1875818768
case Builtin::BI__builtin_hlsl_elementwise_frac: {
1875918769
Value *Op0 = EmitScalarExpr(E->getArg(0));
1876018770
if (!E->getArg(0)->getType()->hasFloatingRepresentation())

clang/lib/CodeGen/CGHLSLRuntime.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class CGHLSLRuntime {
7575
GENERATE_HLSL_INTRINSIC_FUNCTION(All, all)
7676
GENERATE_HLSL_INTRINSIC_FUNCTION(Any, any)
7777
GENERATE_HLSL_INTRINSIC_FUNCTION(Cross, cross)
78+
GENERATE_HLSL_INTRINSIC_FUNCTION(Degrees, degrees)
7879
GENERATE_HLSL_INTRINSIC_FUNCTION(Frac, frac)
7980
GENERATE_HLSL_INTRINSIC_FUNCTION(Length, length)
8081
GENERATE_HLSL_INTRINSIC_FUNCTION(Lerp, lerp)

clang/lib/Headers/hlsl/hlsl_intrinsics.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,36 @@ uint64_t3 countbits(uint64_t3);
766766
_HLSL_BUILTIN_ALIAS(__builtin_elementwise_popcount)
767767
uint64_t4 countbits(uint64_t4);
768768

769+
//===----------------------------------------------------------------------===//
770+
// degrees builtins
771+
//===----------------------------------------------------------------------===//
772+
773+
/// \fn T degrees(T x)
774+
/// \brief Converts the specified value from radians to degrees.
775+
/// \param x The specified input value.
776+
777+
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
778+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_degrees)
779+
half degrees(half);
780+
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
781+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_degrees)
782+
half2 degrees(half2);
783+
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
784+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_degrees)
785+
half3 degrees(half3);
786+
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
787+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_degrees)
788+
half4 degrees(half4);
789+
790+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_degrees)
791+
float degrees(float);
792+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_degrees)
793+
float2 degrees(float2);
794+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_degrees)
795+
float3 degrees(float3);
796+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_degrees)
797+
float4 degrees(float4);
798+
769799
//===----------------------------------------------------------------------===//
770800
// dot product builtins
771801
//===----------------------------------------------------------------------===//

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,6 +1896,7 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
18961896
return true;
18971897
break;
18981898
}
1899+
case Builtin::BI__builtin_hlsl_elementwise_degrees:
18991900
case Builtin::BI__builtin_hlsl_elementwise_radians:
19001901
case Builtin::BI__builtin_hlsl_elementwise_rsqrt:
19011902
case Builtin::BI__builtin_hlsl_elementwise_frac: {

clang/lib/Sema/SemaTemplateDeductionGuide.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ class ExtractTypeForDeductionGuide
7070
ExtractTypeForDeductionGuide(
7171
Sema &SemaRef,
7272
llvm::SmallVectorImpl<TypedefNameDecl *> &MaterializedTypedefs,
73-
ClassTemplateDecl *NestedPattern,
74-
const MultiLevelTemplateArgumentList *OuterInstantiationArgs)
73+
ClassTemplateDecl *NestedPattern = nullptr,
74+
const MultiLevelTemplateArgumentList *OuterInstantiationArgs = nullptr)
7575
: Base(SemaRef), MaterializedTypedefs(MaterializedTypedefs),
7676
NestedPattern(NestedPattern),
7777
OuterInstantiationArgs(OuterInstantiationArgs) {
@@ -1228,10 +1228,25 @@ FunctionTemplateDecl *DeclareAggregateDeductionGuideForTypeAlias(
12281228
getRHSTemplateDeclAndArgs(SemaRef, AliasTemplate).first;
12291229
if (!RHSTemplate)
12301230
return nullptr;
1231+
1232+
llvm::SmallVector<TypedefNameDecl *> TypedefDecls;
1233+
llvm::SmallVector<QualType> NewParamTypes;
1234+
ExtractTypeForDeductionGuide TypeAliasTransformer(SemaRef, TypedefDecls);
1235+
for (QualType P : ParamTypes) {
1236+
QualType Type = TypeAliasTransformer.TransformType(P);
1237+
if (Type.isNull())
1238+
return nullptr;
1239+
NewParamTypes.push_back(Type);
1240+
}
1241+
12311242
auto *RHSDeductionGuide = SemaRef.DeclareAggregateDeductionGuideFromInitList(
1232-
RHSTemplate, ParamTypes, Loc);
1243+
RHSTemplate, NewParamTypes, Loc);
12331244
if (!RHSDeductionGuide)
12341245
return nullptr;
1246+
1247+
for (TypedefNameDecl *TD : TypedefDecls)
1248+
TD->setDeclContext(RHSDeductionGuide->getTemplatedDecl());
1249+
12351250
return BuildDeductionGuideForTypeAlias(SemaRef, AliasTemplate,
12361251
RHSDeductionGuide, Loc);
12371252
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// RUN: %clang_cc1 -finclude-default-header -triple \
2+
// RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type \
3+
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
4+
// RUN: --check-prefixes=CHECK,NATIVE_HALF \
5+
// RUN: -DFNATTRS=noundef -DTARGET=dx
6+
// RUN: %clang_cc1 -finclude-default-header -triple \
7+
// RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
8+
// RUN: -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF \
9+
// RUN: -DFNATTRS=noundef -DTARGET=dx
10+
// RUN: %clang_cc1 -finclude-default-header -triple \
11+
// RUN: spirv-unknown-vulkan-compute %s -fnative-half-type \
12+
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
13+
// RUN: --check-prefixes=CHECK,NATIVE_HALF \
14+
// RUN: -DFNATTRS="spir_func noundef" -DTARGET=spv
15+
// RUN: %clang_cc1 -finclude-default-header -triple \
16+
// RUN: spirv-unknown-vulkan-compute %s -emit-llvm -disable-llvm-passes \
17+
// RUN: -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF \
18+
// RUN: -DFNATTRS="spir_func noundef" -DTARGET=spv
19+
20+
// NATIVE_HALF: define [[FNATTRS]] half @
21+
// NATIVE_HALF: %hlsl.degrees = call half @llvm.[[TARGET]].degrees.f16(
22+
// NATIVE_HALF: ret half %hlsl.degrees
23+
// NO_HALF: define [[FNATTRS]] float @
24+
// NO_HALF: %hlsl.degrees = call float @llvm.[[TARGET]].degrees.f32(
25+
// NO_HALF: ret float %hlsl.degrees
26+
half test_degrees_half(half p0) { return degrees(p0); }
27+
// NATIVE_HALF: define [[FNATTRS]] <2 x half> @
28+
// NATIVE_HALF: %hlsl.degrees = call <2 x half> @llvm.[[TARGET]].degrees.v2f16
29+
// NATIVE_HALF: ret <2 x half> %hlsl.degrees
30+
// NO_HALF: define [[FNATTRS]] <2 x float> @
31+
// NO_HALF: %hlsl.degrees = call <2 x float> @llvm.[[TARGET]].degrees.v2f32(
32+
// NO_HALF: ret <2 x float> %hlsl.degrees
33+
half2 test_degrees_half2(half2 p0) { return degrees(p0); }
34+
// NATIVE_HALF: define [[FNATTRS]] <3 x half> @
35+
// NATIVE_HALF: %hlsl.degrees = call <3 x half> @llvm.[[TARGET]].degrees.v3f16
36+
// NATIVE_HALF: ret <3 x half> %hlsl.degrees
37+
// NO_HALF: define [[FNATTRS]] <3 x float> @
38+
// NO_HALF: %hlsl.degrees = call <3 x float> @llvm.[[TARGET]].degrees.v3f32(
39+
// NO_HALF: ret <3 x float> %hlsl.degrees
40+
half3 test_degrees_half3(half3 p0) { return degrees(p0); }
41+
// NATIVE_HALF: define [[FNATTRS]] <4 x half> @
42+
// NATIVE_HALF: %hlsl.degrees = call <4 x half> @llvm.[[TARGET]].degrees.v4f16
43+
// NATIVE_HALF: ret <4 x half> %hlsl.degrees
44+
// NO_HALF: define [[FNATTRS]] <4 x float> @
45+
// NO_HALF: %hlsl.degrees = call <4 x float> @llvm.[[TARGET]].degrees.v4f32(
46+
// NO_HALF: ret <4 x float> %hlsl.degrees
47+
half4 test_degrees_half4(half4 p0) { return degrees(p0); }
48+
49+
// CHECK: define [[FNATTRS]] float @
50+
// CHECK: %hlsl.degrees = call float @llvm.[[TARGET]].degrees.f32(
51+
// CHECK: ret float %hlsl.degrees
52+
float test_degrees_float(float p0) { return degrees(p0); }
53+
// CHECK: define [[FNATTRS]] <2 x float> @
54+
// CHECK: %hlsl.degrees = call <2 x float> @llvm.[[TARGET]].degrees.v2f32
55+
// CHECK: ret <2 x float> %hlsl.degrees
56+
float2 test_degrees_float2(float2 p0) { return degrees(p0); }
57+
// CHECK: define [[FNATTRS]] <3 x float> @
58+
// CHECK: %hlsl.degrees = call <3 x float> @llvm.[[TARGET]].degrees.v3f32
59+
// CHECK: ret <3 x float> %hlsl.degrees
60+
float3 test_degrees_float3(float3 p0) { return degrees(p0); }
61+
// CHECK: define [[FNATTRS]] <4 x float> @
62+
// CHECK: %hlsl.degrees = call <4 x float> @llvm.[[TARGET]].degrees.v4f32
63+
// CHECK: ret <4 x float> %hlsl.degrees
64+
float4 test_degrees_float4(float4 p0) { return degrees(p0); }

clang/test/SemaCXX/cxx20-ctad-type-alias.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,3 +481,16 @@ struct Out {
481481
Out<float>::B out(100); // deduced to Out<float>::A<float>;
482482
static_assert(__is_same(decltype(out), Out<float>::A<float>));
483483
}
484+
485+
namespace GH111508 {
486+
487+
template <typename V> struct S {
488+
using T = V;
489+
T Data;
490+
};
491+
492+
template <typename V> using Alias = S<V>;
493+
494+
Alias A(42);
495+
496+
} // namespace GH111508
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -emit-llvm-only -disable-llvm-passes -verify
2+
3+
float test_too_few_arg() {
4+
return __builtin_hlsl_elementwise_degrees();
5+
// expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
6+
}
7+
8+
float2 test_too_many_arg(float2 p0) {
9+
return __builtin_hlsl_elementwise_degrees(p0, p0);
10+
// expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
11+
}
12+
13+
float builtin_bool_to_float_type_promotion(bool p1) {
14+
return __builtin_hlsl_elementwise_degrees(p1);
15+
// expected-error@-1 {{passing 'bool' to parameter of incompatible type 'float'}}
16+
}
17+
18+
float builtin_degrees_int_to_float_promotion(int p1) {
19+
return __builtin_hlsl_elementwise_degrees(p1);
20+
// expected-error@-1 {{passing 'int' to parameter of incompatible type 'float'}}
21+
}
22+
23+
float2 builtin_degrees_int2_to_float2_promotion(int2 p1) {
24+
return __builtin_hlsl_elementwise_degrees(p1);
25+
// expected-error@-1 {{passing 'int2' (aka 'vector<int, 2>') to parameter of incompatible type '__attribute__((__vector_size__(2 * sizeof(float)))) float' (vector of 2 'float' values)}}
26+
}

0 commit comments

Comments
 (0)