Skip to content
Merged
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
4 changes: 4 additions & 0 deletions interpreter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ if (NOT builtin_clang)
message(WARNING "Due to ROOT-specific patches you need a special version of clang. You cannot use vanilla clang.")
endif()

if(APPLE AND builtin_clang AND OSX_SDK_VERSION VERSION_GREATER_EQUAL "26.4")
add_compile_definitions(MAC_SDK_WORKAROUND)
endif()

#--Set the LLVM version required for ROOT-----------------------------------------------------------
set(ROOT_LLVM_VERSION_REQUIRED_MAJOR 18)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,12 +515,16 @@ 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)
#if defined(MAC_SDK_WORKAROUND)
BUILTIN(__builtin_clzg , "i." , "nct")
#endif
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)
#if defined(MAC_SDK_WORKAROUND)
BUILTIN(__builtin_ctzg , "i." , "nct")
#endif
BUILTIN(__builtin_ffs , "ii" , "FncE")
BUILTIN(__builtin_ffsl , "iLi" , "FncE")
BUILTIN(__builtin_ffsll, "iLLi", "FncE")
Expand All @@ -530,6 +534,9 @@ BUILTIN(__builtin_parityll, "iULLi", "ncE")
BUILTIN(__builtin_popcount , "iUi" , "ncE")
BUILTIN(__builtin_popcountl , "iULi" , "ncE")
BUILTIN(__builtin_popcountll, "iULLi", "ncE")
#if defined(MAC_SDK_WORKAROUND)
BUILTIN(__builtin_popcountg , "i." , "ncE")
#endif
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 @@ -567,6 +567,9 @@ 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)
#if defined(MAC_SDK_WORKAROUND)
TYPE_TRAIT_2(__is_nothrow_convertible, IsNothrowConvertible, KEYCXX)
#endif
ARRAY_TYPE_TRAIT(__array_rank, ArrayRank, KEYCXX)
ARRAY_TYPE_TRAIT(__array_extent, ArrayExtent, KEYCXX)
// Name for GCC 6 compatibility.
Expand Down
3 changes: 3 additions & 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,9 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
case Builtin::BI__builtin_popcount:
case Builtin::BI__builtin_popcountl:
case Builtin::BI__builtin_popcountll:
#if defined(MAC_SDK_WORKAROUND)
case Builtin::BI__builtin_popcountg:
#endif
case Builtin::BI__popcnt16: // Microsoft variants of popcount
case Builtin::BI__popcnt:
case Builtin::BI__popcnt64: {
Expand Down
61 changes: 61 additions & 0 deletions interpreter/llvm-project/clang/lib/CodeGen/CGBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3130,36 +3130,92 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
case Builtin::BI__builtin_ctzs:
case Builtin::BI__builtin_ctz:
case Builtin::BI__builtin_ctzl:
#if defined(MAC_SDK_WORKAROUND)
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);
#else
case Builtin::BI__builtin_ctzll: {
Value *ArgValue = EmitCheckedArgForBuiltin(E->getArg(0), BCK_CTZPassedZero);

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

llvm::Type *ResultType = ConvertType(E->getType());
#if defined(MAC_SDK_WORKAROUND)
Value *ZeroUndef =
Builder.getInt1(HasFallback || getTarget().isCLZForZeroUndef());
#else
Value *ZeroUndef = Builder.getInt1(getTarget().isCLZForZeroUndef());
#endif
Value *Result = Builder.CreateCall(F, {ArgValue, ZeroUndef});
if (Result->getType() != ResultType)
Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true,
"cast");
#if defined(MAC_SDK_WORKAROUND)
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);
#else
return RValue::get(Result);
#endif
}
case Builtin::BI__builtin_clzs:
case Builtin::BI__builtin_clz:
case Builtin::BI__builtin_clzl:
#if defined(MAC_SDK_WORKAROUND)
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);
#else
case Builtin::BI__builtin_clzll: {
Value *ArgValue = EmitCheckedArgForBuiltin(E->getArg(0), BCK_CLZPassedZero);

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

llvm::Type *ResultType = ConvertType(E->getType());
#if defined(MAC_SDK_WORKAROUND)
Value *ZeroUndef =
Builder.getInt1(HasFallback || getTarget().isCLZForZeroUndef());
#else
Value *ZeroUndef = Builder.getInt1(getTarget().isCLZForZeroUndef());
#endif
Value *Result = Builder.CreateCall(F, {ArgValue, ZeroUndef});
if (Result->getType() != ResultType)
Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true,
"cast");
#if defined(MAC_SDK_WORKAROUND)
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);
#else
return RValue::get(Result);
#endif
}
case Builtin::BI__builtin_ffs:
case Builtin::BI__builtin_ffsl:
Expand Down Expand Up @@ -3219,7 +3275,12 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
case Builtin::BI__popcnt64:
case Builtin::BI__builtin_popcount:
case Builtin::BI__builtin_popcountl:
#if defined(MAC_SDK_WORKAROUND)
case Builtin::BI__builtin_popcountll:
case Builtin::BI__builtin_popcountg: {
#else
case Builtin::BI__builtin_popcountll: {
#endif
Value *ArgValue = EmitScalarExpr(E->getArg(0));

llvm::Type *ArgType = ArgValue->getType();
Expand Down
77 changes: 77 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,69 @@ static bool checkFPMathBuiltinElementType(Sema &S, SourceLocation Loc,
return false;
}

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

Expr *Arg = TheCall->getArg(0);
QualType ArgTy = Arg->getType();

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

#if defined(MAC_SDK_WORKAROUND)
/// 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;
}
#endif

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

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

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

if (BTT != BTT_IsNothrowConvertible)
return true;

return Self.canThrow(Result.get()) == CT_Cannot;
#else
return !Result.isInvalid() && !SFINAE.hasErrorOccurred();
#endif
}

case BTT_IsAssignable:
Expand Down
2 changes: 1 addition & 1 deletion interpreter/llvm-project/llvm-project.tag
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ROOT-llvm18-20250626-01
ROOT-llvm18-20260306-v6-36-01
Loading