186 changes: 186 additions & 0 deletions clang/test/CodeGenHLSL/builtins/any.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
// RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type \
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
// RUN: --check-prefixes=CHECK,NATIVE_HALF
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
// RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
// RUN: -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF

#ifdef __HLSL_ENABLE_16_BIT
// NATIVE_HALF: define noundef i1 @
// NATIVE_HALF: %dx.any = call i1 @llvm.dx.any.i16
// NATIVE_HALF: ret i1 %dx.any
bool test_any_int16_t(int16_t p0) { return any(p0); }
// NATIVE_HALF: define noundef i1 @
// NATIVE_HALF: %dx.any = call i1 @llvm.dx.any.v2i16
// NATIVE_HALF: ret i1 %dx.any
bool test_any_int16_t2(int16_t2 p0) { return any(p0); }
// NATIVE_HALF: define noundef i1 @
// NATIVE_HALF: %dx.any = call i1 @llvm.dx.any.v3i16
// NATIVE_HALF: ret i1 %dx.any
bool test_any_int16_t3(int16_t3 p0) { return any(p0); }
// NATIVE_HALF: define noundef i1 @
// NATIVE_HALF: %dx.any = call i1 @llvm.dx.any.v4i16
// NATIVE_HALF: ret i1 %dx.any
bool test_any_int16_t4(int16_t4 p0) { return any(p0); }

// NATIVE_HALF: define noundef i1 @
// NATIVE_HALF: %dx.any = call i1 @llvm.dx.any.i16
// NATIVE_HALF: ret i1 %dx.any
bool test_any_uint16_t(uint16_t p0) { return any(p0); }
// NATIVE_HALF: define noundef i1 @
// NATIVE_HALF: %dx.any = call i1 @llvm.dx.any.v2i16
// NATIVE_HALF: ret i1 %dx.any
bool test_any_uint16_t2(uint16_t2 p0) { return any(p0); }
// NATIVE_HALF: define noundef i1 @
// NATIVE_HALF: %dx.any = call i1 @llvm.dx.any.v3i16
// NATIVE_HALF: ret i1 %dx.any
bool test_any_uint16_t3(uint16_t3 p0) { return any(p0); }
// NATIVE_HALF: define noundef i1 @
// NATIVE_HALF: %dx.any = call i1 @llvm.dx.any.v4i16
// NATIVE_HALF: ret i1 %dx.any
bool test_any_uint16_t4(uint16_t4 p0) { return any(p0); }
#endif // __HLSL_ENABLE_16_BIT

// CHECK: define noundef i1 @
// NATIVE_HALF: %dx.any = call i1 @llvm.dx.any.f16
// NO_HALF: %dx.any = call i1 @llvm.dx.any.f32
// CHECK: ret i1 %dx.any
bool test_any_half(half p0) { return any(p0); }

// CHECK: define noundef i1 @
// NATIVE_HALF: %dx.any = call i1 @llvm.dx.any.v2f16
// NO_HALF: %dx.any = call i1 @llvm.dx.any.v2f32
// CHECK: ret i1 %dx.any
bool test_any_half2(half2 p0) { return any(p0); }

// CHECK: define noundef i1 @
// NATIVE_HALF: %dx.any = call i1 @llvm.dx.any.v3f16
// NO_HALF: %dx.any = call i1 @llvm.dx.any.v3f32
// CHECK: ret i1 %dx.any
bool test_any_half3(half3 p0) { return any(p0); }

// CHECK: define noundef i1 @
// NATIVE_HALF: %dx.any = call i1 @llvm.dx.any.v4f16
// NO_HALF: %dx.any = call i1 @llvm.dx.any.v4f32
// CHECK: ret i1 %dx.any
bool test_any_half4(half4 p0) { return any(p0); }

// CHECK: define noundef i1 @
// CHECK: %dx.any = call i1 @llvm.dx.any.f32
// CHECK: ret i1 %dx.any
bool test_any_float(float p0) { return any(p0); }
// CHECK: define noundef i1 @
// CHECK: %dx.any = call i1 @llvm.dx.any.v2f32
// CHECK: ret i1 %dx.any
bool test_any_float2(float2 p0) { return any(p0); }
// CHECK: define noundef i1 @
// CHECK: %dx.any = call i1 @llvm.dx.any.v3f32
// CHECK: ret i1 %dx.any
bool test_any_float3(float3 p0) { return any(p0); }
// CHECK: define noundef i1 @
// CHECK: %dx.any = call i1 @llvm.dx.any.v4f32
// CHECK: ret i1 %dx.any
bool test_any_float4(float4 p0) { return any(p0); }

// CHECK: define noundef i1 @
// CHECK: %dx.any = call i1 @llvm.dx.any.f64
// CHECK: ret i1 %dx.any
bool test_any_double(double p0) { return any(p0); }
// CHECK: define noundef i1 @
// CHECK: %dx.any = call i1 @llvm.dx.any.v2f64
// CHECK: ret i1 %dx.any
bool test_any_double2(double2 p0) { return any(p0); }
// CHECK: define noundef i1 @
// CHECK: %dx.any = call i1 @llvm.dx.any.v3f64
// CHECK: ret i1 %dx.any
bool test_any_double3(double3 p0) { return any(p0); }
// CHECK: define noundef i1 @
// CHECK: %dx.any = call i1 @llvm.dx.any.v4f64
// CHECK: ret i1 %dx.any
bool test_any_double4(double4 p0) { return any(p0); }

// CHECK: define noundef i1 @
// CHECK: %dx.any = call i1 @llvm.dx.any.i32
// CHECK: ret i1 %dx.any
bool test_any_int(int p0) { return any(p0); }
// CHECK: define noundef i1 @
// CHECK: %dx.any = call i1 @llvm.dx.any.v2i32
// CHECK: ret i1 %dx.any
bool test_any_int2(int2 p0) { return any(p0); }
// CHECK: define noundef i1 @
// CHECK: %dx.any = call i1 @llvm.dx.any.v3i32
// CHECK: ret i1 %dx.any
bool test_any_int3(int3 p0) { return any(p0); }
// CHECK: define noundef i1 @
// CHECK: %dx.any = call i1 @llvm.dx.any.v4i32
// CHECK: ret i1 %dx.any
bool test_any_int4(int4 p0) { return any(p0); }

// CHECK: define noundef i1 @
// CHECK: %dx.any = call i1 @llvm.dx.any.i32
// CHECK: ret i1 %dx.any
bool test_any_uint(uint p0) { return any(p0); }
// CHECK: define noundef i1 @
// CHECK: %dx.any = call i1 @llvm.dx.any.v2i32
// CHECK: ret i1 %dx.any
bool test_any_uint2(uint2 p0) { return any(p0); }
// CHECK: define noundef i1 @
// CHECK: %dx.any = call i1 @llvm.dx.any.v3i32
// CHECK: ret i1 %dx.any
bool test_any_uint3(uint3 p0) { return any(p0); }
// CHECK: define noundef i1 @
// CHECK: %dx.any = call i1 @llvm.dx.any.v4i32
// CHECK: ret i1 %dx.any
bool test_any_uint4(uint4 p0) { return any(p0); }

// CHECK: define noundef i1 @
// CHECK: %dx.any = call i1 @llvm.dx.any.i64
// CHECK: ret i1 %dx.any
bool test_any_int64_t(int64_t p0) { return any(p0); }
// CHECK: define noundef i1 @
// CHECK: %dx.any = call i1 @llvm.dx.any.v2i64
// CHECK: ret i1 %dx.any
bool test_any_int64_t2(int64_t2 p0) { return any(p0); }
// CHECK: define noundef i1 @
// CHECK: %dx.any = call i1 @llvm.dx.any.v3i64
// CHECK: ret i1 %dx.any
bool test_any_int64_t3(int64_t3 p0) { return any(p0); }
// CHECK: define noundef i1 @
// CHECK: %dx.any = call i1 @llvm.dx.any.v4i64
// CHECK: ret i1 %dx.any
bool test_any_int64_t4(int64_t4 p0) { return any(p0); }

// CHECK: define noundef i1 @
// CHECK: %dx.any = call i1 @llvm.dx.any.i64
// CHECK: ret i1 %dx.any
bool test_any_uint64_t(uint64_t p0) { return any(p0); }
// CHECK: define noundef i1 @
// CHECK: %dx.any = call i1 @llvm.dx.any.v2i64
// CHECK: ret i1 %dx.any
bool test_any_uint64_t2(uint64_t2 p0) { return any(p0); }
// CHECK: define noundef i1 @
// CHECK: %dx.any = call i1 @llvm.dx.any.v3i64
// CHECK: ret i1 %dx.any
bool test_any_uint64_t3(uint64_t3 p0) { return any(p0); }
// CHECK: define noundef i1 @
// CHECK: %dx.any = call i1 @llvm.dx.any.v4i64
// CHECK: ret i1 %dx.any
bool test_any_uint64_t4(uint64_t4 p0) { return any(p0); }

// CHECK: define noundef i1 @
// CHECK: %dx.any = call i1 @llvm.dx.any.i1
// CHECK: ret i1 %dx.any
bool test_any_bool(bool p0) { return any(p0); }
// CHECK: define noundef i1 @
// CHECK: %dx.any = call i1 @llvm.dx.any.v2i1
// CHECK: ret i1 %dx.any
bool test_any_bool2(bool2 p0) { return any(p0); }
// CHECK: define noundef i1 @
// CHECK: %dx.any = call i1 @llvm.dx.any.v3i1
// CHECK: ret i1 %dx.any
bool test_any_bool3(bool3 p0) { return any(p0); }
// CHECK: define noundef i1 @
// CHECK: %dx.any = call i1 @llvm.dx.any.v4i1
// CHECK: ret i1 %dx.any
bool test_any_bool4(bool4 p0) { return any(p0); }
53 changes: 53 additions & 0 deletions clang/test/CodeGenHLSL/builtins/exp.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
// RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type \
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
// RUN: --check-prefixes=CHECK,NATIVE_HALF
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
// RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
// RUN: -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF

// NATIVE_HALF: define noundef half @
// NATIVE_HALF: %elt.exp = call half @llvm.exp.f16(
// NATIVE_HALF: ret half %elt.exp
// NO_HALF: define noundef float @"?test_exp_half@@YA$halff@$halff@@Z"(
// NO_HALF: %elt.exp = call float @llvm.exp.f32(
// NO_HALF: ret float %elt.exp
half test_exp_half(half p0) { return exp(p0); }
// NATIVE_HALF: define noundef <2 x half> @
// NATIVE_HALF: %elt.exp = call <2 x half> @llvm.exp.v2f16
// NATIVE_HALF: ret <2 x half> %elt.exp
// NO_HALF: define noundef <2 x float> @
// NO_HALF: %elt.exp = call <2 x float> @llvm.exp.v2f32(
// NO_HALF: ret <2 x float> %elt.exp
half2 test_exp_half2(half2 p0) { return exp(p0); }
// NATIVE_HALF: define noundef <3 x half> @
// NATIVE_HALF: %elt.exp = call <3 x half> @llvm.exp.v3f16
// NATIVE_HALF: ret <3 x half> %elt.exp
// NO_HALF: define noundef <3 x float> @
// NO_HALF: %elt.exp = call <3 x float> @llvm.exp.v3f32(
// NO_HALF: ret <3 x float> %elt.exp
half3 test_exp_half3(half3 p0) { return exp(p0); }
// NATIVE_HALF: define noundef <4 x half> @
// NATIVE_HALF: %elt.exp = call <4 x half> @llvm.exp.v4f16
// NATIVE_HALF: ret <4 x half> %elt.exp
// NO_HALF: define noundef <4 x float> @
// NO_HALF: %elt.exp = call <4 x float> @llvm.exp.v4f32(
// NO_HALF: ret <4 x float> %elt.exp
half4 test_exp_half4(half4 p0) { return exp(p0); }

// CHECK: define noundef float @
// CHECK: %elt.exp = call float @llvm.exp.f32(
// CHECK: ret float %elt.exp
float test_exp_float(float p0) { return exp(p0); }
// CHECK: define noundef <2 x float> @
// CHECK: %elt.exp = call <2 x float> @llvm.exp.v2f32
// CHECK: ret <2 x float> %elt.exp
float2 test_exp_float2(float2 p0) { return exp(p0); }
// CHECK: define noundef <3 x float> @
// CHECK: %elt.exp = call <3 x float> @llvm.exp.v3f32
// CHECK: ret <3 x float> %elt.exp
float3 test_exp_float3(float3 p0) { return exp(p0); }
// CHECK: define noundef <4 x float> @
// CHECK: %elt.exp = call <4 x float> @llvm.exp.v4f32
// CHECK: ret <4 x float> %elt.exp
float4 test_exp_float4(float4 p0) { return exp(p0); }
53 changes: 53 additions & 0 deletions clang/test/CodeGenHLSL/builtins/exp2.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
// RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type \
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
// RUN: --check-prefixes=CHECK,NATIVE_HALF
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
// RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
// RUN: -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF

// NATIVE_HALF: define noundef half @
// NATIVE_HALF: %elt.exp2 = call half @llvm.exp2.f16(
// NATIVE_HALF: ret half %elt.exp2
// NO_HALF: define noundef float @"?test_exp2_half@@YA$halff@$halff@@Z"(
// NO_HALF: %elt.exp2 = call float @llvm.exp2.f32(
// NO_HALF: ret float %elt.exp2
half test_exp2_half(half p0) { return exp2(p0); }
// NATIVE_HALF: define noundef <2 x half> @
// NATIVE_HALF: %elt.exp2 = call <2 x half> @llvm.exp2.v2f16
// NATIVE_HALF: ret <2 x half> %elt.exp2
// NO_HALF: define noundef <2 x float> @
// NO_HALF: %elt.exp2 = call <2 x float> @llvm.exp2.v2f32(
// NO_HALF: ret <2 x float> %elt.exp2
half2 test_exp2_half2(half2 p0) { return exp2(p0); }
// NATIVE_HALF: define noundef <3 x half> @
// NATIVE_HALF: %elt.exp2 = call <3 x half> @llvm.exp2.v3f16
// NATIVE_HALF: ret <3 x half> %elt.exp2
// NO_HALF: define noundef <3 x float> @
// NO_HALF: %elt.exp2 = call <3 x float> @llvm.exp2.v3f32(
// NO_HALF: ret <3 x float> %elt.exp2
half3 test_exp2_half3(half3 p0) { return exp2(p0); }
// NATIVE_HALF: define noundef <4 x half> @
// NATIVE_HALF: %elt.exp2 = call <4 x half> @llvm.exp2.v4f16
// NATIVE_HALF: ret <4 x half> %elt.exp2
// NO_HALF: define noundef <4 x float> @
// NO_HALF: %elt.exp2 = call <4 x float> @llvm.exp2.v4f32(
// NO_HALF: ret <4 x float> %elt.exp2
half4 test_exp2_half4(half4 p0) { return exp2(p0); }

// CHECK: define noundef float @
// CHECK: %elt.exp2 = call float @llvm.exp2.f32(
// CHECK: ret float %elt.exp2
float test_exp2_float(float p0) { return exp2(p0); }
// CHECK: define noundef <2 x float> @
// CHECK: %elt.exp2 = call <2 x float> @llvm.exp2.v2f32
// CHECK: ret <2 x float> %elt.exp2
float2 test_exp2_float2(float2 p0) { return exp2(p0); }
// CHECK: define noundef <3 x float> @
// CHECK: %elt.exp2 = call <3 x float> @llvm.exp2.v3f32
// CHECK: ret <3 x float> %elt.exp2
float3 test_exp2_float3(float3 p0) { return exp2(p0); }
// CHECK: define noundef <4 x float> @
// CHECK: %elt.exp2 = call <4 x float> @llvm.exp2.v4f32
// CHECK: ret <4 x float> %elt.exp2
float4 test_exp2_float4(float4 p0) { return exp2(p0); }
191 changes: 191 additions & 0 deletions clang/test/CodeGenHLSL/builtins/mad.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
// RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type \
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
// RUN: --check-prefixes=CHECK,NATIVE_HALF
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
// RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
// RUN: -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF

#ifdef __HLSL_ENABLE_16_BIT
// NATIVE_HALF: %dx.umad = call i16 @llvm.dx.umad.i16(i16 %0, i16 %1, i16 %2)
// NATIVE_HALF: ret i16 %dx.umad
uint16_t test_mad_uint16_t(uint16_t p0, uint16_t p1, uint16_t p2) { return mad(p0, p1, p2); }

// NATIVE_HALF: %dx.umad = call <2 x i16> @llvm.dx.umad.v2i16(<2 x i16> %0, <2 x i16> %1, <2 x i16> %2)
// NATIVE_HALF: ret <2 x i16> %dx.umad
uint16_t2 test_mad_uint16_t2(uint16_t2 p0, uint16_t2 p1, uint16_t2 p2) { return mad(p0, p1, p2); }

// NATIVE_HALF: %dx.umad = call <3 x i16> @llvm.dx.umad.v3i16(<3 x i16> %0, <3 x i16> %1, <3 x i16> %2)
// NATIVE_HALF: ret <3 x i16> %dx.umad
uint16_t3 test_mad_uint16_t3(uint16_t3 p0, uint16_t3 p1, uint16_t3 p2) { return mad(p0, p1, p2); }

// NATIVE_HALF: %dx.umad = call <4 x i16> @llvm.dx.umad.v4i16(<4 x i16> %0, <4 x i16> %1, <4 x i16> %2)
// NATIVE_HALF: ret <4 x i16> %dx.umad
uint16_t4 test_mad_uint16_t4(uint16_t4 p0, uint16_t4 p1, uint16_t4 p2) { return mad(p0, p1, p2); }

// NATIVE_HALF: %dx.imad = call i16 @llvm.dx.imad.i16(i16 %0, i16 %1, i16 %2)
// NATIVE_HALF: ret i16 %dx.imad
int16_t test_mad_int16_t(int16_t p0, int16_t p1, int16_t p2) { return mad(p0, p1, p2); }

// NATIVE_HALF: %dx.imad = call <2 x i16> @llvm.dx.imad.v2i16(<2 x i16> %0, <2 x i16> %1, <2 x i16> %2)
// NATIVE_HALF: ret <2 x i16> %dx.imad
int16_t2 test_mad_int16_t2(int16_t2 p0, int16_t2 p1, int16_t2 p2) { return mad(p0, p1, p2); }

// NATIVE_HALF: %dx.imad = call <3 x i16> @llvm.dx.imad.v3i16(<3 x i16> %0, <3 x i16> %1, <3 x i16> %2)
// NATIVE_HALF: ret <3 x i16> %dx.imad
int16_t3 test_mad_int16_t3(int16_t3 p0, int16_t3 p1, int16_t3 p2) { return mad(p0, p1, p2); }

// NATIVE_HALF: %dx.imad = call <4 x i16> @llvm.dx.imad.v4i16(<4 x i16> %0, <4 x i16> %1, <4 x i16> %2)
// NATIVE_HALF: ret <4 x i16> %dx.imad
int16_t4 test_mad_int16_t4(int16_t4 p0, int16_t4 p1, int16_t4 p2) { return mad(p0, p1, p2); }
#endif // __HLSL_ENABLE_16_BIT

// NATIVE_HALF: %dx.fmad = call half @llvm.fmuladd.f16(half %0, half %1, half %2)
// NATIVE_HALF: ret half %dx.fmad
// NO_HALF: %dx.fmad = call float @llvm.fmuladd.f32(float %0, float %1, float %2)
// NO_HALF: ret float %dx.fmad
half test_mad_half(half p0, half p1, half p2) { return mad(p0, p1, p2); }

// NATIVE_HALF: %dx.fmad = call <2 x half> @llvm.fmuladd.v2f16(<2 x half> %0, <2 x half> %1, <2 x half> %2)
// NATIVE_HALF: ret <2 x half> %dx.fmad
// NO_HALF: %dx.fmad = call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %0, <2 x float> %1, <2 x float> %2)
// NO_HALF: ret <2 x float> %dx.fmad
half2 test_mad_half2(half2 p0, half2 p1, half2 p2) { return mad(p0, p1, p2); }

// NATIVE_HALF: %dx.fmad = call <3 x half> @llvm.fmuladd.v3f16(<3 x half> %0, <3 x half> %1, <3 x half> %2)
// NATIVE_HALF: ret <3 x half> %dx.fmad
// NO_HALF: %dx.fmad = call <3 x float> @llvm.fmuladd.v3f32(<3 x float> %0, <3 x float> %1, <3 x float> %2)
// NO_HALF: ret <3 x float> %dx.fmad
half3 test_mad_half3(half3 p0, half3 p1, half3 p2) { return mad(p0, p1, p2); }

// NATIVE_HALF: %dx.fmad = call <4 x half> @llvm.fmuladd.v4f16(<4 x half> %0, <4 x half> %1, <4 x half> %2)
// NATIVE_HALF: ret <4 x half> %dx.fmad
// NO_HALF: %dx.fmad = call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %0, <4 x float> %1, <4 x float> %2)
// NO_HALF: ret <4 x float> %dx.fmad
half4 test_mad_half4(half4 p0, half4 p1, half4 p2) { return mad(p0, p1, p2); }

// CHECK: %dx.fmad = call float @llvm.fmuladd.f32(float %0, float %1, float %2)
// CHECK: ret float %dx.fmad
float test_mad_float(float p0, float p1, float p2) { return mad(p0, p1, p2); }

// CHECK: %dx.fmad = call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %0, <2 x float> %1, <2 x float> %2)
// CHECK: ret <2 x float> %dx.fmad
float2 test_mad_float2(float2 p0, float2 p1, float2 p2) { return mad(p0, p1, p2); }

// CHECK: %dx.fmad = call <3 x float> @llvm.fmuladd.v3f32(<3 x float> %0, <3 x float> %1, <3 x float> %2)
// CHECK: ret <3 x float> %dx.fmad
float3 test_mad_float3(float3 p0, float3 p1, float3 p2) { return mad(p0, p1, p2); }

// CHECK: %dx.fmad = call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %0, <4 x float> %1, <4 x float> %2)
// CHECK: ret <4 x float> %dx.fmad
float4 test_mad_float4(float4 p0, float4 p1, float4 p2) { return mad(p0, p1, p2); }

// CHECK: %dx.fmad = call double @llvm.fmuladd.f64(double %0, double %1, double %2)
// CHECK: ret double %dx.fmad
double test_mad_double(double p0, double p1, double p2) { return mad(p0, p1, p2); }

// CHECK: %dx.fmad = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %0, <2 x double> %1, <2 x double> %2)
// CHECK: ret <2 x double> %dx.fmad
double2 test_mad_double2(double2 p0, double2 p1, double2 p2) { return mad(p0, p1, p2); }

// CHECK: %dx.fmad = call <3 x double> @llvm.fmuladd.v3f64(<3 x double> %0, <3 x double> %1, <3 x double> %2)
// CHECK: ret <3 x double> %dx.fmad
double3 test_mad_double3(double3 p0, double3 p1, double3 p2) { return mad(p0, p1, p2); }

// CHECK: %dx.fmad = call <4 x double> @llvm.fmuladd.v4f64(<4 x double> %0, <4 x double> %1, <4 x double> %2)
// CHECK: ret <4 x double> %dx.fmad
double4 test_mad_double4(double4 p0, double4 p1, double4 p2) { return mad(p0, p1, p2); }

// CHECK: %dx.imad = call i32 @llvm.dx.imad.i32(i32 %0, i32 %1, i32 %2)
// CHECK: ret i32 %dx.imad
int test_mad_int(int p0, int p1, int p2) { return mad(p0, p1, p2); }

// CHECK: %dx.imad = call <2 x i32> @llvm.dx.imad.v2i32(<2 x i32> %0, <2 x i32> %1, <2 x i32> %2)
// CHECK: ret <2 x i32> %dx.imad
int2 test_mad_int2(int2 p0, int2 p1, int2 p2) { return mad(p0, p1, p2); }

// CHECK: %dx.imad = call <3 x i32> @llvm.dx.imad.v3i32(<3 x i32> %0, <3 x i32> %1, <3 x i32> %2)
// CHECK: ret <3 x i32> %dx.imad
int3 test_mad_int3(int3 p0, int3 p1, int3 p2) { return mad(p0, p1, p2); }

// CHECK: %dx.imad = call <4 x i32> @llvm.dx.imad.v4i32(<4 x i32> %0, <4 x i32> %1, <4 x i32> %2)
// CHECK: ret <4 x i32> %dx.imad
int4 test_mad_int4(int4 p0, int4 p1, int4 p2) { return mad(p0, p1, p2); }

// CHECK: %dx.imad = call i64 @llvm.dx.imad.i64(i64 %0, i64 %1, i64 %2)
// CHECK: ret i64 %dx.imad
int64_t test_mad_int64_t(int64_t p0, int64_t p1, int64_t p2) { return mad(p0, p1, p2); }

// CHECK: %dx.imad = call <2 x i64> @llvm.dx.imad.v2i64(<2 x i64> %0, <2 x i64> %1, <2 x i64> %2)
// CHECK: ret <2 x i64> %dx.imad
int64_t2 test_mad_int64_t2(int64_t2 p0, int64_t2 p1, int64_t2 p2) { return mad(p0, p1, p2); }

// CHECK: %dx.imad = call <3 x i64> @llvm.dx.imad.v3i64(<3 x i64> %0, <3 x i64> %1, <3 x i64> %2)
// CHECK: ret <3 x i64> %dx.imad
int64_t3 test_mad_int64_t3(int64_t3 p0, int64_t3 p1, int64_t3 p2) { return mad(p0, p1, p2); }

// CHECK: %dx.imad = call <4 x i64> @llvm.dx.imad.v4i64(<4 x i64> %0, <4 x i64> %1, <4 x i64> %2)
// CHECK: ret <4 x i64> %dx.imad
int64_t4 test_mad_int64_t4(int64_t4 p0, int64_t4 p1, int64_t4 p2) { return mad(p0, p1, p2); }

// CHECK: %dx.umad = call i32 @llvm.dx.umad.i32(i32 %0, i32 %1, i32 %2)
// CHECK: ret i32 %dx.umad
uint test_mad_uint(uint p0, uint p1, uint p2) { return mad(p0, p1, p2); }

// CHECK: %dx.umad = call <2 x i32> @llvm.dx.umad.v2i32(<2 x i32> %0, <2 x i32> %1, <2 x i32> %2)
// CHECK: ret <2 x i32> %dx.umad
uint2 test_mad_uint2(uint2 p0, uint2 p1, uint2 p2) { return mad(p0, p1, p2); }

// CHECK: %dx.umad = call <3 x i32> @llvm.dx.umad.v3i32(<3 x i32> %0, <3 x i32> %1, <3 x i32> %2)
// CHECK: ret <3 x i32> %dx.umad
uint3 test_mad_uint3(uint3 p0, uint3 p1, uint3 p2) { return mad(p0, p1, p2); }

// CHECK: %dx.umad = call <4 x i32> @llvm.dx.umad.v4i32(<4 x i32> %0, <4 x i32> %1, <4 x i32> %2)
// CHECK: ret <4 x i32> %dx.umad
uint4 test_mad_uint4(uint4 p0, uint4 p1, uint4 p2) { return mad(p0, p1, p2); }

// CHECK: %dx.umad = call i64 @llvm.dx.umad.i64(i64 %0, i64 %1, i64 %2)
// CHECK: ret i64 %dx.umad
uint64_t test_mad_uint64_t(uint64_t p0, uint64_t p1, uint64_t p2) { return mad(p0, p1, p2); }

// CHECK: %dx.umad = call <2 x i64> @llvm.dx.umad.v2i64(<2 x i64> %0, <2 x i64> %1, <2 x i64> %2)
// CHECK: ret <2 x i64> %dx.umad
uint64_t2 test_mad_uint64_t2(uint64_t2 p0, uint64_t2 p1, uint64_t2 p2) { return mad(p0, p1, p2); }

// CHECK: %dx.umad = call <3 x i64> @llvm.dx.umad.v3i64(<3 x i64> %0, <3 x i64> %1, <3 x i64> %2)
// CHECK: ret <3 x i64> %dx.umad
uint64_t3 test_mad_uint64_t3(uint64_t3 p0, uint64_t3 p1, uint64_t3 p2) { return mad(p0, p1, p2); }

// CHECK: %dx.umad = call <4 x i64> @llvm.dx.umad.v4i64(<4 x i64> %0, <4 x i64> %1, <4 x i64> %2)
// CHECK: ret <4 x i64> %dx.umad
uint64_t4 test_mad_uint64_t4(uint64_t4 p0, uint64_t4 p1, uint64_t4 p2) { return mad(p0, p1, p2); }

// CHECK: %dx.fmad = call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %splat.splat, <2 x float> %1, <2 x float> %2)
// CHECK: ret <2 x float> %dx.fmad
float2 test_mad_float2_splat(float p0, float2 p1, float2 p2) { return mad(p0, p1, p2); }

// CHECK: %dx.fmad = call <3 x float> @llvm.fmuladd.v3f32(<3 x float> %splat.splat, <3 x float> %1, <3 x float> %2)
// CHECK: ret <3 x float> %dx.fmad
float3 test_mad_float3_splat(float p0, float3 p1, float3 p2) { return mad(p0, p1, p2); }

// CHECK: %dx.fmad = call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %splat.splat, <4 x float> %1, <4 x float> %2)
// CHECK: ret <4 x float> %dx.fmad
float4 test_mad_float4_splat(float p0, float4 p1, float4 p2) { return mad(p0, p1, p2); }

// CHECK: %conv = sitofp i32 %2 to float
// CHECK: %splat.splatinsert = insertelement <2 x float> poison, float %conv, i64 0
// CHECK: %splat.splat = shufflevector <2 x float> %splat.splatinsert, <2 x float> poison, <2 x i32> zeroinitializer
// CHECK: %dx.fmad = call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %0, <2 x float> %1, <2 x float> %splat.splat)
// CHECK: ret <2 x float> %dx.fmad
float2 test_mad_float2_int_splat(float2 p0, float2 p1, int p2) {
return mad(p0, p1, p2);
}

// CHECK: %conv = sitofp i32 %2 to float
// CHECK: %splat.splatinsert = insertelement <3 x float> poison, float %conv, i64 0
// CHECK: %splat.splat = shufflevector <3 x float> %splat.splatinsert, <3 x float> poison, <3 x i32> zeroinitializer
// CHECK: %dx.fmad = call <3 x float> @llvm.fmuladd.v3f32(<3 x float> %0, <3 x float> %1, <3 x float> %splat.splat)
// CHECK: ret <3 x float> %dx.fmad
float3 test_mad_float3_int_splat(float3 p0, float3 p1, int p2) {
return mad(p0, p1, p2);
}
53 changes: 53 additions & 0 deletions clang/test/CodeGenHLSL/builtins/rcp.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
// RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type \
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
// RUN: --check-prefixes=CHECK,NATIVE_HALF
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
// RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
// RUN: -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF

// NATIVE_HALF: define noundef half @
// NATIVE_HALF: %dx.rcp = call half @llvm.dx.rcp.f16(
// NATIVE_HALF: ret half %dx.rcp
// NO_HALF: define noundef float @"?test_rcp_half@@YA$halff@$halff@@Z"(
// NO_HALF: %dx.rcp = call float @llvm.dx.rcp.f32(
// NO_HALF: ret float %dx.rcp
half test_rcp_half(half p0) { return rcp(p0); }
// NATIVE_HALF: define noundef <2 x half> @
// NATIVE_HALF: %dx.rcp = call <2 x half> @llvm.dx.rcp.v2f16
// NATIVE_HALF: ret <2 x half> %dx.rcp
// NO_HALF: define noundef <2 x float> @
// NO_HALF: %dx.rcp = call <2 x float> @llvm.dx.rcp.v2f32(
// NO_HALF: ret <2 x float> %dx.rcp
half2 test_rcp_half2(half2 p0) { return rcp(p0); }
// NATIVE_HALF: define noundef <3 x half> @
// NATIVE_HALF: %dx.rcp = call <3 x half> @llvm.dx.rcp.v3f16
// NATIVE_HALF: ret <3 x half> %dx.rcp
// NO_HALF: define noundef <3 x float> @
// NO_HALF: %dx.rcp = call <3 x float> @llvm.dx.rcp.v3f32(
// NO_HALF: ret <3 x float> %dx.rcp
half3 test_rcp_half3(half3 p0) { return rcp(p0); }
// NATIVE_HALF: define noundef <4 x half> @
// NATIVE_HALF: %dx.rcp = call <4 x half> @llvm.dx.rcp.v4f16
// NATIVE_HALF: ret <4 x half> %dx.rcp
// NO_HALF: define noundef <4 x float> @
// NO_HALF: %dx.rcp = call <4 x float> @llvm.dx.rcp.v4f32(
// NO_HALF: ret <4 x float> %dx.rcp
half4 test_rcp_half4(half4 p0) { return rcp(p0); }

// CHECK: define noundef float @
// CHECK: %dx.rcp = call float @llvm.dx.rcp.f32(
// CHECK: ret float %dx.rcp
float test_rcp_float(float p0) { return rcp(p0); }
// CHECK: define noundef <2 x float> @
// CHECK: %dx.rcp = call <2 x float> @llvm.dx.rcp.v2f32
// CHECK: ret <2 x float> %dx.rcp
float2 test_rcp_float2(float2 p0) { return rcp(p0); }
// CHECK: define noundef <3 x float> @
// CHECK: %dx.rcp = call <3 x float> @llvm.dx.rcp.v3f32
// CHECK: ret <3 x float> %dx.rcp
float3 test_rcp_float3(float3 p0) { return rcp(p0); }
// CHECK: define noundef <4 x float> @
// CHECK: %dx.rcp = call <4 x float> @llvm.dx.rcp.v4f32
// CHECK: ret <4 x float> %dx.rcp
float4 test_rcp_float4(float4 p0) { return rcp(p0); }
35 changes: 16 additions & 19 deletions clang/test/CodeGenHLSL/semantics/DispatchThreadID.hlsl
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm -finclude-default-header -disable-llvm-passes -o - %s
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm -finclude-default-header -disable-llvm-passes -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-DXIL
// RUN: %clang_cc1 -triple spirv-linux-vulkan-library -x hlsl -emit-llvm -finclude-default-header -disable-llvm-passes -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-SPIRV

// Make sure SV_DispatchThreadID translated into dx.thread.id.

const RWBuffer<float> In;
RWBuffer<float> Out;

// CHECK: define void @foo()
// CHECK: %[[ID:[0-9a-zA-Z]+]] = call i32 @llvm.dx.thread.id(i32 0)
// CHECK: call void @"?foo@@YAXH@Z"(i32 %[[ID]])
// CHECK: define void @foo()
// CHECK-DXIL: %[[#ID:]] = call i32 @llvm.dx.thread.id(i32 0)
// CHECK-SPIRV: %[[#ID:]] = call i32 @llvm.spv.thread.id(i32 0)
// CHECK: call void @{{.*}}foo{{.*}}(i32 %[[#ID]])
[shader("compute")]
[numthreads(8,8,1)]
void foo(uint Idx : SV_DispatchThreadID) {
Out[Idx] = In[Idx];
}
void foo(uint Idx : SV_DispatchThreadID) {}

// CHECK: define void @bar()
// CHECK: %[[ID_X:[0-9a-zA-Z]+]] = call i32 @llvm.dx.thread.id(i32 0)
// CHECK: %[[ID_X_:[0-9a-zA-Z]+]] = insertelement <2 x i32> poison, i32 %[[ID_X]], i64 0
// CHECK: %[[ID_Y:[0-9a-zA-Z]+]] = call i32 @llvm.dx.thread.id(i32 1)
// CHECK: %[[ID_XY:[0-9a-zA-Z]+]] = insertelement <2 x i32> %[[ID_X_]], i32 %[[ID_Y]], i64 1
// CHECK: call void @"?bar@@YAXT?$__vector@H$01@__clang@@@Z"(<2 x i32> %[[ID_XY]])
// CHECK: define void @bar()
// CHECK-DXIL: %[[#ID_X:]] = call i32 @llvm.dx.thread.id(i32 0)
// CHECK-SPIRV: %[[#ID_X:]] = call i32 @llvm.spv.thread.id(i32 0)
// CHECK: %[[#ID_X_:]] = insertelement <2 x i32> poison, i32 %[[#ID_X]], i64 0
// CHECK-DXIL: %[[#ID_Y:]] = call i32 @llvm.dx.thread.id(i32 1)
// CHECK-SPIRV: %[[#ID_Y:]] = call i32 @llvm.spv.thread.id(i32 1)
// CHECK: %[[#ID_XY:]] = insertelement <2 x i32> %[[#ID_X_]], i32 %[[#ID_Y]], i64 1
// CHECK-DXIL: call void @{{.*}}bar{{.*}}(<2 x i32> %[[#ID_XY]])
[shader("compute")]
[numthreads(8,8,1)]
void bar(uint2 Idx : SV_DispatchThreadID) {
Out[Idx.y] = In[Idx.x];
}
void bar(uint2 Idx : SV_DispatchThreadID) {}

102 changes: 102 additions & 0 deletions clang/test/CodeGenObjC/constant-non-fragile-ivar-offset.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.14.0 -emit-llvm %s -o - | FileCheck %s

// CHECK: @"OBJC_IVAR_$_StaticLayout.static_layout_ivar" = hidden constant i64 20
// CHECK: @"OBJC_IVAR_$_SuperClass.superClassIvar" = hidden constant i64 20
// CHECK: @"OBJC_IVAR_$_SuperClass._superClassProperty" = hidden constant i64 24
// CHECK: @"OBJC_IVAR_$_IntermediateClass.intermediateClassIvar" = constant i64 32
// CHECK: @"OBJC_IVAR_$_IntermediateClass.intermediateClassIvar2" = constant i64 40
// CHECK: @"OBJC_IVAR_$_IntermediateClass._intermediateProperty" = hidden constant i64 48
// CHECK: @"OBJC_IVAR_$_SubClass.subClassIvar" = constant i64 56
// CHECK: @"OBJC_IVAR_$_SubClass._subClassProperty" = hidden constant i64 64
// CHECK: @"OBJC_IVAR_$_NotStaticLayout.not_static_layout_ivar" = hidden global i64 12

@interface NSObject {
Expand All @@ -14,12 +21,105 @@ @interface StaticLayout : NSObject
@implementation StaticLayout {
int static_layout_ivar;
}

// CHECK-LABEL: define internal void @"\01-[StaticLayout meth]"
-(void)meth {
static_layout_ivar = 0;
// CHECK-NOT: load i64, ptr @"OBJC_IVAR_$_StaticLayout
// CHECK: getelementptr inbounds i8, ptr %0, i64 20
}
@end

@interface SuperClass : NSObject
@property (nonatomic, assign) int superClassProperty;
@end

@implementation SuperClass {
int superClassIvar; // Declare an ivar
}

// CHECK-LABEL: define internal void @"\01-[SuperClass superClassMethod]"
- (void)superClassMethod {
_superClassProperty = 42;
superClassIvar = 10;
// CHECK-NOT: load i64, ptr @"OBJC_IVAR_$_SuperClass
// CHECK: getelementptr inbounds i8, ptr %1, i64 20
}

// Implicitly synthesized method here
// CHECK-LABEL: define internal i32 @"\01-[SuperClass superClassProperty]"
// CHECK: getelementptr inbounds i8, ptr %0, i64 24

// CHECK-LABEL: define internal void @"\01-[SuperClass setSuperClassProperty:]"
// CHECK: getelementptr inbounds i8, ptr %1, i64 24
@end

@interface IntermediateClass : SuperClass {
double intermediateClassIvar;

@protected
int intermediateClassIvar2;
}
@property (nonatomic, strong) SuperClass *intermediateProperty;
@end

@implementation IntermediateClass
@synthesize intermediateProperty = _intermediateProperty;

// CHECK-LABEL: define internal void @"\01-[IntermediateClass intermediateClassMethod]"
- (void)intermediateClassMethod {
intermediateClassIvar = 3.14;
// CHECK-NOT: load i64, ptr @"OBJC_IVAR_$_IntermediateClass
// CHECK: getelementptr inbounds i8, ptr %0, i64 32
}

// CHECK-LABEL: define internal void @"\01-[IntermediateClass intermediateClassPropertyMethod]"
- (void)intermediateClassPropertyMethod {
self.intermediateProperty = 0;
// CHECK: load ptr, ptr @OBJC_SELECTOR_REFERENCES_
// CHECK: call void @objc_msgSend(ptr noundef %0, ptr noundef %1, ptr noundef null)
}

// CHECK-LABEL: define internal void @"\01-[IntermediateClass intermediateClassPropertyMethodDirect]"
- (void)intermediateClassPropertyMethodDirect {
_intermediateProperty = 0;
// CHECK-NOT: load i64, ptr @"OBJC_IVAR_$_IntermediateClass._intermediateProperty"
// CHECK: getelementptr inbounds i8, ptr %0, i64 48
}
@end

@interface SubClass : IntermediateClass {
double subClassIvar;
}
@property (nonatomic, assign) SubClass *subClassProperty;
@end

@implementation SubClass

// CHECK-LABEL: define internal void @"\01-[SubClass subclassVar]"
- (void)subclassVar {
subClassIvar = 6.28;
// CHECK-NOT: load i64, ptr @"OBJC_IVAR_$_SubClass
// CHECK: getelementptr inbounds i8, ptr %0, i64 56
}

// CHECK-LABEL: define internal void @"\01-[SubClass intermediateSubclassVar]"
-(void)intermediateSubclassVar {
intermediateClassIvar = 3.14;
// CHECK-NOT: load i64, ptr @"OBJC_IVAR_$_IntermediateClass
// CHECK: getelementptr inbounds i8, ptr %0, i64 32
}

// Implicit synthesized method here:
// CHECK-LABEL: define internal ptr @"\01-[SubClass subClassProperty]"
// CHECK-NOT: load i64, ptr @"OBJC_IVAR_$_SubClass._subClassProperty"
// CHECK: getelementptr inbounds i8, ptr %0, i64 64

// CHECK-LABEL: define internal void @"\01-[SubClass setSubClassProperty:]"
// CHECK-NOT: load i64, ptr @"OBJC_IVAR_$_SubClass._subClassProperty"
// CHECK: getelementptr inbounds i8, ptr %1, i64 64
@end

@interface NotNSObject {
int these, might, change;
}
Expand All @@ -31,6 +131,8 @@ @interface NotStaticLayout : NotNSObject
@implementation NotStaticLayout {
int not_static_layout_ivar;
}

// CHECK-LABEL: define internal void @"\01-[NotStaticLayout meth]"
-(void)meth {
not_static_layout_ivar = 0;
// CHECK: load i64, ptr @"OBJC_IVAR_$_NotStaticLayout.not_static_layout_ivar
Expand Down
4 changes: 4 additions & 0 deletions clang/test/Driver/freebsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,7 @@
// RELOCATABLE-NOT: "-l
// RELOCATABLE-NOT: crt{{[^./\\]+}}.o

// Check that the -X and --no-relax flags are passed to the linker on riscv64
// RUN: %clang --target=riscv64-unknown-freebsd -mno-relax -### %s 2>&1 \
// RUN: | FileCheck -check-prefix=RISCV64-FLAGS %s
// RISCV64-FLAGS: "-X" "--no-relax"
5 changes: 5 additions & 0 deletions clang/test/Driver/fuchsia.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,8 @@
// RUN: | FileCheck %s -check-prefix=CHECK-PROFRT-X86_64
// CHECK-PROFRT-X86_64: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
// CHECK-PROFRT-X86_64: "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}x86_64-unknown-fuchsia{{/|\\\\}}libclang_rt.profile.a"

// Check that the -X and --no-relax flags are passed to the linker on riscv64
// RUN: %clang --target=riscv64-unknown-fuchsia -mno-relax -### %s 2>&1 \
// RUN: | FileCheck -check-prefix=RISCV64-FLAGS %s
// RISCV64-FLAGS: "-X" "--no-relax"
5 changes: 5 additions & 0 deletions clang/test/Driver/haiku.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@
// RUN: | FileCheck --check-prefix=CHECK-ARM-CPU %s
// CHECK-ARM-CPU: "-target-cpu" "arm1176jzf-s"

// Check that the -X and --no-relax flags are passed to the linker on riscv64
// RUN: %clang --target=riscv64-unknown-haiku -mno-relax -### %s 2>&1 \
// RUN: | FileCheck -check-prefix=RISCV64-FLAGS %s
// RISCV64-FLAGS: "-X" "--no-relax"

// Check passing LTO flags to the linker
// RUN: %clang --target=x86_64-unknown-haiku -flto -### %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-LTO-FLAGS %s
Expand Down
7 changes: 7 additions & 0 deletions clang/test/Driver/netbsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,10 @@
// DRIVER-PASS-INCLUDES: "-cc1" {{.*}}"-resource-dir" "[[RESOURCE:[^"]+]]"
// DRIVER-PASS-INCLUDES-SAME: "-internal-isystem" "[[RESOURCE]]{{/|\\\\}}include"
// DRIVER-PASS-INCLUDES-SAME: {{^}} "-internal-externc-isystem" "{{.*}}/usr/include"

// Check that the -X and --no-relax flags are passed to the linker on riscv
// RUN: %clang --target=riscv32-unknown-netbsd -mno-relax -### %s 2>&1 \
// RUN: | FileCheck -check-prefix=RISCV-FLAGS %s
// RUN: %clang --target=riscv64-unknown-netbsd -mno-relax -### %s 2>&1 \
// RUN: | FileCheck -check-prefix=RISCV-FLAGS %s
// RISCV-FLAGS: "-X" "--no-relax"
8 changes: 4 additions & 4 deletions clang/test/Driver/openbsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@
// UNWIND-TABLES: "-funwind-tables=2"
// NO-UNWIND-TABLES-NOT: "-funwind-tables=2"

// Check that the -X flag is passed to the linker on riscv64
// RUN: %clang --target=riscv64-unknown-openbsd -### %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-RISCV64-FLAGS %s
// CHECK-RISCV64-FLAGS: "-X"
// Check that the -X and --no-relax flags are passed to the linker on riscv64
// RUN: %clang --target=riscv64-unknown-openbsd -mno-relax -### %s 2>&1 \
// RUN: | FileCheck -check-prefix=RISCV64-FLAGS %s
// RISCV64-FLAGS: "-X" "--no-relax"

// Check passing LTO flags to the linker
// RUN: %clang --target=amd64-unknown-openbsd -flto -### %s 2>&1 \
Expand Down
65 changes: 62 additions & 3 deletions clang/test/InstallAPI/objcclasses.test
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,68 @@
@end

__attribute__((visibility("hidden")))
@interface Hidden
@interface Hidden
@end

__attribute__((visibility("hidden")))
@interface HiddenWithIvars {
@public
char _ivar;
}
@end

__attribute__((objc_exception))
@interface Exception
@end

@interface PublicClass : Visible {
@package
int _internal;
@protected
int _external;
@private
int private;
@public
char _public;
}
@end


//--- Foo.framework/PrivateHeaders/Foo_Private.h
#import <Foo/Foo.h>

@interface ClassWithIvars : Visible {
char _ivar1;
char _ivar2;
@private
int _privateIVar;
@protected
int _externalIVar;
@package
int _internalIVar;
}
@end

@interface Exception () {
@public
char _ivarFromExtension;
@private
int _privateIvarFromExtension;
}
@end


//--- inputs.json.in
{
"headers": [ {
"path" : "DSTROOT/Foo.framework/Headers/Foo.h",
"type" : "public"
}],
},
{
"path" : "DSTROOT/Foo.framework/PrivateHeaders/Foo_Private.h",
"type" : "private"
}
],
"version": "3"
}

Expand All @@ -53,11 +102,21 @@ __attribute__((objc_exception))
{
"data": {
"objc_class": [
"PublicClass",
"Exception",
"Visible"
"Visible",
"ClassWithIvars"
],
"objc_eh_type": [
"Exception"
],
"objc_ivar": [
"Exception._ivarFromExtension",
"ClassWithIvars._ivar2",
"PublicClass._external",
"ClassWithIvars._ivar1",
"ClassWithIvars._externalIVar",
"PublicClass._public"
]
}
}
Expand Down
7 changes: 0 additions & 7 deletions clang/test/Modules/Inputs/config.h

This file was deleted.

5 changes: 0 additions & 5 deletions clang/test/Modules/Inputs/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,6 @@ module cxx_decls_merged {
header "cxx-decls-merged.h"
}

module config {
header "config.h"
config_macros [exhaustive] WANT_FOO, WANT_BAR
}

module diag_flags {
header "diag_flags.h"
}
Expand Down
54 changes: 51 additions & 3 deletions clang/test/Modules/config_macros.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,50 @@
// This test verifies that config macro warnings are emitted when it looks like
// the user expected a `#define` to impact the import of a module.

// RUN: rm -rf %t
// RUN: split-file %s %t

// Prebuild the `config` module so it's in the module cache.
// RUN: %clang_cc1 -std=c99 -fmodules -fimplicit-module-maps -x objective-c -fmodules-cache-path=%t -DWANT_FOO=1 -emit-module -fmodule-name=config %t/module.modulemap

// Verify that each time the `config` module is imported the current macro state
// is checked.
// RUN: %clang_cc1 -std=c99 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %t -DWANT_FOO=1 %t/config.m -verify

// Verify that warnings are emitted before building a module in case the command
// line macro state causes the module to fail to build.
// RUN: %clang_cc1 -std=c99 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %t %t/config_error.m -verify

//--- module.modulemap

module config {
header "config.h"
config_macros [exhaustive] WANT_FOO, WANT_BAR
}

module config_error {
header "config_error.h"
config_macros SOME_VALUE
}

//--- config.h

#ifdef WANT_FOO
int* foo(void);
#endif

#ifdef WANT_BAR
char *bar(void);
#endif

//--- config_error.h

struct my_thing {
char buf[SOME_VALUE];
};

//--- config.m

@import config;

int *test_foo(void) {
Expand All @@ -22,7 +69,8 @@
#define WANT_BAR 1 // expected-note{{macro was defined here}}
@import config; // expected-warning{{definition of configuration macro 'WANT_BAR' has no effect on the import of 'config'; pass '-DWANT_BAR=...' on the command line to configure the module}}

// RUN: rm -rf %t
// RUN: %clang_cc1 -std=c99 -fmodules -fimplicit-module-maps -x objective-c -fmodules-cache-path=%t -DWANT_FOO=1 -emit-module -fmodule-name=config %S/Inputs/module.modulemap
// RUN: %clang_cc1 -std=c99 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs -DWANT_FOO=1 %s -verify
//--- config_error.m

#define SOME_VALUE 5 // expected-note{{macro was defined here}}
@import config_error; // expected-error{{could not build module}} \
// expected-warning{{definition of configuration macro 'SOME_VALUE' has no effect on the import of 'config_error';}}
9 changes: 9 additions & 0 deletions clang/test/Preprocessor/riscv-target-features.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
// CHECK-NOT: __riscv_smepmp {{.*$}}
// CHECK-NOT: __riscv_ssaia {{.*$}}
// CHECK-NOT: __riscv_ssccptr {{.*$}}
// CHECK-NOT: __riscv_sscofpmf {{.*$}}
// CHECK-NOT: __riscv_sscounterenw {{.*$}}
// CHECK-NOT: __riscv_ssstateen {{.*$}}
// CHECK-NOT: __riscv_ssstrict {{.*$}}
Expand Down Expand Up @@ -351,6 +352,14 @@
// RUN: -o - | FileCheck --check-prefix=CHECK-SSCCPTR-EXT %s
// CHECK-SSCCPTR-EXT: __riscv_ssccptr 1000000{{$}}

// RUN: %clang --target=riscv32-unknown-linux-gnu \
// RUN: -march=rv32isscofpmf -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-SSCOFPMF-EXT %s
// RUN: %clang --target=riscv64-unknown-linux-gnu \
// RUN: -march=rv64isscofpmf -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-SSCOFPMF-EXT %s
// CHECK-SSCOFPMF-EXT: __riscv_sscofpmf 1000000{{$}}

// RUN: %clang --target=riscv32-unknown-linux-gnu \
// RUN: -march=rv32isscounterenw -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-SSCOUNTERENW-EXT %s
Expand Down
100 changes: 50 additions & 50 deletions clang/test/Sema/integer-overflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,169 +11,169 @@ uint64_t f0(uint64_t);
uint64_t f1(uint64_t, uint32_t);
uint64_t f2(uint64_t, ...);

static const uint64_t overflow = 1 * 4608 * 1024 * 1024; // expected-warning {{overflow in expression; result is 536870912 with type 'int'}}
static const uint64_t overflow = 1 * 4608 * 1024 * 1024; // expected-warning {{overflow in expression; result is 536'870'912 with type 'int'}}

uint64_t check_integer_overflows(int i) {
// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
uint64_t overflow = 4608 * 1024 * 1024,
// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
overflow2 = (uint64_t)(4608 * 1024 * 1024),
// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
overflow3 = (uint64_t)(4608 * 1024 * 1024 * i),
// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
overflow4 = (1ULL * ((4608) * ((1024) * (1024))) + 2ULL),
// expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 2{{overflow in expression; result is 536'870'912 with type 'int'}}
multi_overflow = (uint64_t)((uint64_t)(4608 * 1024 * 1024) * (uint64_t)(4608 * 1024 * 1024));

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
overflow += overflow2 = overflow3 = (uint64_t)(4608 * 1024 * 1024);
// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
overflow += overflow2 = overflow3 = 4608 * 1024 * 1024;

uint64_t not_overflow = 4608 * 1024 * 1024ULL;
uint64_t not_overflow2 = (1ULL * ((uint64_t)(4608) * (1024 * 1024)) + 2ULL);

// expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 2{{overflow in expression; result is 536'870'912 with type 'int'}}
overflow = 4608 * 1024 * 1024 ? 4608 * 1024 * 1024 : 0;

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
overflow = 0 ? 0 : 4608 * 1024 * 1024;

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
if (4608 * 1024 * 1024)
return 0;

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
if ((uint64_t)(4608 * 1024 * 1024))
return 1;

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
if ((uint64_t)(4608 * 1024 * 1024))
return 2;

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
if ((uint64_t)(4608 * 1024 * 1024 * i))
return 3;

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
if ((1ULL * ((4608) * ((1024) * (1024))) + 2ULL))
return 4;

// expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 2{{overflow in expression; result is 536'870'912 with type 'int'}}
if ((uint64_t)((uint64_t)(4608 * 1024 * 1024) * (uint64_t)(4608 * 1024 * 1024)))
return 5;

switch (i) {
// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
case 4608 * 1024 * 1024:
return 6;
// expected-warning@+1 {{overflow in expression; result is 537919488 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 537'919'488 with type 'int'}}
case (uint64_t)(4609 * 1024 * 1024):
return 7;
// expected-error@+1 {{expression is not an integer constant expression}}
case ((uint64_t)(4608 * 1024 * 1024 * i)):
return 8;
// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
case ((1ULL * ((4608) * ((1024) * (1024))) + 2ULL)):
return 9;
// expected-warning@+2 2{{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+2 2{{overflow in expression; result is 536'870'912 with type 'int'}}
// expected-warning@+1 {{overflow converting case value to switch condition type (288230376151711744 to 0)}}
case ((uint64_t)((uint64_t)(4608 * 1024 * 1024) * (uint64_t)(4608 * 1024 * 1024))):
return 10;
}

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
while (4608 * 1024 * 1024);

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
while ((uint64_t)(4608 * 1024 * 1024));

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
while ((uint64_t)(4608 * 1024 * 1024));

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
while ((uint64_t)(4608 * 1024 * 1024 * i));

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
while ((1ULL * ((4608) * ((1024) * (1024))) + 2ULL));

// expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 2{{overflow in expression; result is 536'870'912 with type 'int'}}
while ((uint64_t)((uint64_t)(4608 * 1024 * 1024) * (uint64_t)(4608 * 1024 * 1024)));

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
do { } while (4608 * 1024 * 1024);

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
do { } while ((uint64_t)(4608 * 1024 * 1024));

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
do { } while ((uint64_t)(4608 * 1024 * 1024));

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
do { } while ((uint64_t)(4608 * 1024 * 1024 * i));

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
do { } while ((1ULL * ((4608) * ((1024) * (1024))) + 2ULL));

// expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 2{{overflow in expression; result is 536'870'912 with type 'int'}}
do { } while ((uint64_t)((uint64_t)(4608 * 1024 * 1024) * (uint64_t)(4608 * 1024 * 1024)));

// expected-warning@+3 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+3 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+3 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+3 {{overflow in expression; result is 536'870'912 with type 'int'}}
// expected-warning@+3 {{overflow in expression; result is 536'870'912 with type 'int'}}
// expected-warning@+3 {{overflow in expression; result is 536'870'912 with type 'int'}}
for (uint64_t i = 4608 * 1024 * 1024;
(uint64_t)(4608 * 1024 * 1024);
i += (uint64_t)(4608 * 1024 * 1024 * i));

// expected-warning@+3 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+3 2{{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+3 2{{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+3 {{overflow in expression; result is 536'870'912 with type 'int'}}
// expected-warning@+3 2{{overflow in expression; result is 536'870'912 with type 'int'}}
// expected-warning@+3 2{{overflow in expression; result is 536'870'912 with type 'int'}}
for (uint64_t i = (1ULL * ((4608) * ((1024) * (1024))) + 2ULL);
((uint64_t)((uint64_t)(4608 * 1024 * 1024) * (uint64_t)(4608 * 1024 * 1024)));
i = ((4608 * 1024 * 1024) + ((uint64_t)(4608 * 1024 * 1024))));

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
_Complex long long x = 4608 * 1024 * 1024;

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
(__real__ x) = 4608 * 1024 * 1024;

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
(__imag__ x) = 4608 * 1024 * 1024;

// expected-warning@+4 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+4 {{overflow in expression; result is 536'870'912 with type 'int'}}
// expected-warning@+3 {{array index 536870912 is past the end of the array (that has type 'uint64_t[10]' (aka 'unsigned long long[10]'))}}
// expected-note@+1 {{array 'a' declared here}}
uint64_t a[10];
a[4608 * 1024 * 1024] = 1i;

// expected-warning@+2 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+2 {{overflow in expression; result is 536'870'912 with type 'int'}}
uint64_t *b;
uint64_t b2 = b[4608 * 1024 * 1024] + 1;

// expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 2{{overflow in expression; result is 536'870'912 with type 'int'}}
(void)((i ? (4608 * 1024 * 1024) : (4608 * 1024 * 1024)) + 1);

// expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 2{{overflow in expression; result is 536'870'912 with type 'int'}}
return ((4608 * 1024 * 1024) + ((uint64_t)(4608 * 1024 * 1024)));
}

void check_integer_overflows_in_function_calls(void) {
// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
(void)f0(4608 * 1024 * 1024);

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
uint64_t x = f0(4608 * 1024 * 1024);

// expected-warning@+2 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+2 {{overflow in expression; result is 536'870'912 with type 'int'}}
uint64_t (*f0_ptr)(uint64_t) = &f0;
(void)(*f0_ptr)(4608 * 1024 * 1024);

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
(void)f2(0, f0(4608 * 1024 * 1024));
}
void check_integer_overflows_in_array_size(void) {
int arr[4608 * 1024 * 1024]; // expected-warning {{overflow in expression; result is 536870912 with type 'int'}}
int arr[4608 * 1024 * 1024]; // expected-warning {{overflow in expression; result is 536'870'912 with type 'int'}}
}

struct s {
Expand Down
9 changes: 5 additions & 4 deletions clang/test/Sema/static-assert.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: %clang_cc1 -std=c11 -Wgnu-folding-constant -fsyntax-only -verify %s
// RUN: %clang_cc1 -fms-compatibility -Wgnu-folding-constant -DMS -fsyntax-only -verify=expected,ms %s
// RUN: %clang_cc1 -std=c99 -pedantic -Wgnu-folding-constant -fsyntax-only -verify=expected,ext %s
// RUN: %clang_cc1 -std=c11 -Wgnu-folding-constant -fsyntax-only -verify=expected,c %s
// RUN: %clang_cc1 -fms-compatibility -Wgnu-folding-constant -DMS -fsyntax-only -verify=expected,ms,c %s
// RUN: %clang_cc1 -std=c99 -pedantic -Wgnu-folding-constant -fsyntax-only -verify=expected,ext,c %s
// RUN: %clang_cc1 -xc++ -std=c++11 -pedantic -fsyntax-only -verify=expected,ext,cxx %s

_Static_assert("foo", "string is nonzero"); // ext-warning {{'_Static_assert' is a C11 extension}}
Expand Down Expand Up @@ -57,7 +57,8 @@ UNION(char[2], short) u2 = { .one = { 'a', 'b' } }; // ext-warning 3 {{'_Static_
typedef UNION(char, short) U3; // expected-error {{static assertion failed due to requirement 'sizeof(char) == sizeof(short)': type size mismatch}} \
// expected-note{{evaluates to '1 == 2'}} \
// ext-warning 3 {{'_Static_assert' is a C11 extension}}
typedef UNION(float, 0.5f) U4; // expected-error {{expected a type}} \
typedef UNION(float, 0.5f) U4; // c-error {{expected a type}} \
// cxx-error {{type name requires a specifier or qualifier}} \
// ext-warning 3 {{'_Static_assert' is a C11 extension}}

// After defining the assert macro in MS-compatibility mode, we should
Expand Down
6 changes: 3 additions & 3 deletions clang/test/Sema/switch-1.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ int f(int i) {
switch (i) {
case 2147483647 + 2:
#if (__cplusplus <= 199711L) // C or C++03 or earlier modes
// expected-warning@-2 {{overflow in expression; result is -2147483647 with type 'int'}}
// expected-warning@-2 {{overflow in expression; result is -2'147'483'647 with type 'int'}}
#else
// expected-error@-4 {{case value is not a constant expression}} \
// expected-note@-4 {{value 2147483649 is outside the range of representable values of type 'int'}}
Expand All @@ -23,7 +23,7 @@ int f(int i) {
return 2;
case (123456 *789012) + 1:
#if (__cplusplus <= 199711L)
// expected-warning@-2 {{overflow in expression; result is -1375982336 with type 'int'}}
// expected-warning@-2 {{overflow in expression; result is -1'375'982'336 with type 'int'}}
#else
// expected-error@-4 {{case value is not a constant expression}} \
// expected-note@-4 {{value 97408265472 is outside the range of representable values of type 'int'}}
Expand All @@ -47,7 +47,7 @@ int f(int i) {
case 2147483647:
return 0;
}
return (i, 65537) * 65537; // expected-warning {{overflow in expression; result is 131073 with type 'int'}} \
return (i, 65537) * 65537; // expected-warning {{overflow in expression; result is 131'073 with type 'int'}} \
// expected-warning {{left operand of comma operator has no effect}}
}

Expand Down
15 changes: 15 additions & 0 deletions clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,18 @@ namespace GH62224 {
C<> Val; // No error since fwd is defined already.
static_assert(Val.get() == 42);
}

namespace GH80630 {

consteval const char* ce() { return "Hello"; }

auto f2(const char* loc = []( char const* fn )
{ return fn; } ( ce() ) ) {
return loc;
}

auto g() {
return f2();
}

}
11 changes: 6 additions & 5 deletions clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
// RUN: %clang_cc1 -std=c++20 %s -verify=cxx20,expected,reorder -Wno-c99-designator -Werror=reorder-init-list -Wno-initializer-overrides
// RUN: %clang_cc1 -std=c++20 %s -verify=cxx20,expected,override -Wno-c99-designator -Wno-reorder-init-list -Werror=initializer-overrides
// RUN: %clang_cc1 -std=c++20 %s -verify=cxx20,expected -Wno-c99-designator -Wno-reorder-init-list -Wno-initializer-overrides
// RUN: %clang_cc1 -std=c++20 %s -verify=cxx20,expected,wmissing -Wmissing-field-initializers -Wno-c99-designator -Wno-reorder-init-list -Wno-initializer-overrides
// RUN: %clang_cc1 -std=c++20 %s -verify=cxx20,expected,wmissing,wmissing-designated -Wmissing-field-initializers -Wno-c99-designator -Wno-reorder-init-list -Wno-initializer-overrides
// RUN: %clang_cc1 -std=c++20 %s -verify=cxx20,expected,wmissing -Wmissing-field-initializers -Wno-missing-designated-field-initializers -Wno-c99-designator -Wno-reorder-init-list -Wno-initializer-overrides


namespace class_with_ctor {
Expand Down Expand Up @@ -50,11 +51,11 @@ A a3 = {
A a4 = {
.x = 1, // override-note {{previous}}
.x = 1 // override-error {{overrides prior initialization}}
}; // wmissing-warning {{missing field 'y' initializer}}
}; // wmissing-designated-warning {{missing field 'y' initializer}}
A a5 = {
.y = 1, // override-note {{previous}}
.y = 1 // override-error {{overrides prior initialization}}
}; // wmissing-warning {{missing field 'x' initializer}}
}; // wmissing-designated-warning {{missing field 'x' initializer}}
B b2 = {.a = 1}; // pedantic-error {{brace elision for designated initializer is a C99 extension}}
// wmissing-warning@-1 {{missing field 'y' initializer}}
B b3 = {.a = 1, 2}; // pedantic-error {{mixture of designated and non-designated}} pedantic-note {{first non-designated}} pedantic-error {{brace elision}}
Expand All @@ -74,8 +75,8 @@ C c = {
struct Foo { int a, b; };

struct Foo foo0 = { 1 }; // wmissing-warning {{missing field 'b' initializer}}
struct Foo foo1 = { .a = 1 }; // wmissing-warning {{missing field 'b' initializer}}
struct Foo foo2 = { .b = 1 }; // wmissing-warning {{missing field 'a' initializer}}
struct Foo foo1 = { .a = 1 }; // wmissing-designated-warning {{missing field 'b' initializer}}
struct Foo foo2 = { .b = 1 }; // wmissing-designated-warning {{missing field 'a' initializer}}

}

Expand Down
4 changes: 2 additions & 2 deletions clang/test/SemaCXX/enum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ enum { overflow = 123456 * 234567 };
// expected-warning@-2 {{not an integral constant expression}}
// expected-note@-3 {{value 28958703552 is outside the range of representable values}}
#else
// expected-warning@-5 {{overflow in expression; result is -1106067520 with type 'int'}}
// expected-warning@-5 {{overflow in expression; result is -1'106'067'520 with type 'int'}}
#endif

// FIXME: This is not consistent with the above case.
Expand All @@ -112,7 +112,7 @@ enum NoFold : int { overflow2 = 123456 * 234567 };
// expected-error@-2 {{enumerator value is not a constant expression}}
// expected-note@-3 {{value 28958703552 is outside the range of representable values}}
#else
// expected-warning@-5 {{overflow in expression; result is -1106067520 with type 'int'}}
// expected-warning@-5 {{overflow in expression; result is -1'106'067'520 with type 'int'}}
// expected-warning@-6 {{extension}}
#endif

Expand Down
112 changes: 56 additions & 56 deletions clang/test/SemaCXX/integer-overflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,180 +13,180 @@ uint64_t f0(uint64_t);
uint64_t f1(uint64_t, uint32_t);
uint64_t f2(uint64_t, ...);

static const uint64_t overflow = 1 * 4608 * 1024 * 1024; // expected-warning {{overflow in expression; result is 536870912 with type 'int'}}
static const uint64_t overflow = 1 * 4608 * 1024 * 1024; // expected-warning {{overflow in expression; result is 536'870'912 with type 'int'}}

uint64_t check_integer_overflows(int i) { //expected-note 0+{{declared here}}
// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
uint64_t overflow = 4608 * 1024 * 1024,
// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
overflow2 = (uint64_t)(4608 * 1024 * 1024),
// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
overflow3 = (uint64_t)(4608 * 1024 * 1024 * i),
// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
overflow4 = (1ULL * ((4608) * ((1024) * (1024))) + 2ULL),
// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
overflow5 = static_cast<uint64_t>(4608 * 1024 * 1024),
// expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 2{{overflow in expression; result is 536'870'912 with type 'int'}}
multi_overflow = (uint64_t)((uint64_t)(4608 * 1024 * 1024) * (uint64_t)(4608 * 1024 * 1024));

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
overflow += overflow2 = overflow3 = (uint64_t)(4608 * 1024 * 1024);
// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
overflow += overflow2 = overflow3 = 4608 * 1024 * 1024;

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
overflow += overflow2 = overflow3 = static_cast<uint64_t>(4608 * 1024 * 1024);

uint64_t not_overflow = 4608 * 1024 * 1024ULL;
uint64_t not_overflow2 = (1ULL * ((uint64_t)(4608) * (1024 * 1024)) + 2ULL);

// expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 2{{overflow in expression; result is 536'870'912 with type 'int'}}
overflow = 4608 * 1024 * 1024 ? 4608 * 1024 * 1024 : 0;

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
overflow = 0 ? 0 : 4608 * 1024 * 1024;

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
if (4608 * 1024 * 1024)
return 0;

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
if ((uint64_t)(4608 * 1024 * 1024))
return 1;

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
if (static_cast<uint64_t>(4608 * 1024 * 1024))
return 1;

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
if ((uint64_t)(4608 * 1024 * 1024))
return 2;

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
if ((uint64_t)(4608 * 1024 * 1024 * i))
return 3;

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
if ((1ULL * ((4608) * ((1024) * (1024))) + 2ULL))
return 4;

// expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 2{{overflow in expression; result is 536'870'912 with type 'int'}}
if ((uint64_t)((uint64_t)(4608 * 1024 * 1024) * (uint64_t)(4608 * 1024 * 1024)))
return 5;

#if __cplusplus < 201103L
switch (i) {
// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
case 4608 * 1024 * 1024:
return 6;
// expected-warning@+1 {{overflow in expression; result is 537919488 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 537'919'488 with type 'int'}}
case (uint64_t)(4609 * 1024 * 1024):
return 7;
// expected-warning@+1 {{overflow in expression; result is 537919488 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 537'919'488 with type 'int'}}
case 1 + static_cast<uint64_t>(4609 * 1024 * 1024):
return 7;
// expected-error@+1 {{expression is not an integral constant expression}}
case ((uint64_t)(4608 * 1024 * 1024 * i)):
return 8;
// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
case ((1ULL * ((4608) * ((1024) * (1024))) + 2ULL)):
return 9;
// expected-warning@+2 2{{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+2 2{{overflow in expression; result is 536'870'912 with type 'int'}}
// expected-warning@+1 {{overflow converting case value to switch condition type (288230376151711744 to 0)}}
case ((uint64_t)((uint64_t)(4608 * 1024 * 1024) * (uint64_t)(4608 * 1024 * 1024))):
return 10;
}
#endif

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
while (4608 * 1024 * 1024);

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
while ((uint64_t)(4608 * 1024 * 1024));

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
while (static_cast<uint64_t>(4608 * 1024 * 1024));

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
while ((uint64_t)(4608 * 1024 * 1024));

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
while ((uint64_t)(4608 * 1024 * 1024 * i));

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
while ((1ULL * ((4608) * ((1024) * (1024))) + 2ULL));

// expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 2{{overflow in expression; result is 536'870'912 with type 'int'}}
while ((uint64_t)((uint64_t)(4608 * 1024 * 1024) * (uint64_t)(4608 * 1024 * 1024)));

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
do { } while (4608 * 1024 * 1024);

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
do { } while ((uint64_t)(4608 * 1024 * 1024));

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
do { } while (static_cast<uint64_t>(4608 * 1024 * 1024));

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
do { } while ((uint64_t)(4608 * 1024 * 1024));

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
do { } while ((uint64_t)(4608 * 1024 * 1024 * i));

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
do { } while ((1ULL * ((4608) * ((1024) * (1024))) + 2ULL));

// expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 2{{overflow in expression; result is 536'870'912 with type 'int'}}
do { } while ((uint64_t)((uint64_t)(4608 * 1024 * 1024) * (uint64_t)(4608 * 1024 * 1024)));

// expected-warning@+3 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+3 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+3 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+3 {{overflow in expression; result is 536'870'912 with type 'int'}}
// expected-warning@+3 {{overflow in expression; result is 536'870'912 with type 'int'}}
// expected-warning@+3 {{overflow in expression; result is 536'870'912 with type 'int'}}
for (uint64_t i = 4608 * 1024 * 1024;
(uint64_t)(4608 * 1024 * 1024);
i += (uint64_t)(4608 * 1024 * 1024 * i));

// expected-warning@+3 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+3 2{{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+3 2{{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+3 {{overflow in expression; result is 536'870'912 with type 'int'}}
// expected-warning@+3 2{{overflow in expression; result is 536'870'912 with type 'int'}}
// expected-warning@+3 2{{overflow in expression; result is 536'870'912 with type 'int'}}
for (uint64_t i = (1ULL * ((4608) * ((1024) * (1024))) + 2ULL);
((uint64_t)((uint64_t)(4608 * 1024 * 1024) * (uint64_t)(4608 * 1024 * 1024)));
i = ((4608 * 1024 * 1024) + ((uint64_t)(4608 * 1024 * 1024))));

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
_Complex long long x = 4608 * 1024 * 1024;

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
(__real__ x) = 4608 * 1024 * 1024;

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
(__imag__ x) = 4608 * 1024 * 1024;

// expected-warning@+2 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+2 {{overflow in expression; result is 536'870'912 with type 'int'}}
uint64_t a[10];
a[4608 * 1024 * 1024] = 1;
#if __cplusplus < 201103L
// expected-warning@-2 {{array index 536870912 is past the end of the array (that has type 'uint64_t[10]' (aka 'unsigned long long[10]'))}}
// expected-note@-4 {{array 'a' declared here}}
#endif

// expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 2{{overflow in expression; result is 536'870'912 with type 'int'}}
return ((4608 * 1024 * 1024) + ((uint64_t)(4608 * 1024 * 1024)));
}

void check_integer_overflows_in_function_calls() {
// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
(void)f0(4608 * 1024 * 1024);

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
uint64_t x = f0(4608 * 1024 * 1024);

// expected-warning@+2 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+2 {{overflow in expression; result is 536'870'912 with type 'int'}}
uint64_t (*f0_ptr)(uint64_t) = &f0;
(void)(*f0_ptr)(4608 * 1024 * 1024);

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
(void)f2(0, f0(4608 * 1024 * 1024));
}

Expand All @@ -211,7 +211,7 @@ namespace EvaluationCrashes {

namespace GH31643 {
void f() {
int a = -(1<<31); // expected-warning {{overflow in expression; result is -2147483648 with type 'int'}}
int a = -(1<<31); // expected-warning {{overflow in expression; result is -2'147'483'648 with type 'int'}}
}
}

Expand All @@ -237,8 +237,8 @@ u_ptr<bool> Wrap(int64_t x) {
int64_t Pass(int64_t x) { return x; }

int m() {
int64_t x = Pass(30 * 24 * 60 * 59 * 1000); // expected-warning {{overflow in expression; result is -1746167296 with type 'int'}}
auto r = Wrap(Pass(30 * 24 * 60 * 59 * 1000)); // expected-warning {{overflow in expression; result is -1746167296 with type 'int'}}
int64_t x = Pass(30 * 24 * 60 * 59 * 1000); // expected-warning {{overflow in expression; result is -1'746'167'296 with type 'int'}}
auto r = Wrap(Pass(30 * 24 * 60 * 59 * 1000)); // expected-warning {{overflow in expression; result is -1'746'167'296 with type 'int'}}
return 0;
}
}
Expand Down
18 changes: 18 additions & 0 deletions clang/test/SemaCXX/source_location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -832,3 +832,21 @@ void test() {
}

}

namespace GH80630 {

#define GH80630_LAMBDA \
[]( char const* fn ) { \
static constexpr std::source_location loc = std::source_location::current(); \
return &loc; \
}( std::source_location::current().function() )

auto f( std::source_location const* loc = GH80630_LAMBDA ) {
return loc;
}

auto g() {
return f();
}

}
3 changes: 3 additions & 0 deletions clang/test/SemaCXX/type-traits-nonobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
static_assert(!__is_pod(void), "");
static_assert(!__is_pod(int&), "");
static_assert(!__is_pod(int()), "");
static_assert(!__is_pod(int()&), "");

static_assert(!__is_trivially_copyable(void), "");
static_assert(!__is_trivially_copyable(int&), "");
static_assert(!__is_trivially_copyable(int()), "");
static_assert(!__is_trivially_copyable(int()&), "");

static_assert(!__is_trivially_relocatable(void), "");
static_assert(!__is_trivially_relocatable(int&), "");
static_assert(!__is_trivially_relocatable(int()), "");
static_assert(!__is_trivially_relocatable(int()&), "");
15 changes: 15 additions & 0 deletions clang/test/SemaCXX/warn-unsequenced-paren-list-init.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// RUN: %clang_cc1 -fsyntax-only -std=c++20 -Wno-unused -Wunsequenced -verify %s

struct A {
int x, y;
};

void test() {
int a = 0;

A agg1( a++, a++ ); // no warning
A agg2( a++ + a, a++ ); // expected-warning {{unsequenced modification and access to 'a'}}

int arr1[]( a++, a++ ); // no warning
int arr2[]( a++ + a, a++ ); // expected-warning {{unsequenced modification and access to 'a'}}
}
12 changes: 12 additions & 0 deletions clang/test/SemaHLSL/BuiltIns/any-errors.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm -disable-llvm-passes -verify -verify-ignore-unexpected

bool test_too_few_arg() {
return __builtin_hlsl_elementwise_any();
// expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
}

bool test_too_many_arg(float2 p0) {
return __builtin_hlsl_elementwise_any(p0, p0);
// expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
}
27 changes: 27 additions & 0 deletions clang/test/SemaHLSL/BuiltIns/exp-errors.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm -disable-llvm-passes -verify -verify-ignore-unexpected -DTEST_FUNC=__builtin_elementwise_exp
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm -disable-llvm-passes -verify -verify-ignore-unexpected -DTEST_FUNC=__builtin_elementwise_exp2
float test_too_few_arg() {
return TEST_FUNC();
// expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
}

float2 test_too_many_arg(float2 p0) {
return TEST_FUNC(p0, p0);
// expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
}

float builtin_bool_to_float_type_promotion(bool p1) {
return TEST_FUNC(p1);
// expected-error@-1 {{1st argument must be a vector, integer or floating point type (was 'bool')}}
}

float builtin_exp_int_to_float_promotion(int p1) {
return TEST_FUNC(p1);
// expected-error@-1 {{1st argument must be a floating point type (was 'int')}}
}

float2 builtin_exp_int2_to_float2_promotion(int2 p1) {
return TEST_FUNC(p1);
// expected-error@-1 {{1st argument must be a floating point type (was 'int2' (aka 'vector<int, 2>'))}}
}
86 changes: 86 additions & 0 deletions clang/test/SemaHLSL/BuiltIns/mad-errors.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm -disable-llvm-passes -verify -verify-ignore-unexpected

float2 test_no_second_arg(float2 p0) {
return __builtin_hlsl_mad(p0);
// expected-error@-1 {{too few arguments to function call, expected 3, have 1}}
}

float2 test_no_third_arg(float2 p0) {
return __builtin_hlsl_mad(p0, p0);
// expected-error@-1 {{too few arguments to function call, expected 3, have 2}}
}

float2 test_too_many_arg(float2 p0) {
return __builtin_hlsl_mad(p0, p0, p0, p0);
// expected-error@-1 {{too many arguments to function call, expected 3, have 4}}
}

float2 test_mad_no_second_arg(float2 p0) {
return mad(p0);
// expected-error@-1 {{no matching function for call to 'mad'}}
}

float2 test_mad_vector_size_mismatch(float3 p0, float2 p1) {
return mad(p0, p0, p1);
// expected-warning@-1 {{implicit conversion truncates vector: 'float3' (aka 'vector<float, 3>') to 'float __attribute__((ext_vector_type(2)))' (vector of 2 'float' values)}}
}

float2 test_mad_builtin_vector_size_mismatch(float3 p0, float2 p1) {
return __builtin_hlsl_mad(p0, p1, p1);
// expected-error@-1 {{all arguments to '__builtin_hlsl_mad' must have the same type}}
}

float test_mad_scalar_mismatch(float p0, half p1) {
return mad(p1, p0, p1);
// expected-error@-1 {{call to 'mad' is ambiguous}}
}

float2 test_mad_element_type_mismatch(half2 p0, float2 p1) {
return mad(p1, p0, p1);
// expected-error@-1 {{call to 'mad' is ambiguous}}
}

float2 test_builtin_mad_float2_splat(float p0, float2 p1) {
return __builtin_hlsl_mad(p0, p1, p1);
// expected-error@-1 {{all arguments to '__builtin_hlsl_mad' must be vectors}}
}

float3 test_builtin_mad_float3_splat(float p0, float3 p1) {
return __builtin_hlsl_mad(p0, p1, p1);
// expected-error@-1 {{all arguments to '__builtin_hlsl_mad' must be vectors}}
}

float4 test_builtin_mad_float4_splat(float p0, float4 p1) {
return __builtin_hlsl_mad(p0, p1, p1);
// expected-error@-1 {{all arguments to '__builtin_hlsl_mad' must be vectors}}
}

float2 test_mad_float2_int_splat(float2 p0, int p1) {
return __builtin_hlsl_mad(p0, p1, p1);
// expected-error@-1 {{all arguments to '__builtin_hlsl_mad' must be vectors}}
}

float3 test_mad_float3_int_splat(float3 p0, int p1) {
return __builtin_hlsl_mad(p0, p1, p1);
// expected-error@-1 {{all arguments to '__builtin_hlsl_mad' must be vectors}}
}

float2 test_builtin_mad_int_vect_to_float_vec_promotion(int2 p0, float p1) {
return __builtin_hlsl_mad(p0, p1, p1);
// expected-error@-1 {{all arguments to '__builtin_hlsl_mad' must be vectors}}
}

float builtin_bool_to_float_type_promotion(float p0, bool p1) {
return __builtin_hlsl_mad(p0, p0, p1);
// expected-error@-1 {{3rd argument must be a vector, integer or floating point type (was 'bool')}}
}

float builtin_bool_to_float_type_promotion2(bool p0, float p1) {
return __builtin_hlsl_mad(p1, p0, p1);
// expected-error@-1 {{2nd argument must be a vector, integer or floating point type (was 'bool')}}
}

float builtin_mad_int_to_float_promotion(float p0, int p1) {
return __builtin_hlsl_mad(p0, p0, p1);
// expected-error@-1 {{arguments are of different types ('double' vs 'int')}}
}
27 changes: 27 additions & 0 deletions clang/test/SemaHLSL/BuiltIns/rcp-errors.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm -disable-llvm-passes -verify -verify-ignore-unexpected

float test_too_few_arg() {
return __builtin_hlsl_elementwise_rcp();
// expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
}

float2 test_too_many_arg(float2 p0) {
return __builtin_hlsl_elementwise_rcp(p0, p0);
// expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
}

float builtin_bool_to_float_type_promotion(bool p1) {
return __builtin_hlsl_elementwise_rcp(p1);
// expected-error@-1 {{1st argument must be a vector, integer or floating point type (was 'bool')}}
}

float builtin_rcp_int_to_float_promotion(int p1) {
return __builtin_hlsl_elementwise_rcp(p1);
// expected-error@-1 {{passing 'int' to parameter of incompatible type 'float'}}
}

float2 builtin_rcp_int2_to_float2_promotion(int2 p1) {
return __builtin_hlsl_elementwise_rcp(p1);
// 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)}}
}
4 changes: 2 additions & 2 deletions clang/test/SemaObjC/integer-overflow.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ - (int)add:(int)a with:(int)b {
}

- (void)testIntegerOverflows {
// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
(void)[self add:0 with:4608 * 1024 * 1024];

// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
// expected-warning@+1 {{overflow in expression; result is 536'870'912 with type 'int'}}
(void)[self add:0 with:[self add:4608 * 1024 * 1024 with:0]];
}
@end
2 changes: 1 addition & 1 deletion clang/test/SemaObjC/objc-literal-nsnumber.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ int main(void) {
@-five; // expected-error{{@- must be followed by a number to form an NSNumber object}}
@+five; // expected-error{{@+ must be followed by a number to form an NSNumber object}}
NSNumber *av = @(1391126400000);
NSNumber *bv = @(1391126400 * 1000); // expected-warning {{overflow in expression; result is -443003904 with type 'int'}}
NSNumber *bv = @(1391126400 * 1000); // expected-warning {{overflow in expression; result is -443'003'904 with type 'int'}}
NSNumber *cv = @(big * thousand);
}

Expand Down
30 changes: 30 additions & 0 deletions clang/test/SemaTemplate/unqual-unresolved-using-value.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s

template<typename T>
struct A : T {
using T::f;
using T::g;
using T::h;

void f();
void g();

void i() {
f<int>();
g<int>(); // expected-error{{no member named 'g' in 'A<B>'}}
h<int>(); // expected-error{{expected '(' for function-style cast or type construction}}
// expected-error@-1{{expected expression}}
}
};

struct B {
template<typename T>
void f();

void g();

template<typename T>
void h();
};

template struct A<B>; // expected-note{{in instantiation of member function 'A<B>::i' requested here}}
115 changes: 115 additions & 0 deletions clang/test/TableGen/target-builtins-prototype-parser.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// RUN: clang-tblgen -I %p/../../../clang/include/ %s --gen-clang-builtins | FileCheck %s
// RUN: not clang-tblgen -I %p/../../../clang/include/ %s --gen-clang-builtins -DERROR_EXPECTED_LANES 2>&1 | FileCheck %s --check-prefix=ERROR_EXPECTED_LANES
// RUN: not clang-tblgen -I %p/../../../clang/include/ %s --gen-clang-builtins -DERROR_EXPECTED_COMMA 2>&1 | FileCheck %s --check-prefix=ERROR_EXPECTED_COMMA
// RUN: not clang-tblgen -I %p/../../../clang/include/ %s --gen-clang-builtins -DERROR_EXPECTED_TYPE 2>&1 | FileCheck %s --check-prefix=ERROR_EXPECTED_TYPE
// RUN: not clang-tblgen -I %p/../../../clang/include/ %s --gen-clang-builtins -DERROR_EXPECTED_A 2>&1 | FileCheck %s --check-prefix=ERROR_EXPECTED_A
// RUN: not clang-tblgen -I %p/../../../clang/include/ %s --gen-clang-builtins -DERROR_EXPECTED_B 2>&1 | FileCheck %s --check-prefix=ERROR_EXPECTED_B
// RUN: not clang-tblgen -I %p/../../../clang/include/ %s --gen-clang-builtins -DERROR_EXPECTED_C 2>&1 | FileCheck %s --check-prefix=ERROR_EXPECTED_C
// RUN: not clang-tblgen -I %p/../../../clang/include/ %s --gen-clang-builtins -DERROR_EXPECTED_D 2>&1 | FileCheck %s --check-prefix=ERROR_EXPECTED_D

include "clang/Basic/BuiltinsBase.td"

def : Builtin {
// CHECK: BUILTIN(__builtin_01, "E8idE4b", "")
let Prototype = "_ExtVector<8,int>(double, _ExtVector<4, bool>)";
let Spellings = ["__builtin_01"];
}

def : Builtin {
// CHECK: BUILTIN(__builtin_02, "E8UiE4s", "")
let Prototype = "_ExtVector<8,unsigned int>(_ExtVector<4, short>)";
let Spellings = ["__builtin_02"];
}

def : Builtin {
// CHECK: BUILTIN(__builtin_03, "di", "")
let Prototype = "double(int)";
let Spellings = ["__builtin_03"];
}

def : Builtin {
// CHECK: BUILTIN(__builtin_04, "diIUi", "")
let Prototype = "double(int, _Constant unsigned int)";
let Spellings = ["__builtin_04"];
}

def : Builtin {
// CHECK: BUILTIN(__builtin_05, "v&v&", "")
let Prototype = "void&(void&)";
let Spellings = ["__builtin_05"];
}

def : Builtin {
// CHECK: BUILTIN(__builtin_06, "v*v*cC*.", "")
let Prototype = "void*(void*, char const*, ...)";
let Spellings = ["__builtin_06"];
}

def : Builtin {
// CHECK: BUILTIN(__builtin_07, "E8iE4dE4b.", "")
let Prototype = "_ExtVector<8, int>(_ExtVector<4,double>, _ExtVector<4, bool>, ...)";
let Spellings = ["__builtin_07"];
}

def : Builtin {
// CHECK: BUILTIN(__builtin_08, "di*R", "")
let Prototype = "double(int * restrict)";
let Spellings = ["__builtin_08"];
}

#ifdef ERROR_EXPECTED_LANES
def : Builtin {
// ERROR_EXPECTED_LANES: :[[# @LINE + 1]]:7: error: Expected number of lanes after '_ExtVector<'
let Prototype = "_ExtVector<int>(double)";
let Spellings = ["__builtin_test_use_clang_extended_vectors"];
}
#endif

#ifdef ERROR_EXPECTED_COMMA
def : Builtin {
// ERROR_EXPECTED_COMMA: :[[# @LINE + 1]]:7: error: Expected ',' after number of lanes in '_ExtVector<'
let Prototype = "_ExtVector<8 int>(double)";
let Spellings = ["__builtin_test_use_clang_extended_vectors"];
}
#endif

#ifdef ERROR_EXPECTED_TYPE
def : Builtin {
// ERROR_EXPECTED_TYPE: :[[# @LINE + 1]]:7: error: Expected '>' after scalar type in '_ExtVector<N, type>'
let Prototype = "_ExtVector<8, int (double)";
let Spellings = ["__builtin_test_use_clang_extended_vectors"];
}
#endif

#ifdef ERROR_EXPECTED_A
def : Builtin {
// ERROR_EXPECTED_A: :[[# @LINE + 1]]:7: error: Expected '<' after '_ExtVector'
let Prototype = "_ExtVector(8, int) (double)";
let Spellings = ["__builtin_test_use_clang_extended_vectors"];
}
#endif

#ifdef ERROR_EXPECTED_B
def : Builtin {
// ERROR_EXPECTED_B: :[[# @LINE + 1]]:7: error: Expected '<' after '_ExtVector'
let Prototype = "double(_ExtVector(8, int))";
let Spellings = ["__builtin_test_use_clang_extended_vectors"];
}
#endif

#ifdef ERROR_EXPECTED_C
def : Builtin {
// ERROR_EXPECTED_C: :[[# @LINE + 1]]:7: error: Unknown Type: _EtxVector<8, int>
let Prototype = "_EtxVector<8, int>(void)";
let Spellings = ["__builtin_test_use_clang_extended_vectors"];
}
#endif

#ifdef ERROR_EXPECTED_D
def : Builtin {
// ERROR_EXPECTED_D: :[[# @LINE + 1]]:7: error: Expected number of lanes after '_ExtVector<'
let Prototype = "_ExtVector<>(void)";
let Spellings = ["__builtin_test_use_clang_extended_vectors"];
}
#endif

66 changes: 63 additions & 3 deletions clang/utils/TableGen/ClangBuiltinsEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,47 @@ class PrototypeParser {
if (!Prototype.ends_with(")"))
PrintFatalError(Loc, "Expected closing brace at end of prototype");
Prototype = Prototype.drop_back();
for (auto T = Prototype.split(','); !T.first.empty();
Prototype = T.second, T = Prototype.split(','))
ParseType(T.first);

// Look through the input parameters.
const size_t end = Prototype.size();
for (size_t I = 0; I != end;) {
const StringRef Current = Prototype.substr(I, end);
// Skip any leading space or commas
if (Current.starts_with(" ") || Current.starts_with(",")) {
++I;
continue;
}

// Check if we are in _ExtVector. We do this first because
// extended vectors are written in template form with the syntax
// _ExtVector< ..., ...>, so we need to make sure we are not
// detecting the comma of the template class as a separator for
// the parameters of the prototype. Note: the assumption is that
// we cannot have nested _ExtVector.
if (Current.starts_with("_ExtVector<")) {
const size_t EndTemplate = Current.find('>', 0);
ParseType(Current.substr(0, EndTemplate + 1));
// Move the prototype beyond _ExtVector<...>
I += EndTemplate + 1;
continue;
}

// We know that we are past _ExtVector, therefore the first seen
// comma is the boundary of a parameter in the prototype.
if (size_t CommaPos = Current.find(',', 0)) {
if (CommaPos != StringRef::npos) {
StringRef T = Current.substr(0, CommaPos);
ParseType(T);
// Move the prototype beyond the comma.
I += CommaPos + 1;
continue;
}
}

// No more commas, parse final parameter.
ParseType(Current);
I = end;
}
}

void ParseType(StringRef T) {
Expand Down Expand Up @@ -85,6 +123,28 @@ class PrototypeParser {
if (Substitution.empty())
PrintFatalError(Loc, "Not a template");
ParseType(Substitution);
} else if (T.consume_front("_ExtVector")) {
// Clang extended vector types are mangled as follows:
//
// '_ExtVector<' <lanes> ',' <scalar type> '>'

// Before parsing T(=<scalar type>), make sure the syntax of
// `_ExtVector<N, T>` is correct...
if (!T.consume_front("<"))
PrintFatalError(Loc, "Expected '<' after '_ExtVector'");
unsigned long long Lanes;
if (llvm::consumeUnsignedInteger(T, 10, Lanes))
PrintFatalError(Loc, "Expected number of lanes after '_ExtVector<'");
Type += "E" + std::to_string(Lanes);
if (!T.consume_front(","))
PrintFatalError(Loc,
"Expected ',' after number of lanes in '_ExtVector<'");
if (!T.consume_back(">"))
PrintFatalError(
Loc, "Expected '>' after scalar type in '_ExtVector<N, type>'");

// ...all good, we can check if we have a valid `<scalar type>`.
ParseType(T);
} else {
auto ReturnTypeVal = StringSwitch<std::string>(T)
.Case("__builtin_va_list_ref", "A")
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function(darwin_test_archs os valid_archs)
if(NOT TEST_COMPILE_ONLY)
message(STATUS "Finding valid architectures for ${os}...")
set(SIMPLE_C ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/src.c)
file(WRITE ${SIMPLE_C} "#include <stdio.h>\nint main(void) { printf(__FILE__); return 0; }\n")
file(WRITE ${SIMPLE_C} "#include <stdio.h>\n#include <unistd.h>\nint main(void) { printf(__FILE__); fork(); return 0; }\n")

set(os_linker_flags)
foreach(flag ${DARWIN_${os}_LINK_FLAGS})
Expand Down
15 changes: 15 additions & 0 deletions flang/docs/Extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,21 @@ end
`INDEX` include an optional `BACK=` argument, but it doesn't actually
work.

* Allocatable components of array and structure constructors are deallocated
after use without calling final subroutines.
The standard does not specify when and how deallocation of array and structure
constructors allocatable components should happen. All compilers free the
memory after use, but the behavior when the allocatable component is a derived
type with finalization differ, especially when dealing with nested array and
structure constructors expressions. Some compilers call final routine for the
allocatable components of each constructor sub-expressions, some call it only
for the allocatable component of the top level constructor, and some only
deallocate the memory. Deallocating only the memory offers the most
flexibility when lowering such expressions, and it is not clear finalization
is desirable in such context (Fortran interop 1.6.2 in F2018 standards require
array and structure constructors not to be finalized, so it also makes sense
not to finalize their allocatable components when releasing their storage).

## De Facto Standard Features

* `EXTENDS_TYPE_OF()` returns `.TRUE.` if both of its arguments have the
Expand Down
Loading