Skip to content

Commit 86e2a2f

Browse files
authored
Merge pull request llvm#358 from AMD-Lightning-Internal/upstream_merge_202501291026
merge main into amd-staging
2 parents f465cb3 + 5bc4ce5 commit 86e2a2f

File tree

391 files changed

+4551
-2437
lines changed

Some content is hidden

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

391 files changed

+4551
-2437
lines changed

clang/docs/LanguageExtensions.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,9 @@ The integer elementwise intrinsics, including ``__builtin_elementwise_popcount``
757757
``__builtin_elementwise_bitreverse``, ``__builtin_elementwise_add_sat``,
758758
``__builtin_elementwise_sub_sat`` can be called in a ``constexpr`` context.
759759

760+
No implicit promotion of integer types takes place. The mixing of integer types
761+
of different sizes and signs is forbidden in binary and ternary builtins.
762+
760763
============================================== ====================================================================== =========================================
761764
Name Operation Supported element types
762765
============================================== ====================================================================== =========================================

clang/include/clang/Basic/BuiltinsAMDGPU.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,8 @@ TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v4i16, "V4sV4s*1", "nc", "gf
504504
TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v4f16, "V4hV4h*1", "nc", "gfx12-insts,wavefrontsize64")
505505
TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v4bf16, "V4yV4y*1", "nc", "gfx12-insts,wavefrontsize64")
506506

507+
TARGET_BUILTIN(__builtin_amdgcn_ds_bpermute_fi_b32, "iii", "nc", "gfx12-insts")
508+
507509
//===----------------------------------------------------------------------===//
508510
// WMMA builtins.
509511
// Postfix w32 indicates the builtin requires wavefront size of 32.

clang/include/clang/Sema/Sema.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2331,7 +2331,8 @@ class Sema final : public SemaBase {
23312331
const FunctionProtoType *Proto);
23322332

23332333
/// \param FPOnly restricts the arguments to floating-point types.
2334-
bool BuiltinVectorMath(CallExpr *TheCall, QualType &Res, bool FPOnly = false);
2334+
std::optional<QualType> BuiltinVectorMath(CallExpr *TheCall,
2335+
bool FPOnly = false);
23352336
bool BuiltinVectorToScalarMath(CallExpr *TheCall);
23362337

23372338
void checkLifetimeCaptureBy(FunctionDecl *FDecl, bool IsMemberFunction,
@@ -7499,10 +7500,15 @@ class Sema final : public SemaBase {
74997500
return K == ConditionKind::Switch ? Context.IntTy : Context.BoolTy;
75007501
}
75017502

7502-
// UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
7503-
// functions and arrays to their respective pointers (C99 6.3.2.1).
7503+
// UsualUnaryConversions - promotes integers (C99 6.3.1.1p2), converts
7504+
// functions and arrays to their respective pointers (C99 6.3.2.1), and
7505+
// promotes floating-piont types according to the language semantics.
75047506
ExprResult UsualUnaryConversions(Expr *E);
75057507

7508+
// UsualUnaryFPConversions - promotes floating-point types according to the
7509+
// current language semantics.
7510+
ExprResult UsualUnaryFPConversions(Expr *E);
7511+
75067512
/// CallExprUnaryConversions - a special case of an unary conversion
75077513
/// performed on a function designator of a call expression.
75087514
ExprResult CallExprUnaryConversions(Expr *E);
@@ -7565,6 +7571,11 @@ class Sema final : public SemaBase {
75657571
ExprResult DefaultVariadicArgumentPromotion(Expr *E, VariadicCallType CT,
75667572
FunctionDecl *FDecl);
75677573

7574+
// Check that the usual arithmetic conversions can be performed on this pair
7575+
// of expressions that might be of enumeration type.
7576+
void checkEnumArithmeticConversions(Expr *LHS, Expr *RHS, SourceLocation Loc,
7577+
Sema::ArithConvKind ACK);
7578+
75687579
// UsualArithmeticConversions - performs the UsualUnaryConversions on it's
75697580
// operands and then handles various conversions that are common to binary
75707581
// operators (C99 6.3.1.8). If both operands aren't arithmetic, this

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6175,7 +6175,7 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
61756175
}
61766176

61776177
if (D->getType()->isReferenceType())
6178-
return false; // FIXME: Do we need to emit InvalidDeclRef?
6178+
return this->emitDummyPtr(D, E);
61796179
}
61806180

61816181
// In case we need to re-visit a declaration.

clang/lib/AST/ByteCode/Descriptor.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,8 @@ QualType Descriptor::getElemQualType() const {
409409
assert(isArray());
410410
QualType T = getType();
411411
if (T->isPointerOrReferenceType())
412-
return T->getPointeeType();
412+
T = T->getPointeeType();
413+
413414
if (const auto *AT = T->getAsArrayTypeUnsafe()) {
414415
// For primitive arrays, we don't save a QualType at all,
415416
// just a PrimType. Try to figure out the QualType here.
@@ -424,7 +425,8 @@ QualType Descriptor::getElemQualType() const {
424425
return CT->getElementType();
425426
if (const auto *CT = T->getAs<VectorType>())
426427
return CT->getElementType();
427-
llvm_unreachable("Array that's not an array/complex/vector type?");
428+
429+
return T;
428430
}
429431

430432
SourceLocation Descriptor::getLocation() const {

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ static bool diagnoseUnknownDecl(InterpState &S, CodePtr OpPC,
6868
const SourceInfo &E = S.Current->getSource(OpPC);
6969

7070
if (isa<ParmVarDecl>(D)) {
71+
if (D->getType()->isReferenceType())
72+
return false;
73+
7174
if (S.getLangOpts().CPlusPlus11) {
7275
S.FFDiag(E, diag::note_constexpr_function_param_value_unknown) << D;
7376
S.Note(D->getLocation(), diag::note_declared_at) << D->getSourceRange();
@@ -1287,6 +1290,12 @@ bool Call(InterpState &S, CodePtr OpPC, const Function *Func,
12871290

12881291
const Pointer &ThisPtr = S.Stk.peek<Pointer>(ThisOffset);
12891292

1293+
// C++23 [expr.const]p5.6
1294+
// an invocation of a virtual function ([class.virtual]) for an object whose
1295+
// dynamic type is constexpr-unknown;
1296+
if (ThisPtr.isDummy() && Func->isVirtual())
1297+
return false;
1298+
12901299
// If the current function is a lambda static invoker and
12911300
// the function we're about to call is a lambda call operator,
12921301
// skip the CheckInvoke, since the ThisPtr is a null pointer
@@ -1661,17 +1670,6 @@ bool GetTypeidPtr(InterpState &S, CodePtr OpPC, const Type *TypeInfoType) {
16611670
if (!P.isBlockPointer())
16621671
return false;
16631672

1664-
if (P.isDummy()) {
1665-
QualType StarThisType =
1666-
S.getASTContext().getLValueReferenceType(P.getType());
1667-
S.FFDiag(S.Current->getSource(OpPC),
1668-
diag::note_constexpr_polymorphic_unknown_dynamic_type)
1669-
<< AK_TypeId
1670-
<< P.toAPValue(S.getASTContext())
1671-
.getAsString(S.getASTContext(), StarThisType);
1672-
return false;
1673-
}
1674-
16751673
S.Stk.push<Pointer>(P.getType().getTypePtr(), TypeInfoType);
16761674
return true;
16771675
}

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,9 +1538,12 @@ static bool interp__builtin_constant_p(InterpState &S, CodePtr OpPC,
15381538
if (ArgType->isIntegralOrEnumerationType() || ArgType->isFloatingType() ||
15391539
ArgType->isAnyComplexType() || ArgType->isPointerType() ||
15401540
ArgType->isNullPtrType()) {
1541+
auto PrevDiags = S.getEvalStatus().Diag;
1542+
S.getEvalStatus().Diag = nullptr;
15411543
InterpStack Stk;
15421544
Compiler<EvalEmitter> C(S.Ctx, S.P, S, Stk);
15431545
auto Res = C.interpretExpr(Arg, /*ConvertResultToRValue=*/Arg->isGLValue());
1546+
S.getEvalStatus().Diag = PrevDiags;
15441547
if (Res.isInvalid()) {
15451548
C.cleanup();
15461549
Stk.clear();

clang/lib/AST/ByteCode/Pointer.cpp

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const {
209209
return ASTCtx.toCharUnitsFromBits(Layout.getFieldOffset(FieldIndex));
210210
};
211211

212+
bool UsePath = true;
213+
if (getType()->isLValueReferenceType())
214+
UsePath = false;
215+
212216
// Build the path into the object.
213217
Pointer Ptr = *this;
214218
while (Ptr.isField() || Ptr.isArrayElement()) {
@@ -217,38 +221,42 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const {
217221
// An array root may still be an array element itself.
218222
if (Ptr.isArrayElement()) {
219223
Ptr = Ptr.expand();
224+
const Descriptor *Desc = Ptr.getFieldDesc();
220225
unsigned Index = Ptr.getIndex();
221-
Path.push_back(APValue::LValuePathEntry::ArrayIndex(Index));
222-
QualType ElemType = Ptr.getFieldDesc()->getElemQualType();
226+
QualType ElemType = Desc->getElemQualType();
223227
Offset += (Index * ASTCtx.getTypeSizeInChars(ElemType));
228+
if (Ptr.getArray().getType()->isArrayType())
229+
Path.push_back(APValue::LValuePathEntry::ArrayIndex(Index));
224230
Ptr = Ptr.getArray();
225231
} else {
226-
Path.push_back(APValue::LValuePathEntry(
227-
{Ptr.getFieldDesc()->asDecl(), /*IsVirtual=*/false}));
232+
const Descriptor *Desc = Ptr.getFieldDesc();
233+
const auto *Dcl = Desc->asDecl();
234+
Path.push_back(APValue::LValuePathEntry({Dcl, /*IsVirtual=*/false}));
228235

229-
if (const auto *FD =
230-
dyn_cast_if_present<FieldDecl>(Ptr.getFieldDesc()->asDecl()))
236+
if (const auto *FD = dyn_cast_if_present<FieldDecl>(Dcl))
231237
Offset += getFieldOffset(FD);
232238

233239
Ptr = Ptr.getBase();
234240
}
235241
} else if (Ptr.isArrayElement()) {
236242
Ptr = Ptr.expand();
243+
const Descriptor *Desc = Ptr.getFieldDesc();
237244
unsigned Index;
238245
if (Ptr.isOnePastEnd())
239246
Index = Ptr.getArray().getNumElems();
240247
else
241248
Index = Ptr.getIndex();
242249

243-
QualType ElemType = Ptr.getFieldDesc()->getElemQualType();
250+
QualType ElemType = Desc->getElemQualType();
244251
Offset += (Index * ASTCtx.getTypeSizeInChars(ElemType));
245-
Path.push_back(APValue::LValuePathEntry::ArrayIndex(Index));
252+
if (Ptr.getArray().getType()->isArrayType())
253+
Path.push_back(APValue::LValuePathEntry::ArrayIndex(Index));
246254
Ptr = Ptr.getArray();
247255
} else {
256+
const Descriptor *Desc = Ptr.getFieldDesc();
248257
bool IsVirtual = false;
249258

250259
// Create a path entry for the field.
251-
const Descriptor *Desc = Ptr.getFieldDesc();
252260
if (const auto *BaseOrMember = Desc->asDecl()) {
253261
if (const auto *FD = dyn_cast<FieldDecl>(BaseOrMember)) {
254262
Ptr = Ptr.getBase();
@@ -281,8 +289,11 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const {
281289
// Just invert the order of the elements.
282290
std::reverse(Path.begin(), Path.end());
283291

284-
return APValue(Base, Offset, Path, /*IsOnePastEnd=*/isOnePastEnd(),
285-
/*IsNullPtr=*/false);
292+
if (UsePath)
293+
return APValue(Base, Offset, Path,
294+
/*IsOnePastEnd=*/!isElementPastEnd() && isOnePastEnd());
295+
296+
return APValue(Base, Offset, APValue::NoLValuePath());
286297
}
287298

288299
void Pointer::print(llvm::raw_ostream &OS) const {

clang/lib/AST/ByteCode/Pointer.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,8 +630,7 @@ class Pointer {
630630
if (isUnknownSizeArray())
631631
return false;
632632

633-
return isElementPastEnd() || isPastEnd() ||
634-
(getSize() == getOffset() && !isZeroSizeArray());
633+
return isPastEnd() || (getSize() == getOffset() && !isZeroSizeArray());
635634
}
636635

637636
/// Checks if the pointer points past the end of the object.

clang/lib/Basic/Targets/ARM.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,8 @@ bool ARMTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
608608
HasBTI = 1;
609609
} else if (Feature == "+fullbf16") {
610610
HasFullBFloat16 = true;
611+
} else if (Feature == "+execute-only") {
612+
TLSSupported = false;
611613
}
612614
}
613615

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4286,7 +4286,7 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
42864286
}
42874287
}
42884288

4289-
// Check if -fopenmp is specified and set default version to 5.0.
4289+
// Check if -fopenmp is specified and set default version to 5.1.
42904290
Opts.OpenMP = Args.hasArg(OPT_fopenmp) ? 51 : 0;
42914291
// Check if -fopenmp-simd is specified.
42924292
bool IsSimdSpecified =

clang/lib/Frontend/InitPreprocessor.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,9 +1466,15 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
14661466
case 50:
14671467
Builder.defineMacro("_OPENMP", "201811");
14681468
break;
1469+
case 51:
1470+
Builder.defineMacro("_OPENMP", "202011");
1471+
break;
14691472
case 52:
14701473
Builder.defineMacro("_OPENMP", "202111");
14711474
break;
1475+
case 60:
1476+
Builder.defineMacro("_OPENMP", "202411");
1477+
break;
14721478
default: // case 51:
14731479
// Default version is OpenMP 5.1
14741480
Builder.defineMacro("_OPENMP", "202011");

0 commit comments

Comments
 (0)