From: Craig Topper Date: Wed, 8 Aug 2018 22:31:12 +0000 (+0000) Subject: [Builtins] Add __builtin_clrsb support to IntExprEvaluator::VisitBuiltinCallExpr X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9c67812c6c9d5a4f9f82fbc93ceffd0130c8e080;p=clang [Builtins] Add __builtin_clrsb support to IntExprEvaluator::VisitBuiltinCallExpr This addresses a FIXME that has existed since before clang supported the builtin. This time with only reviewed changes. Differential Revision: https://reviews.llvm.org/D50471 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@339295 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 7e596d0715..0ce962e419 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -8117,9 +8117,15 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E, case Builtin::BI__builtin_classify_type: return Success((int)EvaluateBuiltinClassifyType(E, Info.getLangOpts()), E); - // FIXME: BI__builtin_clrsb - // FIXME: BI__builtin_clrsbl - // FIXME: BI__builtin_clrsbll + case Builtin::BI__builtin_clrsb: + case Builtin::BI__builtin_clrsbl: + case Builtin::BI__builtin_clrsbll: { + APSInt Val; + if (!EvaluateInteger(E->getArg(0), Val, Info)) + return false; + + return Success(Val.getBitWidth() - Val.getMinSignedBits(), E); + } case Builtin::BI__builtin_clz: case Builtin::BI__builtin_clzl: diff --git a/test/Sema/constant-builtins-2.c b/test/Sema/constant-builtins-2.c index 40cfce1f4a..9bb5215b8d 100644 --- a/test/Sema/constant-builtins-2.c +++ b/test/Sema/constant-builtins-2.c @@ -176,6 +176,19 @@ char ffs4[__builtin_ffs(0xfbe70) == 5 ? 1 : -1]; char ffs5[__builtin_ffs(1U << (BITSIZE(int) - 1)) == BITSIZE(int) ? 1 : -1]; char ffs6[__builtin_ffsl(0x10L) == 5 ? 1 : -1]; char ffs7[__builtin_ffsll(0x100LL) == 9 ? 1 : -1]; + +char clrsb1[__builtin_clrsb(0) == BITSIZE(int) - 1 ? 1 : -1]; +char clrsb2[__builtin_clrsbl(0L) == BITSIZE(long) - 1 ? 1 : -1]; +char clrsb3[__builtin_clrsbll(0LL) == BITSIZE(long long) - 1 ? 1 : -1]; +char clrsb4[__builtin_clrsb(~0) == BITSIZE(int) - 1 ? 1 : -1]; +char clrsb5[__builtin_clrsbl(~0L) == BITSIZE(long) - 1 ? 1 : -1]; +char clrsb6[__builtin_clrsbll(~0LL) == BITSIZE(long long) - 1 ? 1 : -1]; +char clrsb7[__builtin_clrsb(1) == BITSIZE(int) - 2 ? 1 : -1]; +char clrsb8[__builtin_clrsb(~1) == BITSIZE(int) - 2 ? 1 : -1]; +char clrsb9[__builtin_clrsb(1 << (BITSIZE(int) - 1)) == 0 ? 1 : -1]; +char clrsb10[__builtin_clrsb(~(1 << (BITSIZE(int) - 1))) == 0 ? 1 : -1]; +char clrsb11[__builtin_clrsb(0xf) == BITSIZE(int) - 5 ? 1 : -1]; +char clrsb12[__builtin_clrsb(~0x1f) == BITSIZE(int) - 6 ? 1 : -1]; #undef BITSIZE // GCC misc stuff