Skip to content

Commit 94a640c

Browse files
committed
fixup! [clang] Implement __builtin_{clzg,ctzg}
1 parent 5e37b3b commit 94a640c

File tree

3 files changed

+5
-13
lines changed

3 files changed

+5
-13
lines changed

clang/include/clang/Basic/Builtins.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -660,8 +660,6 @@ def Clz : Builtin, BitShort_Int_Long_LongLongTemplate {
660660
let Prototype = "int(unsigned T)";
661661
}
662662

663-
// FIXME: Add int clzimax(uintmax_t)
664-
665663
def Clzg : Builtin {
666664
let Spellings = ["__builtin_clzg"];
667665
let Attributes = [NoThrow, Const, CustomTypeChecking];
@@ -674,8 +672,6 @@ def Ctz : Builtin, BitShort_Int_Long_LongLongTemplate {
674672
let Prototype = "int(unsigned T)";
675673
}
676674

677-
// FIXME: Add int ctzimax(uintmax_t)
678-
679675
def Ctzg : Builtin {
680676
let Spellings = ["__builtin_ctzg"];
681677
let Attributes = [NoThrow, Const, CustomTypeChecking];

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3141,7 +3141,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
31413141
Function *F = CGM.getIntrinsic(Intrinsic::cttz, ArgType);
31423142

31433143
llvm::Type *ResultType = ConvertType(E->getType());
3144-
Value *ZeroUndef = Builder.getInt1(getTarget().isCLZForZeroUndef());
3144+
Value *ZeroUndef =
3145+
Builder.getInt1(HasFallback || getTarget().isCLZForZeroUndef());
31453146
Value *Result = Builder.CreateCall(F, {ArgValue, ZeroUndef});
31463147
if (Result->getType() != ResultType)
31473148
Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true,
@@ -3172,7 +3173,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
31723173
Function *F = CGM.getIntrinsic(Intrinsic::ctlz, ArgType);
31733174

31743175
llvm::Type *ResultType = ConvertType(E->getType());
3175-
Value *ZeroUndef = Builder.getInt1(getTarget().isCLZForZeroUndef());
3176+
Value *ZeroUndef =
3177+
Builder.getInt1(HasFallback || getTarget().isCLZForZeroUndef());
31763178
Value *Result = Builder.CreateCall(F, {ArgValue, ZeroUndef});
31773179
if (Result->getType() != ResultType)
31783180
Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true,

clang/lib/Sema/SemaChecking.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,7 +2237,7 @@ static bool SemaBuiltinCountZeroBitsGeneric(Sema &S, CallExpr *TheCall) {
22372237
}
22382238

22392239
if (TheCall->getNumArgs() > 1) {
2240-
ExprResult Arg1Res = S.DefaultLvalueConversion(TheCall->getArg(1));
2240+
ExprResult Arg1Res = S.UsualUnaryConversions(TheCall->getArg(1));
22412241
if (Arg1Res.isInvalid())
22422242
return true;
22432243

@@ -2246,12 +2246,6 @@ static bool SemaBuiltinCountZeroBitsGeneric(Sema &S, CallExpr *TheCall) {
22462246

22472247
QualType Arg1Ty = Arg1->getType();
22482248

2249-
if (S.Context.isPromotableIntegerType(Arg1Ty)) {
2250-
Arg1Ty = S.Context.getPromotedIntegerType(Arg1Ty);
2251-
Arg1 = S.ImpCastExprToType(Arg1, Arg1Ty, CK_IntegralCast).get();
2252-
TheCall->setArg(1, Arg1);
2253-
}
2254-
22552249
if (!Arg1Ty->isSpecificBuiltinType(BuiltinType::Int)) {
22562250
S.Diag(Arg1->getBeginLoc(), diag::err_builtin_invalid_arg_type)
22572251
<< 2 << /*'int' ty*/ 8 << Arg1Ty;

0 commit comments

Comments
 (0)