Skip to content

Commit 4d650ef

Browse files
authored
[Sema] Fix type mismatch error when arguments to elementwise math builtin have different qualifiers, which should be well-formed (#141485)
Fixes #141397 Element-wise math builtins (e.g. __builtin_elementwise_max/__builtin_elementwise_pow etc.) fail when their arguments have different qualifications, but should be well-formed. The fix is ​​to use hasSameUnqualifiedType to check if the arguments match.
1 parent 6d3b72a commit 4d650ef

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ Bug Fixes in This Version
669669
base classes. (GH139452)
670670
- Fixed an assertion failure in serialization of constexpr structs containing unions. (#GH140130)
671671
- Fixed duplicate entries in TableGen that caused the wrong attribute to be selected. (GH#140701)
672+
- Fixed type mismatch error when 'builtin-elementwise-math' arguments have different qualifiers, this should be well-formed. (#GH141397)
672673

673674
Bug Fixes to Compiler Builtins
674675
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaChecking.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15572,7 +15572,7 @@ Sema::BuiltinVectorMath(CallExpr *TheCall,
1557215572
if (checkMathBuiltinElementType(*this, LocA, TyA, ArgTyRestr, 1))
1557315573
return std::nullopt;
1557415574

15575-
if (TyA.getCanonicalType() != TyB.getCanonicalType()) {
15575+
if (!Context.hasSameUnqualifiedType(TyA, TyB)) {
1557615576
Diag(LocA, diag::err_typecheck_call_different_arg_types) << TyA << TyB;
1557715577
return std::nullopt;
1557815578
}

clang/test/Sema/builtins-elementwise-math.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
typedef double double2 __attribute__((ext_vector_type(2)));
44
typedef double double4 __attribute__((ext_vector_type(4)));
55
typedef float float2 __attribute__((ext_vector_type(2)));
6+
typedef float float3 __attribute__((ext_vector_type(3)));
67
typedef float float4 __attribute__((ext_vector_type(4)));
78

89
typedef int int2 __attribute__((ext_vector_type(2)));
@@ -1202,3 +1203,13 @@ void test_builtin_elementwise_fma(int i32, int2 v2i32, short i16,
12021203
c3 = __builtin_elementwise_fma(f32, f32, c3);
12031204
// expected-error@-1 {{3rd argument must be a scalar or vector of floating-point types (was '_Complex float')}}
12041205
}
1206+
1207+
typedef struct {
1208+
float3 b;
1209+
} struct_float3;
1210+
// This example uncovered a bug #141397 :
1211+
// Type mismatch error when 'builtin-elementwise-math' arguments have different qualifiers, this should be well-formed
1212+
float3 foo(float3 a,const struct_float3* hi) {
1213+
float3 b = __builtin_elementwise_max((float3)(0.0f), a);
1214+
return __builtin_elementwise_pow(b, hi->b.yyy);
1215+
}

0 commit comments

Comments
 (0)