Skip to content

Commit 23aaa40

Browse files
authored
merge main into amd-staging (llvm#2078)
2 parents 8f97359 + 97774a8 commit 23aaa40

File tree

169 files changed

+14859
-2579
lines changed

Some content is hidden

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

169 files changed

+14859
-2579
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,8 @@ OpenMP Support
921921
- Added support 'no_openmp_constructs' assumption clause.
922922
- Added support for 'self_maps' in map and requirement clause.
923923
- Added support for 'omp stripe' directive.
924+
- Fixed a crashing bug with ``omp tile sizes`` if the argument to ``sizes`` was
925+
an invalid expression. (#GH139073)
924926

925927
Improvements
926928
^^^^^^^^^^^^

clang/include/clang/InstallAPI/DylibVerifier.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,31 @@ enum class VerificationMode {
2525
Pedantic,
2626
};
2727

28-
using LibAttrs = llvm::StringMap<ArchitectureSet>;
2928
using ReexportedInterfaces = llvm::SmallVector<llvm::MachO::InterfaceFile, 8>;
3029

30+
/// Represents dynamic library specific attributes that are tied to
31+
/// architecture slices. It is commonly used for comparing options
32+
/// passed on the command line to installapi and what exists in dylib load
33+
/// commands.
34+
class LibAttrs {
35+
public:
36+
using Entry = std::pair<std::string, ArchitectureSet>;
37+
using AttrsToArchs = llvm::SmallVector<Entry, 10>;
38+
39+
// Mutable access to architecture set tied to the input attribute.
40+
ArchitectureSet &getArchSet(StringRef Attr);
41+
// Get entry based on the attribute.
42+
std::optional<Entry> find(StringRef Attr) const;
43+
// Immutable access to underlying container.
44+
const AttrsToArchs &get() const { return LibraryAttributes; };
45+
// Mutable access to underlying container.
46+
AttrsToArchs &get() { return LibraryAttributes; };
47+
bool operator==(const LibAttrs &Other) const { return Other.get() == get(); };
48+
49+
private:
50+
AttrsToArchs LibraryAttributes;
51+
};
52+
3153
// Pointers to information about a zippered declaration used for
3254
// querying and reporting violations against different
3355
// declarations that all map to the same symbol.

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 61 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
238238
case CK_DerivedToBaseMemberPointer: {
239239
assert(classifyPrim(CE->getType()) == PT_MemberPtr);
240240
assert(classifyPrim(SubExpr->getType()) == PT_MemberPtr);
241-
const auto *FromMP = SubExpr->getType()->getAs<MemberPointerType>();
242-
const auto *ToMP = CE->getType()->getAs<MemberPointerType>();
241+
const auto *FromMP = SubExpr->getType()->castAs<MemberPointerType>();
242+
const auto *ToMP = CE->getType()->castAs<MemberPointerType>();
243243

244244
unsigned DerivedOffset =
245245
Ctx.collectBaseOffset(ToMP->getMostRecentCXXRecordDecl(),
@@ -254,8 +254,8 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
254254
case CK_BaseToDerivedMemberPointer: {
255255
assert(classifyPrim(CE) == PT_MemberPtr);
256256
assert(classifyPrim(SubExpr) == PT_MemberPtr);
257-
const auto *FromMP = SubExpr->getType()->getAs<MemberPointerType>();
258-
const auto *ToMP = CE->getType()->getAs<MemberPointerType>();
257+
const auto *FromMP = SubExpr->getType()->castAs<MemberPointerType>();
258+
const auto *ToMP = CE->getType()->castAs<MemberPointerType>();
259259

260260
unsigned DerivedOffset =
261261
Ctx.collectBaseOffset(FromMP->getMostRecentCXXRecordDecl(),
@@ -320,37 +320,38 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
320320
}
321321

322322
case CK_IntegralToFloating: {
323-
std::optional<PrimType> FromT = classify(SubExpr->getType());
324-
if (!FromT)
323+
if (!CE->getType()->isRealFloatingType())
325324
return false;
326-
327325
if (!this->visit(SubExpr))
328326
return false;
329-
330327
const auto *TargetSemantics = &Ctx.getFloatSemantics(CE->getType());
331-
return this->emitCastIntegralFloating(*FromT, TargetSemantics,
332-
getFPOptions(CE), CE);
328+
return this->emitCastIntegralFloating(
329+
classifyPrim(SubExpr), TargetSemantics, getFPOptions(CE), CE);
333330
}
334331

335-
case CK_FloatingToBoolean:
336-
case CK_FloatingToIntegral: {
337-
338-
std::optional<PrimType> ToT = classify(CE->getType());
339-
340-
if (!ToT)
332+
case CK_FloatingToBoolean: {
333+
if (!SubExpr->getType()->isRealFloatingType() ||
334+
!CE->getType()->isBooleanType())
341335
return false;
342-
336+
if (const auto *FL = dyn_cast<FloatingLiteral>(SubExpr))
337+
return this->emitConstBool(FL->getValue().isNonZero(), CE);
343338
if (!this->visit(SubExpr))
344339
return false;
340+
return this->emitCastFloatingIntegralBool(getFPOptions(CE), CE);
341+
}
345342

343+
case CK_FloatingToIntegral: {
344+
if (!this->visit(SubExpr))
345+
return false;
346+
PrimType ToT = classifyPrim(CE);
346347
if (ToT == PT_IntAP)
347348
return this->emitCastFloatingIntegralAP(Ctx.getBitWidth(CE->getType()),
348349
getFPOptions(CE), CE);
349350
if (ToT == PT_IntAPS)
350351
return this->emitCastFloatingIntegralAPS(Ctx.getBitWidth(CE->getType()),
351352
getFPOptions(CE), CE);
352353

353-
return this->emitCastFloatingIntegral(*ToT, getFPOptions(CE), CE);
354+
return this->emitCastFloatingIntegral(ToT, getFPOptions(CE), CE);
354355
}
355356

356357
case CK_NullToPointer:
@@ -395,9 +396,7 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
395396
case CK_ArrayToPointerDecay: {
396397
if (!this->visit(SubExpr))
397398
return false;
398-
if (!this->emitArrayDecay(CE))
399-
return false;
400-
return true;
399+
return this->emitArrayDecay(CE);
401400
}
402401

403402
case CK_IntegralToPointer: {
@@ -480,47 +479,63 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
480479
return this->emitBuiltinBitCast(CE);
481480

482481
case CK_IntegralToBoolean:
483-
case CK_FixedPointToBoolean:
482+
case CK_FixedPointToBoolean: {
483+
// HLSL uses this to cast to one-element vectors.
484+
std::optional<PrimType> FromT = classify(SubExpr->getType());
485+
if (!FromT)
486+
return false;
487+
488+
if (const auto *IL = dyn_cast<IntegerLiteral>(SubExpr))
489+
return this->emitConst(IL->getValue(), CE);
490+
if (!this->visit(SubExpr))
491+
return false;
492+
return this->emitCast(*FromT, classifyPrim(CE), CE);
493+
}
494+
484495
case CK_BooleanToSignedIntegral:
485496
case CK_IntegralCast: {
486497
std::optional<PrimType> FromT = classify(SubExpr->getType());
487498
std::optional<PrimType> ToT = classify(CE->getType());
488-
489499
if (!FromT || !ToT)
490500
return false;
491501

492-
if (!this->visit(SubExpr))
493-
return false;
502+
// Try to emit a casted known constant value directly.
503+
if (const auto *IL = dyn_cast<IntegerLiteral>(SubExpr)) {
504+
if (ToT != PT_IntAP && ToT != PT_IntAPS && FromT != PT_IntAP &&
505+
FromT != PT_IntAPS && !CE->getType()->isEnumeralType())
506+
return this->emitConst(IL->getValue(), CE);
507+
if (!this->emitConst(IL->getValue(), SubExpr))
508+
return false;
509+
} else {
510+
if (!this->visit(SubExpr))
511+
return false;
512+
}
494513

495514
// Possibly diagnose casts to enum types if the target type does not
496515
// have a fixed size.
497516
if (Ctx.getLangOpts().CPlusPlus && CE->getType()->isEnumeralType()) {
498-
if (const auto *ET = CE->getType().getCanonicalType()->getAs<EnumType>();
499-
ET && !ET->getDecl()->isFixed()) {
517+
if (const auto *ET = CE->getType().getCanonicalType()->castAs<EnumType>();
518+
!ET->getDecl()->isFixed()) {
500519
if (!this->emitCheckEnumValue(*FromT, ET->getDecl(), CE))
501520
return false;
502521
}
503522
}
504523

505-
auto maybeNegate = [&]() -> bool {
506-
if (CE->getCastKind() == CK_BooleanToSignedIntegral)
507-
return this->emitNeg(*ToT, CE);
508-
return true;
509-
};
510-
511-
if (ToT == PT_IntAP)
512-
return this->emitCastAP(*FromT, Ctx.getBitWidth(CE->getType()), CE) &&
513-
maybeNegate();
514-
if (ToT == PT_IntAPS)
515-
return this->emitCastAPS(*FromT, Ctx.getBitWidth(CE->getType()), CE) &&
516-
maybeNegate();
517-
518-
if (FromT == ToT)
519-
return true;
520-
if (!this->emitCast(*FromT, *ToT, CE))
521-
return false;
522-
523-
return maybeNegate();
524+
if (ToT == PT_IntAP) {
525+
if (!this->emitCastAP(*FromT, Ctx.getBitWidth(CE->getType()), CE))
526+
return false;
527+
} else if (ToT == PT_IntAPS) {
528+
if (!this->emitCastAPS(*FromT, Ctx.getBitWidth(CE->getType()), CE))
529+
return false;
530+
} else {
531+
if (FromT == ToT)
532+
return true;
533+
if (!this->emitCast(*FromT, *ToT, CE))
534+
return false;
535+
}
536+
if (CE->getCastKind() == CK_BooleanToSignedIntegral)
537+
return this->emitNeg(*ToT, CE);
538+
return true;
524539
}
525540

526541
case CK_PointerToBoolean:

clang/lib/AST/ByteCode/Context.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,6 @@ std::optional<PrimType> Context::classify(QualType T) const {
219219
if (T->isBooleanType())
220220
return PT_Bool;
221221

222-
// We map these to primitive arrays.
223-
if (T->isAnyComplexType() || T->isVectorType())
224-
return std::nullopt;
225-
226222
if (T->isSignedIntegerOrEnumerationType()) {
227223
switch (Ctx.getIntWidth(T)) {
228224
case 64:
@@ -259,13 +255,9 @@ std::optional<PrimType> Context::classify(QualType T) const {
259255
if (T->isNullPtrType())
260256
return PT_Ptr;
261257

262-
if (T->isFloatingType())
258+
if (T->isRealFloatingType())
263259
return PT_Float;
264260

265-
if (T->isSpecificBuiltinType(BuiltinType::BoundMember) ||
266-
T->isMemberPointerType())
267-
return PT_MemberPtr;
268-
269261
if (T->isFunctionPointerType() || T->isFunctionReferenceType() ||
270262
T->isFunctionType() || T->isBlockPointerType())
271263
return PT_Ptr;
@@ -279,9 +271,14 @@ std::optional<PrimType> Context::classify(QualType T) const {
279271
if (const auto *DT = dyn_cast<DecltypeType>(T))
280272
return classify(DT->getUnderlyingType());
281273

274+
if (T->isSpecificBuiltinType(BuiltinType::BoundMember) ||
275+
T->isMemberPointerType())
276+
return PT_MemberPtr;
277+
282278
if (T->isFixedPointType())
283279
return PT_FixedPoint;
284280

281+
// Vector and complex types get here.
285282
return std::nullopt;
286283
}
287284

clang/lib/AST/DeclBase.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -695,27 +695,31 @@ static AvailabilityResult CheckAvailability(ASTContext &Context,
695695
if (!A->getIntroduced().empty() &&
696696
EnclosingVersion < A->getIntroduced()) {
697697
IdentifierInfo *IIEnv = A->getEnvironment();
698-
StringRef TargetEnv =
699-
Context.getTargetInfo().getTriple().getEnvironmentName();
700-
StringRef EnvName = llvm::Triple::getEnvironmentTypeName(
701-
Context.getTargetInfo().getTriple().getEnvironment());
702-
// Matching environment or no environment on attribute
703-
if (!IIEnv || (!TargetEnv.empty() && IIEnv->getName() == TargetEnv)) {
698+
auto &Triple = Context.getTargetInfo().getTriple();
699+
StringRef TargetEnv = Triple.getEnvironmentName();
700+
StringRef EnvName =
701+
llvm::Triple::getEnvironmentTypeName(Triple.getEnvironment());
702+
// Matching environment or no environment on attribute.
703+
if (!IIEnv || (Triple.hasEnvironment() && IIEnv->getName() == TargetEnv)) {
704704
if (Message) {
705705
Message->clear();
706706
llvm::raw_string_ostream Out(*Message);
707707
VersionTuple VTI(A->getIntroduced());
708-
Out << "introduced in " << PrettyPlatformName << " " << VTI << " "
709-
<< EnvName << HintMessage;
708+
Out << "introduced in " << PrettyPlatformName << " " << VTI;
709+
if (Triple.hasEnvironment())
710+
Out << " " << EnvName;
711+
Out << HintMessage;
710712
}
711713
}
712-
// Non-matching environment or no environment on target
714+
// Non-matching environment or no environment on target.
713715
else {
714716
if (Message) {
715717
Message->clear();
716718
llvm::raw_string_ostream Out(*Message);
717-
Out << "not available on " << PrettyPlatformName << " " << EnvName
718-
<< HintMessage;
719+
Out << "not available on " << PrettyPlatformName;
720+
if (Triple.hasEnvironment())
721+
Out << " " << EnvName;
722+
Out << HintMessage;
719723
}
720724
}
721725

clang/lib/AST/Type.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2301,8 +2301,7 @@ bool Type::hasUnsignedIntegerRepresentation() const {
23012301

23022302
bool Type::isFloatingType() const {
23032303
if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2304-
return BT->getKind() >= BuiltinType::Half &&
2305-
BT->getKind() <= BuiltinType::Ibm128;
2304+
return BT->isFloatingPoint();
23062305
if (const auto *CT = dyn_cast<ComplexType>(CanonicalType))
23072306
return CT->getElementType()->isFloatingType();
23082307
return false;

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4180,11 +4180,28 @@ static Value *emitPointerArithmetic(CodeGenFunction &CGF,
41804180
// The index is not pointer-sized.
41814181
// The pointer type is not byte-sized.
41824182
//
4183-
if (BinaryOperator::isNullPointerArithmeticExtension(CGF.getContext(),
4184-
op.Opcode,
4185-
expr->getLHS(),
4186-
expr->getRHS()))
4187-
return CGF.Builder.CreateIntToPtr(index, pointer->getType());
4183+
// Note that we do not suppress the pointer overflow check in this case.
4184+
if (BinaryOperator::isNullPointerArithmeticExtension(
4185+
CGF.getContext(), op.Opcode, expr->getLHS(), expr->getRHS())) {
4186+
Value *Ptr = CGF.Builder.CreateIntToPtr(index, pointer->getType());
4187+
if (CGF.getLangOpts().PointerOverflowDefined ||
4188+
!CGF.SanOpts.has(SanitizerKind::PointerOverflow) ||
4189+
NullPointerIsDefined(CGF.Builder.GetInsertBlock()->getParent(),
4190+
PtrTy->getPointerAddressSpace()))
4191+
return Ptr;
4192+
// The inbounds GEP of null is valid iff the index is zero.
4193+
CodeGenFunction::SanitizerScope SanScope(&CGF);
4194+
Value *IsZeroIndex = CGF.Builder.CreateIsNull(index);
4195+
llvm::Constant *StaticArgs[] = {
4196+
CGF.EmitCheckSourceLocation(op.E->getExprLoc())};
4197+
llvm::Type *IntPtrTy = DL.getIntPtrType(PtrTy);
4198+
Value *IntPtr = llvm::Constant::getNullValue(IntPtrTy);
4199+
Value *ComputedGEP = CGF.Builder.CreateZExtOrTrunc(index, IntPtrTy);
4200+
Value *DynamicArgs[] = {IntPtr, ComputedGEP};
4201+
CGF.EmitCheck({{IsZeroIndex, SanitizerKind::SO_PointerOverflow}},
4202+
SanitizerHandler::PointerOverflow, StaticArgs, DynamicArgs);
4203+
return Ptr;
4204+
}
41884205

41894206
if (width != DL.getIndexTypeSizeInBits(PtrTy)) {
41904207
// Zero-extend or sign-extend the pointer value according to

clang/lib/Driver/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ add_clang_library(clangDriver
5454
ToolChains/CrossWindows.cpp
5555
ToolChains/CSKYToolChain.cpp
5656
ToolChains/Cuda.cpp
57+
ToolChains/Cygwin.cpp
5758
ToolChains/Darwin.cpp
5859
ToolChains/DragonFly.cpp
5960
ToolChains/Flang.cpp

clang/lib/Driver/Driver.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "ToolChains/Clang.h"
1818
#include "ToolChains/CrossWindows.h"
1919
#include "ToolChains/Cuda.h"
20+
#include "ToolChains/Cygwin.h"
2021
#include "ToolChains/Darwin.h"
2122
#include "ToolChains/DragonFly.h"
2223
#include "ToolChains/FreeBSD.h"
@@ -6916,6 +6917,9 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
69166917
case llvm::Triple::GNU:
69176918
TC = std::make_unique<toolchains::MinGW>(*this, Target, Args);
69186919
break;
6920+
case llvm::Triple::Cygnus:
6921+
TC = std::make_unique<toolchains::Cygwin>(*this, Target, Args);
6922+
break;
69196923
case llvm::Triple::Itanium:
69206924
TC = std::make_unique<toolchains::CrossWindowsToolChain>(*this, Target,
69216925
Args);

0 commit comments

Comments
 (0)