Skip to content

Commit 384250c

Browse files
committed
Merge from 'main' to 'sycl-web' (44 commits)
CONFLICT (content): Merge conflict in clang/docs/LanguageExtensions.rst
2 parents f667227 + 21d8332 commit 384250c

File tree

200 files changed

+4056
-1785
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

200 files changed

+4056
-1785
lines changed

bolt/test/runtime/instrument-wrong-target.s

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Test that BOLT errs when trying to instrument a binary with a different
22
# architecture than the one BOLT is built for.
33

4-
# REQUIRES: x86_64-linux,bolt-runtime,target=x86_64{{.*}}
4+
# REQUIRES: x86_64-linux,bolt-runtime
5+
# REQUIRES: target-x86_64 && aarch64-registered-target
56

67
# RUN: llvm-mc -triple aarch64 -filetype=obj %s -o %t.o
78
# RUN: ld.lld -q -pie -o %t.exe %t.o

clang/docs/LanguageExtensions.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3494,6 +3494,37 @@ internal linkage.
34943494
// Computes a unique stable name for a given variable.
34953495
constexpr const char * __builtin_sycl_unique_stable_id( expr );
34963496
3497+
``__builtin_popcountg``
3498+
-----------------------
3499+
3500+
``__builtin_popcountg`` returns the number of 1 bits in the argument. The
3501+
argument can be of any integer type.
3502+
3503+
**Syntax**:
3504+
3505+
.. code-block:: c++
3506+
3507+
int __builtin_popcountg(type x)
3508+
3509+
**Examples**:
3510+
3511+
.. code-block:: c++
3512+
3513+
int x = 1;
3514+
int x_pop = __builtin_popcountg(x);
3515+
3516+
unsigned long y = 3;
3517+
int y_pop = __builtin_popcountg(y);
3518+
3519+
_BitInt(128) z = 7;
3520+
int z_pop = __builtin_popcountg(z);
3521+
3522+
**Description**:
3523+
3524+
``__builtin_popcountg`` is meant to be a type-generic alternative to the
3525+
``__builtin_popcount{,l,ll}`` builtins, with support for other integer types,
3526+
such as ``__int128`` and C23 ``_BitInt(N)``.
3527+
34973528
Multiprecision Arithmetic Builtins
34983529
----------------------------------
34993530

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ Bug Fixes to C++ Support
283283
(`#78524 <https://github.com/llvm/llvm-project/issues/78524>`_)
284284
- Clang no longer instantiates the exception specification of discarded candidate function
285285
templates when determining the primary template of an explicit specialization.
286+
- Fixed a crash in Microsoft compatibility mode where unqualified dependent base class
287+
lookup searches the bases of an incomplete class.
286288

287289
Bug Fixes to AST Handling
288290
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,8 +527,10 @@ class SExprBuilder {
527527
BlockInfo *CurrentBlockInfo = nullptr;
528528
};
529529

530+
#ifndef NDEBUG
530531
// Dump an SCFG to llvm::errs().
531532
void printSCFG(CFGWalker &Walker);
533+
#endif // NDEBUG
532534

533535
} // namespace threadSafety
534536
} // namespace clang

clang/include/clang/Basic/Builtins.td

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,12 @@ def Popcount : Builtin, BitInt_Long_LongLongTemplate {
688688
let Prototype = "int(unsigned T)";
689689
}
690690

691+
def Popcountg : Builtin {
692+
let Spellings = ["__builtin_popcountg"];
693+
let Attributes = [NoThrow, Const];
694+
let Prototype = "int(...)";
695+
}
696+
691697
def Clrsb : Builtin, BitInt_Long_LongLongTemplate {
692698
let Spellings = ["__builtin_clrsb"];
693699
let Attributes = [NoThrow, Const, Constexpr];
@@ -4524,6 +4530,12 @@ def HLSLCreateHandle : LangBuiltin<"HLSL_LANG"> {
45244530
let Prototype = "void*(unsigned char)";
45254531
}
45264532

4533+
def HLSLDotProduct : LangBuiltin<"HLSL_LANG"> {
4534+
let Spellings = ["__builtin_hlsl_dot"];
4535+
let Attributes = [NoThrow, Const];
4536+
let Prototype = "void(...)";
4537+
}
4538+
45274539
// Builtins for XRay.
45284540
def XRayCustomEvent : Builtin {
45294541
let Spellings = ["__xray_customevent"];

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12065,7 +12065,8 @@ def err_builtin_invalid_arg_type: Error <
1206512065
"pointer to a valid matrix element type|"
1206612066
"signed integer or floating point type|vector type|"
1206712067
"floating point type|"
12068-
"vector of integers}1 (was %2)">;
12068+
"vector of integers|"
12069+
"type of integer}1 (was %2)">;
1206912070

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

clang/include/clang/Sema/Sema.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14502,6 +14502,7 @@ class Sema final {
1450214502
bool CheckPPCBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID,
1450314503
CallExpr *TheCall);
1450414504
bool CheckAMDGCNBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
14505+
bool CheckHLSLBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
1450514506
bool CheckRISCVLMUL(CallExpr *TheCall, unsigned ArgNum);
1450614507
bool CheckRISCVBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID,
1450714508
CallExpr *TheCall);
@@ -14590,6 +14591,8 @@ class Sema final {
1459014591

1459114592
bool CheckPPCMMAType(QualType Type, SourceLocation TypeLoc);
1459214593

14594+
bool SemaBuiltinVectorMath(CallExpr *TheCall, QualType &Res);
14595+
bool SemaBuiltinVectorToScalarMath(CallExpr *TheCall);
1459314596
bool SemaBuiltinElementwiseMath(CallExpr *TheCall);
1459414597
bool SemaBuiltinElementwiseTernaryMath(CallExpr *TheCall);
1459514598
bool PrepareBuiltinElementwiseMathOneArgCall(CallExpr *TheCall);

clang/lib/AST/Interp/InterpBuiltin.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ static void pushInteger(InterpState &S, T Val, QualType QT) {
8585
pushInteger(S, APSInt(Val, !std::is_signed_v<T>), QT);
8686
else
8787
pushInteger(S,
88-
APSInt(APInt(sizeof(T) * 8, Val, std::is_signed_v<T>),
88+
APSInt(APInt(sizeof(T) * 8, static_cast<uint64_t>(Val),
89+
std::is_signed_v<T>),
8990
!std::is_signed_v<T>),
9091
QT);
9192
}
@@ -464,7 +465,7 @@ static bool interp__builtin_popcount(InterpState &S, CodePtr OpPC,
464465

465466
PrimType ArgT = *S.getContext().classify(Call->getArg(0)->getType());
466467
APSInt Val = peekToAPSInt(S.Stk, ArgT);
467-
pushInteger(S, APSInt(APInt(32, Val.popcount())), Call->getType());
468+
pushInteger(S, Val.popcount(), Call->getType());
468469
return true;
469470
}
470471

@@ -805,7 +806,7 @@ static bool interp__builtin_clz(InterpState &S, CodePtr OpPC,
805806
if (ZeroIsUndefined && Val == 0)
806807
return false;
807808

808-
pushInteger(S, APSInt(APInt(32, Val.countl_zero())), Call->getType());
809+
pushInteger(S, Val.countl_zero(), Call->getType());
809810
return true;
810811
}
811812

clang/lib/Analysis/FlowSensitive/Transfer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -671,9 +671,9 @@ class TransferVisitor : public ConstStmtVisitor<TransferVisitor> {
671671
}
672672

673673
if (!Type->isStructureOrClassType()) {
674-
// Until array initialization is implemented, we don't need to care about
675-
// cases where `getNumInits() > 1`.
676-
if (S->getNumInits() == 1)
674+
// Until array initialization is implemented, we skip arrays and don't
675+
// need to care about cases where `getNumInits() > 1`.
676+
if (!Type->isArrayType() && S->getNumInits() == 1)
677677
propagateValueOrStorageLocation(*S->getInit(0), *S, Env);
678678
return;
679679
}

clang/lib/Analysis/ThreadSafetyCommon.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ void SExprBuilder::exitCFG(const CFGBlock *Last) {
995995
IncompleteArgs.clear();
996996
}
997997

998-
/*
998+
#ifndef NDEBUG
999999
namespace {
10001000

10011001
class TILPrinter :
@@ -1016,4 +1016,4 @@ void printSCFG(CFGWalker &Walker) {
10161016

10171017
} // namespace threadSafety
10181018
} // namespace clang
1019-
*/
1019+
#endif // NDEBUG

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "llvm/IR/IntrinsicsAMDGPU.h"
4646
#include "llvm/IR/IntrinsicsARM.h"
4747
#include "llvm/IR/IntrinsicsBPF.h"
48+
#include "llvm/IR/IntrinsicsDirectX.h"
4849
#include "llvm/IR/IntrinsicsHexagon.h"
4950
#include "llvm/IR/IntrinsicsNVPTX.h"
5051
#include "llvm/IR/IntrinsicsPowerPC.h"
@@ -3296,7 +3297,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
32963297
case Builtin::BI__popcnt64:
32973298
case Builtin::BI__builtin_popcount:
32983299
case Builtin::BI__builtin_popcountl:
3299-
case Builtin::BI__builtin_popcountll: {
3300+
case Builtin::BI__builtin_popcountll:
3301+
case Builtin::BI__builtin_popcountg: {
33003302
Value *ArgValue = EmitScalarExpr(E->getArg(0));
33013303

33023304
llvm::Type *ArgType = ArgValue->getType();
@@ -6069,6 +6071,10 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
60696071
llvm_unreachable("Bad evaluation kind in EmitBuiltinExpr");
60706072
}
60716073

6074+
// EmitHLSLBuiltinExpr will check getLangOpts().HLSL
6075+
if (Value *V = EmitHLSLBuiltinExpr(BuiltinID, E))
6076+
return RValue::get(V);
6077+
60726078
if (getLangOpts().HIPStdPar && getLangOpts().CUDAIsDevice)
60736079
return EmitHipStdParUnsupportedBuiltin(this, FD);
60746080

@@ -18056,6 +18062,52 @@ llvm::Value *CodeGenFunction::EmitScalarOrConstFoldImmArg(unsigned ICEArguments,
1805618062
return Arg;
1805718063
}
1805818064

18065+
Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
18066+
const CallExpr *E) {
18067+
if (!getLangOpts().HLSL)
18068+
return nullptr;
18069+
18070+
switch (BuiltinID) {
18071+
case Builtin::BI__builtin_hlsl_dot: {
18072+
Value *Op0 = EmitScalarExpr(E->getArg(0));
18073+
Value *Op1 = EmitScalarExpr(E->getArg(1));
18074+
llvm::Type *T0 = Op0->getType();
18075+
llvm::Type *T1 = Op1->getType();
18076+
if (!T0->isVectorTy() && !T1->isVectorTy()) {
18077+
if (T0->isFloatingPointTy())
18078+
return Builder.CreateFMul(Op0, Op1, "dx.dot");
18079+
18080+
if (T0->isIntegerTy())
18081+
return Builder.CreateMul(Op0, Op1, "dx.dot");
18082+
18083+
// Bools should have been promoted
18084+
llvm_unreachable(
18085+
"Scalar dot product is only supported on ints and floats.");
18086+
}
18087+
// A VectorSplat should have happened
18088+
assert(T0->isVectorTy() && T1->isVectorTy() &&
18089+
"Dot product of vector and scalar is not supported.");
18090+
18091+
// A vector sext or sitofp should have happened
18092+
assert(T0->getScalarType() == T1->getScalarType() &&
18093+
"Dot product of vectors need the same element types.");
18094+
18095+
[[maybe_unused]] auto *VecTy0 =
18096+
E->getArg(0)->getType()->getAs<VectorType>();
18097+
[[maybe_unused]] auto *VecTy1 =
18098+
E->getArg(1)->getType()->getAs<VectorType>();
18099+
// A HLSLVectorTruncation should have happend
18100+
assert(VecTy0->getNumElements() == VecTy1->getNumElements() &&
18101+
"Dot product requires vectors to be of the same size.");
18102+
18103+
return Builder.CreateIntrinsic(
18104+
/*ReturnType*/ T0->getScalarType(), Intrinsic::dx_dot,
18105+
ArrayRef<Value *>{Op0, Op1}, nullptr, "dx.dot");
18106+
} break;
18107+
}
18108+
return nullptr;
18109+
}
18110+
1805918111
Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID,
1806018112
const CallExpr *E) {
1806118113
llvm::AtomicOrdering AO = llvm::AtomicOrdering::SequentiallyConsistent;

clang/lib/CodeGen/CodeGenFunction.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4427,6 +4427,7 @@ class CodeGenFunction : public CodeGenTypeCache {
44274427
llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E);
44284428
llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
44294429
llvm::Value *EmitAMDGPUBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
4430+
llvm::Value *EmitHLSLBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
44304431
llvm::Value *EmitScalarOrConstFoldImmArg(unsigned ICEArguments, unsigned Idx,
44314432
const CallExpr *E);
44324433
llvm::Value *EmitSystemZBuiltinExpr(unsigned BuiltinID, const CallExpr *E);

clang/lib/Driver/ToolChain.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -759,19 +759,29 @@ std::string ToolChain::getCompilerRT(const ArgList &Args, StringRef Component,
759759
// Check for runtime files in the new layout without the architecture first.
760760
std::string CRTBasename =
761761
buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/false);
762+
SmallString<128> Path;
762763
for (const auto &LibPath : getLibraryPaths()) {
763764
SmallString<128> P(LibPath);
764765
llvm::sys::path::append(P, CRTBasename);
765766
if (getVFS().exists(P))
766767
return std::string(P);
768+
if (Path.empty())
769+
Path = P;
767770
}
771+
if (getTriple().isOSAIX())
772+
Path.clear();
768773

769-
// Fall back to the old expected compiler-rt name if the new one does not
770-
// exist.
774+
// Check the filename for the old layout if the new one does not exist.
771775
CRTBasename =
772776
buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/true);
773-
SmallString<128> Path(getCompilerRTPath());
774-
llvm::sys::path::append(Path, CRTBasename);
777+
SmallString<128> OldPath(getCompilerRTPath());
778+
llvm::sys::path::append(OldPath, CRTBasename);
779+
if (Path.empty() || getVFS().exists(OldPath))
780+
return std::string(OldPath);
781+
782+
// If none is found, use a file name from the new layout, which may get
783+
// printed in an error message, aiding users in knowing what Clang is
784+
// looking for.
775785
return std::string(Path);
776786
}
777787

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,13 +1322,16 @@ void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args,
13221322
// add the correct libraries to link against as dependents in the object
13231323
// file.
13241324
if (!TC.getTriple().isKnownWindowsMSVCEnvironment()) {
1325-
StringRef f128LibName = TC.getDriver().getFlangF128MathLibrary();
1326-
f128LibName.consume_front_insensitive("lib");
1327-
if (!f128LibName.empty()) {
1325+
StringRef F128LibName = TC.getDriver().getFlangF128MathLibrary();
1326+
F128LibName.consume_front_insensitive("lib");
1327+
if (!F128LibName.empty()) {
1328+
bool AsNeeded = !TC.getTriple().isOSAIX();
13281329
CmdArgs.push_back("-lFortranFloat128Math");
1329-
addAsNeededOption(TC, Args, CmdArgs, /*as_needed=*/true);
1330-
CmdArgs.push_back(Args.MakeArgString("-l" + f128LibName));
1331-
addAsNeededOption(TC, Args, CmdArgs, /*as_needed=*/false);
1330+
if (AsNeeded)
1331+
addAsNeededOption(TC, Args, CmdArgs, /*as_needed=*/true);
1332+
CmdArgs.push_back(Args.MakeArgString("-l" + F128LibName));
1333+
if (AsNeeded)
1334+
addAsNeededOption(TC, Args, CmdArgs, /*as_needed=*/false);
13321335
}
13331336
CmdArgs.push_back("-lFortranRuntime");
13341337
CmdArgs.push_back("-lFortranDecimal");

0 commit comments

Comments
 (0)