[clang] 4d650ef - [Sema] Fix type mismatch error when arguments to elementwise math builtin have different qualifiers, which should be well-formed (#141485)
via cfe-commits
cfe-commits at lists.llvm.org
Fri May 30 07:09:23 PDT 2025
Author: Acthink Yang
Date: 2025-05-30T07:09:20-07:00
New Revision: 4d650ef4b3d7a0f21f8681e73586d0319fc3953b
URL: https://github.com/llvm/llvm-project/commit/4d650ef4b3d7a0f21f8681e73586d0319fc3953b
DIFF: https://github.com/llvm/llvm-project/commit/4d650ef4b3d7a0f21f8681e73586d0319fc3953b.diff
LOG: [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.
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaChecking.cpp
clang/test/Sema/builtins-elementwise-math.c
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 32266fce4d3cb..dc97883de05d0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -669,6 +669,7 @@ Bug Fixes in This Version
base classes. (GH139452)
- Fixed an assertion failure in serialization of constexpr structs containing unions. (#GH140130)
- Fixed duplicate entries in TableGen that caused the wrong attribute to be selected. (GH#140701)
+- Fixed type mismatch error when 'builtin-elementwise-math' arguments have
diff erent qualifiers, this should be well-formed. (#GH141397)
Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index ba2630e960e6f..373ca549cb23b 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -15572,7 +15572,7 @@ Sema::BuiltinVectorMath(CallExpr *TheCall,
if (checkMathBuiltinElementType(*this, LocA, TyA, ArgTyRestr, 1))
return std::nullopt;
- if (TyA.getCanonicalType() != TyB.getCanonicalType()) {
+ if (!Context.hasSameUnqualifiedType(TyA, TyB)) {
Diag(LocA, diag::err_typecheck_call_
diff erent_arg_types) << TyA << TyB;
return std::nullopt;
}
diff --git a/clang/test/Sema/builtins-elementwise-math.c b/clang/test/Sema/builtins-elementwise-math.c
index b5648a5e5c6e8..01057b3f8d083 100644
--- a/clang/test/Sema/builtins-elementwise-math.c
+++ b/clang/test/Sema/builtins-elementwise-math.c
@@ -3,6 +3,7 @@
typedef double double2 __attribute__((ext_vector_type(2)));
typedef double double4 __attribute__((ext_vector_type(4)));
typedef float float2 __attribute__((ext_vector_type(2)));
+typedef float float3 __attribute__((ext_vector_type(3)));
typedef float float4 __attribute__((ext_vector_type(4)));
typedef int int2 __attribute__((ext_vector_type(2)));
@@ -1202,3 +1203,13 @@ void test_builtin_elementwise_fma(int i32, int2 v2i32, short i16,
c3 = __builtin_elementwise_fma(f32, f32, c3);
// expected-error at -1 {{3rd argument must be a scalar or vector of floating-point types (was '_Complex float')}}
}
+
+typedef struct {
+ float3 b;
+} struct_float3;
+// This example uncovered a bug #141397 :
+// Type mismatch error when 'builtin-elementwise-math' arguments have
diff erent qualifiers, this should be well-formed
+float3 foo(float3 a,const struct_float3* hi) {
+ float3 b = __builtin_elementwise_max((float3)(0.0f), a);
+ return __builtin_elementwise_pow(b, hi->b.yyy);
+}
More information about the cfe-commits
mailing list