Skip to content

Commit 69dab19

Browse files
committed
self review + respond to pr comments
1 parent 101beb2 commit 69dab19

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed

clang/lib/Headers/hlsl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
// HLSL standard library function declarations/definitions.
2424
#include "hlsl/hlsl_alias_intrinsics.h"
2525
#include "hlsl/hlsl_intrinsics.h"
26+
#include "hlsl/hlsl_compat_overloads.h"
2627

2728
#if defined(__clang__)
2829
#pragma clang diagnostic pop

clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
#ifndef _HLSL_HLSL_ALIAS_INTRINSICS_H_
1010
#define _HLSL_HLSL_ALIAS_INTRINSICS_H_
1111

12-
#include "hlsl_compat_overloads.h"
13-
1412
namespace hlsl {
1513

1614
// Note: Functions in this file are sorted alphabetically, then grouped by base

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,6 +2042,7 @@ static bool CheckVectorElementCallArgs(Sema *S, CallExpr *TheCall) {
20422042
}
20432043

20442044
static bool CheckAllArgsHaveSameType(Sema *S, CallExpr *TheCall) {
2045+
assert(TheCall->getNumArgs() > 1);
20452046
QualType ArgTy0 = TheCall->getArg(0)->getType();
20462047

20472048
for (unsigned I = 1, N = TheCall->getNumArgs(); I < N; ++I) {

clang/test/CodeGenHLSL/builtins/clamp.hlsl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,23 @@ double4 test_clamp_double4_mismatch(double4 p0, double p1) { return clamp(p0, p0
173173
// CHECK: define [[FNATTRS]] [[FFNATTRS]] <4 x double> {{.*}}test_clamp_double4_mismatch2
174174
// CHECK: call reassoc nnan ninf nsz arcp afn <4 x double> @llvm.[[TARGET]].nclamp.v4f64
175175
double4 test_clamp_double4_mismatch2(double4 p0, double p1) { return clamp(p0, p1,p0); }
176+
177+
// CHECK: define [[FNATTRS]] <2 x i32> {{.*}}_overloads1
178+
// CHECK: call <2 x i32> @llvm.[[TARGET]].sclamp.v2i32
179+
int2 test_overloads1(int2 p0, float2 p1, uint p2) { return clamp(p0, p1, p2); }
180+
181+
// CHECK: define [[FNATTRS]] [[FFNATTRS]] <2 x float> {{.*}}test_overloads2
182+
// CHECK: call reassoc nnan ninf nsz arcp afn <2 x float> @llvm.[[TARGET]].nclamp.v2f32
183+
float2 test_overloads2(float2 p0, uint p1, int2 p2) { return clamp(p0, p1, p2); }
184+
185+
// CHECK: define [[FNATTRS]] <3 x i32> {{.*}}test_overloads3
186+
// CHECK: call <3 x i32> @llvm.[[TARGET]].uclamp.v3i32
187+
uint3 test_overloads3(uint3 p0, int p1, float p2) { return clamp(p0, p1, p2); }
188+
189+
// CHECK: define [[FNATTRS]] [[FFNATTRS]] <4 x double> {{.*}}test_overloads4
190+
// CHECK: call reassoc nnan ninf nsz arcp afn <4 x double> @llvm.[[TARGET]].nclamp.v4f64
191+
double4 test_overloads4(double4 p0, float4 p1, int4 p2) { return clamp(p0, p1, p2); }
192+
193+
// CHECK: define [[FNATTRS]] i32 {{.*}}test_overloads5
194+
// CHECK: call i32 @llvm.[[TARGET]].sclamp.i32(
195+
int test_overloads5(int p0, uint p1, double p2) { return clamp(p0, p1, p2); }

clang/test/SemaHLSL/BuiltIns/clamp-errors.hlsl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,26 @@ float2 test_clamp_no_second_arg(float2 p0) {
2020
// expected-error@-1 {{no matching function for call to 'clamp'}}
2121
}
2222

23+
float test_scalar_first_arg(float p0, float2 p1) {
24+
return clamp(p0, p1, p1);
25+
// expected-error@-1 {{call to 'clamp' is ambiguous}}
26+
}
27+
28+
float test_scalar_first_arg2(float p0, float2 p1) {
29+
return clamp(p0, p0, p1);
30+
// expected-error@-1 {{call to 'clamp' is ambiguous}}
31+
}
32+
33+
float2 test_scalar_first_arg3(float p0, float2 p1) {
34+
return clamp(p0, p0, p1);
35+
// expected-error@-1 {{call to 'clamp' is ambiguous}}
36+
}
37+
38+
float3 test_thing(float3 p0, float2 p1) {
39+
return clamp(p0, p0, p1);
40+
// expected-error@-1 {{cannot initialize return object of type 'float3' (aka 'vector<float, 3>') with an rvalue of type 'vector<float, 2>' (vector of 2 'float' values)}}
41+
}
42+
2343
float2 test_clamp_vector_size_mismatch(float3 p0, float2 p1) {
2444
return clamp(p0, p0, p1);
2545
// expected-warning@-1 {{implicit conversion truncates vector: 'float3' (aka 'vector<float, 3>') to 'vector<float, 2>' (vector of 2 'float' values)}}

0 commit comments

Comments
 (0)