[clang] [Sema] built-in args type checking using hasSameUnqualifiedType (PR #141485)

via cfe-commits cfe-commits at lists.llvm.org
Mon May 26 05:17:56 PDT 2025


https://github.com/QiYueFeiXue created https://github.com/llvm/llvm-project/pull/141485

Fixes #141397

>From 3973f98b7285796975ca6e7d41e938e28c942a00 Mon Sep 17 00:00:00 2001
From: QiYue <yangzhh at mail.ustc.edu.cn>
Date: Mon, 26 May 2025 19:51:24 +0800
Subject: [PATCH] [Sema] built-in args type checking using
 hasSameUnqualifiedType

Fixes #141397
---
 clang/lib/Sema/SemaChecking.cpp  | 10 +++++-----
 clang/test/SemaCXX/bug141397.cpp | 16 ++++++++++++++++
 2 files changed, 21 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/SemaCXX/bug141397.cpp

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 930e9083365a1..61aeffde338d8 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -2907,7 +2907,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
       return ExprError();
     }
 
-    if (MagnitudeTy.getCanonicalType() != SignTy.getCanonicalType()) {
+    if (!Context.hasSameUnqualifiedType(MagnitudeTy, SignTy)) {
       return Diag(Sign.get()->getBeginLoc(),
                   diag::err_typecheck_call_different_arg_types)
              << MagnitudeTy << SignTy;
@@ -5265,7 +5265,7 @@ bool Sema::BuiltinComplex(CallExpr *TheCall) {
 
   Expr *Real = TheCall->getArg(0);
   Expr *Imag = TheCall->getArg(1);
-  if (!Context.hasSameType(Real->getType(), Imag->getType())) {
+  if (!Context.hasSameUnqualifiedType(Real->getType(), Imag->getType())) {
     return Diag(Real->getBeginLoc(),
                 diag::err_typecheck_call_different_arg_types)
            << Real->getType() << Imag->getType()
@@ -15568,7 +15568,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_different_arg_types) << TyA << TyB;
     return std::nullopt;
   }
@@ -15607,8 +15607,8 @@ bool Sema::BuiltinElementwiseTernaryMath(
   }
 
   for (int I = 1; I < 3; ++I) {
-    if (Args[0]->getType().getCanonicalType() !=
-        Args[I]->getType().getCanonicalType()) {
+    if (!Context.hasSameUnqualifiedType(Args[0]->getType(),
+                                        Args[I]->getType())) {
       return Diag(Args[0]->getBeginLoc(),
                   diag::err_typecheck_call_different_arg_types)
              << Args[0]->getType() << Args[I]->getType();
diff --git a/clang/test/SemaCXX/bug141397.cpp b/clang/test/SemaCXX/bug141397.cpp
new file mode 100644
index 0000000000000..cb9f13a93f955
--- /dev/null
+++ b/clang/test/SemaCXX/bug141397.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+// expected-no-diagnostics
+
+// This example uncovered a bug in Sema::BuiltinVectorMath, where we should be
+// using ASTContext::hasSameUnqualifiedType().
+
+typedef float vec3 __attribute__((ext_vector_type(3)));
+
+typedef struct {
+  vec3 b;
+} struc;
+
+vec3 foo(vec3 a,const struc* hi) {
+  vec3 b = __builtin_elementwise_max((vec3)(0.0f), a);
+  return __builtin_elementwise_pow(b, hi->b.yyy);
+}



More information about the cfe-commits mailing list