Skip to content

Commit 62d3883

Browse files
committed
fixup! [clang] Implement __builtin_popcountg
1 parent e41f7be commit 62d3883

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11976,7 +11976,8 @@ def err_builtin_invalid_arg_type: Error <
1197611976
"pointer to a valid matrix element type|"
1197711977
"signed integer or floating point type|vector type|"
1197811978
"floating point type|"
11979-
"vector of integers}1 (was %2)">;
11979+
"vector of integers|"
11980+
"type of integer}1 (was %2)">;
1198011981

1198111982
def err_builtin_matrix_disabled: Error<
1198211983
"matrix types extension is disabled. Pass -fenable-matrix to enable it">;

clang/lib/Sema/SemaChecking.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2188,6 +2188,23 @@ static bool SemaBuiltinCpu(Sema &S, const TargetInfo &TI, CallExpr *TheCall,
21882188
return false;
21892189
}
21902190

2191+
/// Checks that __builtin_popcountg was called with a single argument, which is
2192+
/// an integer.
2193+
static bool SemaBuiltinPopcountg(Sema &S, CallExpr *TheCall) {
2194+
if (checkArgCount(S, TheCall, 1))
2195+
return true;
2196+
2197+
Expr *Arg = TheCall->getArg(0);
2198+
QualType ArgTy = Arg->getType();
2199+
2200+
if (!ArgTy->isIntegerType()) {
2201+
S.Diag(Arg->getBeginLoc(), diag::err_builtin_invalid_arg_type)
2202+
<< 1 << /*integer ty*/ 7 << ArgTy;
2203+
return true;
2204+
}
2205+
return false;
2206+
}
2207+
21912208
ExprResult
21922209
Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
21932210
CallExpr *TheCall) {
@@ -2958,7 +2975,12 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
29582975
diag::err_hip_invalid_args_builtin_mangled_name);
29592976
return ExprError();
29602977
}
2978+
break;
29612979
}
2980+
case Builtin::BI__builtin_popcountg:
2981+
if (SemaBuiltinPopcountg(*this, TheCall))
2982+
return ExprError();
2983+
break;
29622984
}
29632985

29642986
// Since the target specific builtins for each arch overlap, only check those

clang/test/Sema/builtin-popcountg.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -verify -Wpedantic %s
2+
3+
typedef int int2 __attribute__((ext_vector_type(2)));
4+
5+
void test_builtin_popcountg(int i, double d, int2 i2) {
6+
__builtin_popcountg();
7+
// expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
8+
__builtin_popcountg(i, i);
9+
// expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
10+
__builtin_popcountg(d);
11+
// expected-error@-1 {{1st argument must be a type of integer (was 'double')}}
12+
__builtin_popcountg(i2);
13+
// expected-error@-1 {{1st argument must be a type of integer (was 'int2' (vector of 2 'int' values))}}
14+
}

0 commit comments

Comments
 (0)