Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14,226 changes: 8,906 additions & 5,320 deletions builtins/nlohmann/json.hpp

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions graf2d/gpadv7/inc/ROOT/RPadLength.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,11 @@ public:
/// using namespace ROOT::Experimental;
/// RLine(0.1_normal, 0.0_normal, RLineExtent(0.2_normal, 0.5_normal));
/// ```
inline RPadLength::Normal operator"" _normal(long double val)
inline RPadLength::Normal operator""_normal(long double val)
{
return RPadLength::Normal{(double)val};
}
inline RPadLength::Normal operator"" _normal(unsigned long long int val)
inline RPadLength::Normal operator""_normal(unsigned long long int val)
{
return RPadLength::Normal{(double)val};
}
Expand All @@ -291,11 +291,11 @@ inline RPadLength::Normal operator"" _normal(unsigned long long int val)
/// using namespace ROOT::Experimental;
/// RLine(100_px, 0_px, RLineExtent(20_px, 50_px));
/// ```
inline RPadLength::Pixel operator"" _px(long double val)
inline RPadLength::Pixel operator""_px(long double val)
{
return RPadLength::Pixel{(double)val};
}
inline RPadLength::Pixel operator"" _px(unsigned long long int val)
inline RPadLength::Pixel operator""_px(unsigned long long int val)
{
return RPadLength::Pixel{(double)val};
}
Expand All @@ -307,11 +307,11 @@ inline RPadLength::Pixel operator"" _px(unsigned long long int val)
/// using namespace ROOT::Experimental;
/// RLine(0.1_user, 0.0_user, RLineExtent(0.2_user, 0.5_user));
/// ```
inline RPadLength::User operator"" _user(long double val)
inline RPadLength::User operator""_user(long double val)
{
return RPadLength::User{(double)val};
}
inline RPadLength::User operator"" _user(unsigned long long int val)
inline RPadLength::User operator""_user(unsigned long long int val)
{
return RPadLength::User{(double)val};
}
Expand Down
74 changes: 74 additions & 0 deletions interpreter/llvm-project/clang/docs/LanguageExtensions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1569,6 +1569,7 @@ The following type trait primitives are supported by Clang. Those traits marked
* ``__is_const`` (C++, Embarcadero)
* ``__is_constructible`` (C++, MSVC 2013)
* ``__is_convertible`` (C++, Embarcadero)
* ``__is_nothrow_convertible`` (C++, GNU)
* ``__is_convertible_to`` (Microsoft):
Synonym for ``__is_convertible``.
* ``__is_destructible`` (C++, MSVC 2013)
Expand Down Expand Up @@ -3437,6 +3438,78 @@ builtin, the mangler emits their usual pattern without any special treatment.
// Computes a unique stable name for the given type.
constexpr const char * __builtin_sycl_unique_stable_name( type-id );

``__builtin_popcountg``
-----------------------

``__builtin_popcountg`` returns the number of 1 bits in the argument. The
argument can be of any unsigned integer type.

**Syntax**:

.. code-block:: c++

int __builtin_popcountg(type x)

**Examples**:

.. code-block:: c++

unsigned int x = 1;
int x_pop = __builtin_popcountg(x);

unsigned long y = 3;
int y_pop = __builtin_popcountg(y);

unsigned _BitInt(128) z = 7;
int z_pop = __builtin_popcountg(z);

**Description**:

``__builtin_popcountg`` is meant to be a type-generic alternative to the
``__builtin_popcount{,l,ll}`` builtins, with support for other integer types,
such as ``unsigned __int128`` and C23 ``unsigned _BitInt(N)``.

``__builtin_clzg`` and ``__builtin_ctzg``
-----------------------------------------

``__builtin_clzg`` (respectively ``__builtin_ctzg``) returns the number of
leading (respectively trailing) 0 bits in the first argument. The first argument
can be of any unsigned integer type.

If the first argument is 0 and an optional second argument of ``int`` type is
provided, then the second argument is returned. If the first argument is 0, but
only one argument is provided, then the behavior is undefined.

**Syntax**:

.. code-block:: c++

int __builtin_clzg(type x[, int fallback])
int __builtin_ctzg(type x[, int fallback])

**Examples**:

.. code-block:: c++

unsigned int x = 1;
int x_lz = __builtin_clzg(x);
int x_tz = __builtin_ctzg(x);

unsigned long y = 2;
int y_lz = __builtin_clzg(y);
int y_tz = __builtin_ctzg(y);

unsigned _BitInt(128) z = 4;
int z_lz = __builtin_clzg(z);
int z_tz = __builtin_ctzg(z);

**Description**:

``__builtin_clzg`` (respectively ``__builtin_ctzg``) is meant to be a
type-generic alternative to the ``__builtin_clz{,l,ll}`` (respectively
``__builtin_ctz{,l,ll}``) builtins, with support for other integer types, such
as ``unsigned __int128`` and C23 ``unsigned _BitInt(N)``.

Multiprecision Arithmetic Builtins
----------------------------------

Expand Down Expand Up @@ -5278,6 +5351,7 @@ The following builtin intrinsics can be used in constant expressions:
* ``__builtin_popcount``
* ``__builtin_popcountl``
* ``__builtin_popcountll``
* ``__builtin_popcountg``
* ``__builtin_rotateleft8``
* ``__builtin_rotateleft16``
* ``__builtin_rotateleft32``
Expand Down
5 changes: 5 additions & 0 deletions interpreter/llvm-project/clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,11 @@ Non-comprehensive list of changes in this release
PGO instrumentation profile generation, and ``__LLVM_INSTR_PROFILE_USE`` when
compiling with PGO profile use.

- Added ``__builtin_popcountg`` as a type-generic alternative to
``__builtin_popcount{,l,ll}`` with support for any unsigned integer type. Like
the previous builtins, this new builtin is constexpr and may be used in
constant expressions.

New Compiler Flags
------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,12 +515,12 @@ BUILTIN(__builtin_clzs , "iUs" , "ncE")
BUILTIN(__builtin_clz , "iUi" , "ncE")
BUILTIN(__builtin_clzl , "iULi" , "ncE")
BUILTIN(__builtin_clzll, "iULLi", "ncE")
// TODO: int clzimax(uintmax_t)
BUILTIN(__builtin_clzg , "i." , "nct")
BUILTIN(__builtin_ctzs , "iUs" , "ncE")
BUILTIN(__builtin_ctz , "iUi" , "ncE")
BUILTIN(__builtin_ctzl , "iULi" , "ncE")
BUILTIN(__builtin_ctzll, "iULLi", "ncE")
// TODO: int ctzimax(uintmax_t)
BUILTIN(__builtin_ctzg , "i." , "nct")
BUILTIN(__builtin_ffs , "ii" , "FncE")
BUILTIN(__builtin_ffsl , "iLi" , "FncE")
BUILTIN(__builtin_ffsll, "iLLi", "FncE")
Expand All @@ -530,6 +530,7 @@ BUILTIN(__builtin_parityll, "iULLi", "ncE")
BUILTIN(__builtin_popcount , "iUi" , "ncE")
BUILTIN(__builtin_popcountl , "iULi" , "ncE")
BUILTIN(__builtin_popcountll, "iULLi", "ncE")
BUILTIN(__builtin_popcountg , "i." , "nctE")
BUILTIN(__builtin_clrsb , "ii" , "ncE")
BUILTIN(__builtin_clrsbl , "iLi" , "ncE")
BUILTIN(__builtin_clrsbll, "iLLi", "ncE")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11954,7 +11954,8 @@ def err_builtin_invalid_arg_type: Error <
"pointer to a valid matrix element type|"
"signed integer or floating point type|vector type|"
"floating point type|"
"vector of integers}1 (was %2)">;
"vector of integers|"
"type of unsigned integer}1 (was %2)">;

def err_builtin_matrix_disabled: Error<
"matrix types extension is disabled. Pass -fenable-matrix to enable it">;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ TYPE_TRAIT_1(__is_unsigned, IsUnsigned, KEYCXX)
// Embarcadero Binary Type Traits
TYPE_TRAIT_2(__is_same, IsSame, KEYCXX)
TYPE_TRAIT_2(__is_convertible, IsConvertible, KEYCXX)
TYPE_TRAIT_2(__is_nothrow_convertible, IsNothrowConvertible, KEYCXX)
ARRAY_TYPE_TRAIT(__array_rank, ArrayRank, KEYCXX)
ARRAY_TYPE_TRAIT(__array_extent, ArrayExtent, KEYCXX)
// Name for GCC 6 compatibility.
Expand Down
1 change: 1 addition & 0 deletions interpreter/llvm-project/clang/lib/AST/ExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12461,6 +12461,7 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
case Builtin::BI__builtin_popcount:
case Builtin::BI__builtin_popcountl:
case Builtin::BI__builtin_popcountll:
case Builtin::BI__builtin_popcountg:
case Builtin::BI__popcnt16: // Microsoft variants of popcount
case Builtin::BI__popcnt:
case Builtin::BI__popcnt64: {
Expand Down
49 changes: 40 additions & 9 deletions interpreter/llvm-project/clang/lib/CodeGen/CGBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3130,36 +3130,66 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
case Builtin::BI__builtin_ctzs:
case Builtin::BI__builtin_ctz:
case Builtin::BI__builtin_ctzl:
case Builtin::BI__builtin_ctzll: {
Value *ArgValue = EmitCheckedArgForBuiltin(E->getArg(0), BCK_CTZPassedZero);
case Builtin::BI__builtin_ctzll:
case Builtin::BI__builtin_ctzg: {
bool HasFallback = BuiltinIDIfNoAsmLabel == Builtin::BI__builtin_ctzg &&
E->getNumArgs() > 1;

Value *ArgValue =
HasFallback ? EmitScalarExpr(E->getArg(0))
: EmitCheckedArgForBuiltin(E->getArg(0), BCK_CTZPassedZero);

llvm::Type *ArgType = ArgValue->getType();
Function *F = CGM.getIntrinsic(Intrinsic::cttz, ArgType);

llvm::Type *ResultType = ConvertType(E->getType());
Value *ZeroUndef = Builder.getInt1(getTarget().isCLZForZeroUndef());
Value *ZeroUndef =
Builder.getInt1(HasFallback || getTarget().isCLZForZeroUndef());
Value *Result = Builder.CreateCall(F, {ArgValue, ZeroUndef});
if (Result->getType() != ResultType)
Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true,
"cast");
return RValue::get(Result);
if (!HasFallback)
return RValue::get(Result);

Value *Zero = Constant::getNullValue(ArgType);
Value *IsZero = Builder.CreateICmpEQ(ArgValue, Zero, "iszero");
Value *FallbackValue = EmitScalarExpr(E->getArg(1));
Value *ResultOrFallback =
Builder.CreateSelect(IsZero, FallbackValue, Result, "ctzg");
return RValue::get(ResultOrFallback);
}
case Builtin::BI__builtin_clzs:
case Builtin::BI__builtin_clz:
case Builtin::BI__builtin_clzl:
case Builtin::BI__builtin_clzll: {
Value *ArgValue = EmitCheckedArgForBuiltin(E->getArg(0), BCK_CLZPassedZero);
case Builtin::BI__builtin_clzll:
case Builtin::BI__builtin_clzg: {
bool HasFallback = BuiltinIDIfNoAsmLabel == Builtin::BI__builtin_clzg &&
E->getNumArgs() > 1;

Value *ArgValue =
HasFallback ? EmitScalarExpr(E->getArg(0))
: EmitCheckedArgForBuiltin(E->getArg(0), BCK_CLZPassedZero);

llvm::Type *ArgType = ArgValue->getType();
Function *F = CGM.getIntrinsic(Intrinsic::ctlz, ArgType);

llvm::Type *ResultType = ConvertType(E->getType());
Value *ZeroUndef = Builder.getInt1(getTarget().isCLZForZeroUndef());
Value *ZeroUndef =
Builder.getInt1(HasFallback || getTarget().isCLZForZeroUndef());
Value *Result = Builder.CreateCall(F, {ArgValue, ZeroUndef});
if (Result->getType() != ResultType)
Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true,
"cast");
return RValue::get(Result);
if (!HasFallback)
return RValue::get(Result);

Value *Zero = Constant::getNullValue(ArgType);
Value *IsZero = Builder.CreateICmpEQ(ArgValue, Zero, "iszero");
Value *FallbackValue = EmitScalarExpr(E->getArg(1));
Value *ResultOrFallback =
Builder.CreateSelect(IsZero, FallbackValue, Result, "clzg");
return RValue::get(ResultOrFallback);
}
case Builtin::BI__builtin_ffs:
case Builtin::BI__builtin_ffsl:
Expand Down Expand Up @@ -3219,7 +3249,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
case Builtin::BI__popcnt64:
case Builtin::BI__builtin_popcount:
case Builtin::BI__builtin_popcountl:
case Builtin::BI__builtin_popcountll: {
case Builtin::BI__builtin_popcountll:
case Builtin::BI__builtin_popcountg: {
Value *ArgValue = EmitScalarExpr(E->getArg(0));

llvm::Type *ArgType = ArgValue->getType();
Expand Down
75 changes: 75 additions & 0 deletions interpreter/llvm-project/clang/lib/Sema/SemaChecking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2143,6 +2143,71 @@ static bool checkFPMathBuiltinElementType(Sema &S, SourceLocation Loc,
return false;
}

/// Checks that __builtin_popcountg was called with a single argument, which is
/// an unsigned integer.
static bool SemaBuiltinPopcountg(Sema &S, CallExpr *TheCall) {
if (checkArgCount(S, TheCall, 1))
return true;

ExprResult ArgRes = S.DefaultLvalueConversion(TheCall->getArg(0));
if (ArgRes.isInvalid())
return true;

Expr *Arg = ArgRes.get();
TheCall->setArg(0, Arg);

QualType ArgTy = Arg->getType();

if (!ArgTy->isUnsignedIntegerType()) {
S.Diag(Arg->getBeginLoc(), diag::err_builtin_invalid_arg_type)
<< 1 << /*unsigned integer ty*/ 7 << ArgTy;
return true;
}
return false;
}

/// Checks that __builtin_{clzg,ctzg} was called with a first argument, which is
/// an unsigned integer, and an optional second argument, which is promoted to
/// an 'int'.
static bool SemaBuiltinCountZeroBitsGeneric(Sema &S, CallExpr *TheCall) {
if (checkArgCountRange(S, TheCall, 1, 2))
return true;

ExprResult Arg0Res = S.DefaultLvalueConversion(TheCall->getArg(0));
if (Arg0Res.isInvalid())
return true;

Expr *Arg0 = Arg0Res.get();
TheCall->setArg(0, Arg0);

QualType Arg0Ty = Arg0->getType();

if (!Arg0Ty->isUnsignedIntegerType()) {
S.Diag(Arg0->getBeginLoc(), diag::err_builtin_invalid_arg_type)
<< 1 << /*unsigned integer ty*/ 7 << Arg0Ty;
return true;
}

if (TheCall->getNumArgs() > 1) {
ExprResult Arg1Res = S.UsualUnaryConversions(TheCall->getArg(1));
if (Arg1Res.isInvalid())
return true;

Expr *Arg1 = Arg1Res.get();
TheCall->setArg(1, Arg1);

QualType Arg1Ty = Arg1->getType();

if (!Arg1Ty->isSpecificBuiltinType(BuiltinType::Int)) {
S.Diag(Arg1->getBeginLoc(), diag::err_builtin_invalid_arg_type)
<< 2 << /*'int' ty*/ 8 << Arg1Ty;
return true;
}
}

return false;
}

ExprResult
Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
CallExpr *TheCall) {
Expand Down Expand Up @@ -2900,7 +2965,17 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
diag::err_hip_invalid_args_builtin_mangled_name);
return ExprError();
}
break;
}
case Builtin::BI__builtin_popcountg:
if (SemaBuiltinPopcountg(*this, TheCall))
return ExprError();
break;
case Builtin::BI__builtin_clzg:
case Builtin::BI__builtin_ctzg:
if (SemaBuiltinCountZeroBitsGeneric(*this, TheCall))
return ExprError();
break;
}

// Since the target specific builtins for each arch overlap, only check those
Expand Down
11 changes: 9 additions & 2 deletions interpreter/llvm-project/clang/lib/Sema/SemaExprCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5780,7 +5780,8 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait BTT, QualType LhsT,
return Self.Context.typesAreCompatible(Lhs, Rhs);
}
case BTT_IsConvertible:
case BTT_IsConvertibleTo: {
case BTT_IsConvertibleTo:
case BTT_IsNothrowConvertible: {
// C++0x [meta.rel]p4:
// Given the following function prototype:
//
Expand Down Expand Up @@ -5841,7 +5842,13 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait BTT, QualType LhsT,
return false;

ExprResult Result = Init.Perform(Self, To, Kind, FromPtr);
return !Result.isInvalid() && !SFINAE.hasErrorOccurred();
if (Result.isInvalid() || SFINAE.hasErrorOccurred())
return false;

if (BTT != BTT_IsNothrowConvertible)
return true;

return Self.canThrow(Result.get()) == CT_Cannot;
}

case BTT_IsAssignable:
Expand Down
Loading
Loading