Skip to content

Commit 8a579b1

Browse files
committed
[Sema] built-in args type checking using hasSameUnqualifiedType
Fixes #141397
1 parent f22122a commit 8a579b1

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

clang/lib/Sema/SemaChecking.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2907,7 +2907,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
29072907
return ExprError();
29082908
}
29092909

2910-
if (MagnitudeTy.getCanonicalType() != SignTy.getCanonicalType()) {
2910+
if (!Context.hasSameUnqualifiedType(MagnitudeTy, SignTy)) {
29112911
return Diag(Sign.get()->getBeginLoc(),
29122912
diag::err_typecheck_call_different_arg_types)
29132913
<< MagnitudeTy << SignTy;
@@ -5265,7 +5265,7 @@ bool Sema::BuiltinComplex(CallExpr *TheCall) {
52655265

52665266
Expr *Real = TheCall->getArg(0);
52675267
Expr *Imag = TheCall->getArg(1);
5268-
if (!Context.hasSameType(Real->getType(), Imag->getType())) {
5268+
if (!Context.hasSameUnqualifiedType(Real->getType(), Imag->getType())) {
52695269
return Diag(Real->getBeginLoc(),
52705270
diag::err_typecheck_call_different_arg_types)
52715271
<< Real->getType() << Imag->getType()
@@ -15568,7 +15568,7 @@ Sema::BuiltinVectorMath(CallExpr *TheCall,
1556815568
if (checkMathBuiltinElementType(*this, LocA, TyA, ArgTyRestr, 1))
1556915569
return std::nullopt;
1557015570

15571-
if (TyA.getCanonicalType() != TyB.getCanonicalType()) {
15571+
if (!Context.hasSameUnqualifiedType(TyA, TyB)) {
1557215572
Diag(LocA, diag::err_typecheck_call_different_arg_types) << TyA << TyB;
1557315573
return std::nullopt;
1557415574
}
@@ -15607,8 +15607,8 @@ bool Sema::BuiltinElementwiseTernaryMath(
1560715607
}
1560815608

1560915609
for (int I = 1; I < 3; ++I) {
15610-
if (Args[0]->getType().getCanonicalType() !=
15611-
Args[I]->getType().getCanonicalType()) {
15610+
if (!Context.hasSameUnqualifiedType(Args[0]->getType(),
15611+
Args[I]->getType())) {
1561215612
return Diag(Args[0]->getBeginLoc(),
1561315613
diag::err_typecheck_call_different_arg_types)
1561415614
<< Args[0]->getType() << Args[I]->getType();

clang/test/SemaCXX/bug141397.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 %s -fsyntax-only -verify
2+
// expected-no-diagnostics
3+
4+
// This example uncovered a bug in Sema::BuiltinVectorMath, where we should be
5+
// using ASTContext::hasSameUnqualifiedType().
6+
7+
typedef float vec3 __attribute__((ext_vector_type(3)));
8+
9+
typedef struct {
10+
vec3 b;
11+
} struc;
12+
13+
vec3 foo(vec3 a,const struc* hi) {
14+
vec3 b = __builtin_elementwise_max((vec3)(0.0f), a);
15+
return __builtin_elementwise_pow(b, hi->b.yyy);
16+
}

0 commit comments

Comments
 (0)