Skip to content

Commit 41e31e9

Browse files
committed
Merge remote-tracking branch 'origin/main' into lv-use-scev-for-min-iter
2 parents 86ea8c3 + ee0e17a commit 41e31e9

File tree

85 files changed

+2768
-822
lines changed

Some content is hidden

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

85 files changed

+2768
-822
lines changed

clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,10 +474,8 @@ void ProTypeMemberInitCheck::checkMissingMemberInitializer(
474474
// It only includes fields that have not been fixed
475475
SmallPtrSet<const FieldDecl *, 16> AllFieldsToInit;
476476
forEachField(ClassDecl, FieldsToInit, [&](const FieldDecl *F) {
477-
if (!HasRecordClassMemberSet.contains(F)) {
477+
if (HasRecordClassMemberSet.insert(F).second)
478478
AllFieldsToInit.insert(F);
479-
HasRecordClassMemberSet.insert(F);
480-
}
481479
});
482480
if (FieldsToInit.empty())
483481
return;

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ Bug Fixes to C++ Support
481481
- Clang now uses the correct set of template argument lists when comparing the constraints of
482482
out-of-line definitions and member templates explicitly specialized for a given implicit instantiation of
483483
a class template. (#GH102320)
484+
- Fix a crash when parsing a pseudo destructor involving an invalid type. (#GH111460)
484485

485486
Bug Fixes to AST Handling
486487
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/AST/ByteCode/Function.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ class Function final {
222222
return ParamOffsets[ParamIndex];
223223
}
224224

225+
PrimType getParamType(unsigned ParamIndex) const {
226+
return ParamTypes[ParamIndex];
227+
}
228+
225229
private:
226230
/// Construct a function representing an actual function.
227231
Function(Program &P, FunctionDeclTy Source, unsigned ArgSize,

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "clang/AST/Expr.h"
2323
#include "clang/AST/ExprCXX.h"
2424
#include "clang/Basic/DiagnosticSema.h"
25+
#include "clang/Basic/TargetInfo.h"
2526
#include "llvm/ADT/APSInt.h"
2627
#include "llvm/ADT/StringExtras.h"
2728
#include <limits>
@@ -1415,6 +1416,46 @@ bool InvalidShuffleVectorIndex(InterpState &S, CodePtr OpPC, uint32_t Index) {
14151416
return false;
14161417
}
14171418

1419+
bool CheckPointerToIntegralCast(InterpState &S, CodePtr OpPC,
1420+
const Pointer &Ptr, unsigned BitWidth) {
1421+
if (Ptr.isDummy())
1422+
return false;
1423+
1424+
const SourceInfo &E = S.Current->getSource(OpPC);
1425+
S.CCEDiag(E, diag::note_constexpr_invalid_cast)
1426+
<< 2 << S.getLangOpts().CPlusPlus << S.Current->getRange(OpPC);
1427+
1428+
if (Ptr.isBlockPointer() && !Ptr.isZero()) {
1429+
// Only allow based lvalue casts if they are lossless.
1430+
if (S.getASTContext().getTargetInfo().getPointerWidth(LangAS::Default) !=
1431+
BitWidth)
1432+
return Invalid(S, OpPC);
1433+
}
1434+
return true;
1435+
}
1436+
1437+
bool CastPointerIntegralAP(InterpState &S, CodePtr OpPC, uint32_t BitWidth) {
1438+
const Pointer &Ptr = S.Stk.pop<Pointer>();
1439+
1440+
if (!CheckPointerToIntegralCast(S, OpPC, Ptr, BitWidth))
1441+
return false;
1442+
1443+
S.Stk.push<IntegralAP<false>>(
1444+
IntegralAP<false>::from(Ptr.getIntegerRepresentation(), BitWidth));
1445+
return true;
1446+
}
1447+
1448+
bool CastPointerIntegralAPS(InterpState &S, CodePtr OpPC, uint32_t BitWidth) {
1449+
const Pointer &Ptr = S.Stk.pop<Pointer>();
1450+
1451+
if (!CheckPointerToIntegralCast(S, OpPC, Ptr, BitWidth))
1452+
return false;
1453+
1454+
S.Stk.push<IntegralAP<true>>(
1455+
IntegralAP<true>::from(Ptr.getIntegerRepresentation(), BitWidth));
1456+
return true;
1457+
}
1458+
14181459
// https://github.com/llvm/llvm-project/issues/102513
14191460
#if defined(_WIN32) && !defined(__clang__) && !defined(NDEBUG)
14201461
#pragma optimize("", off)

clang/lib/AST/ByteCode/Interp.h

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2289,53 +2289,22 @@ static inline bool CastFloatingIntegralAPS(InterpState &S, CodePtr OpPC,
22892289
return CheckFloatResult(S, OpPC, F, Status, FPO);
22902290
}
22912291

2292+
bool CheckPointerToIntegralCast(InterpState &S, CodePtr OpPC,
2293+
const Pointer &Ptr, unsigned BitWidth);
2294+
bool CastPointerIntegralAP(InterpState &S, CodePtr OpPC, uint32_t BitWidth);
2295+
bool CastPointerIntegralAPS(InterpState &S, CodePtr OpPC, uint32_t BitWidth);
2296+
22922297
template <PrimType Name, class T = typename PrimConv<Name>::T>
22932298
bool CastPointerIntegral(InterpState &S, CodePtr OpPC) {
22942299
const Pointer &Ptr = S.Stk.pop<Pointer>();
22952300

2296-
if (Ptr.isDummy())
2301+
if (!CheckPointerToIntegralCast(S, OpPC, Ptr, T::bitWidth()))
22972302
return false;
22982303

2299-
const SourceInfo &E = S.Current->getSource(OpPC);
2300-
S.CCEDiag(E, diag::note_constexpr_invalid_cast)
2301-
<< 2 << S.getLangOpts().CPlusPlus << S.Current->getRange(OpPC);
2302-
23032304
S.Stk.push<T>(T::from(Ptr.getIntegerRepresentation()));
23042305
return true;
23052306
}
23062307

2307-
static inline bool CastPointerIntegralAP(InterpState &S, CodePtr OpPC,
2308-
uint32_t BitWidth) {
2309-
const Pointer &Ptr = S.Stk.pop<Pointer>();
2310-
2311-
if (Ptr.isDummy())
2312-
return false;
2313-
2314-
const SourceInfo &E = S.Current->getSource(OpPC);
2315-
S.CCEDiag(E, diag::note_constexpr_invalid_cast)
2316-
<< 2 << S.getLangOpts().CPlusPlus << S.Current->getRange(OpPC);
2317-
2318-
S.Stk.push<IntegralAP<false>>(
2319-
IntegralAP<false>::from(Ptr.getIntegerRepresentation(), BitWidth));
2320-
return true;
2321-
}
2322-
2323-
static inline bool CastPointerIntegralAPS(InterpState &S, CodePtr OpPC,
2324-
uint32_t BitWidth) {
2325-
const Pointer &Ptr = S.Stk.pop<Pointer>();
2326-
2327-
if (Ptr.isDummy())
2328-
return false;
2329-
2330-
const SourceInfo &E = S.Current->getSource(OpPC);
2331-
S.CCEDiag(E, diag::note_constexpr_invalid_cast)
2332-
<< 2 << S.getLangOpts().CPlusPlus << S.Current->getRange(OpPC);
2333-
2334-
S.Stk.push<IntegralAP<true>>(
2335-
IntegralAP<true>::from(Ptr.getIntegerRepresentation(), BitWidth));
2336-
return true;
2337-
}
2338-
23392308
template <PrimType Name, class T = typename PrimConv<Name>::T>
23402309
static inline bool CastIntegralFixedPoint(InterpState &S, CodePtr OpPC,
23412310
uint32_t FPS) {

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ static T getParam(const InterpFrame *Frame, unsigned Index) {
3838
return Frame->getParam<T>(Offset);
3939
}
4040

41+
// static APSInt getAPSIntParam(InterpStack &Stk, size_t Offset = 0) {
42+
static APSInt getAPSIntParam(const InterpFrame *Frame, unsigned Index) {
43+
APSInt R;
44+
unsigned Offset = Frame->getFunction()->getParamOffset(Index);
45+
INT_TYPE_SWITCH(Frame->getFunction()->getParamType(Index),
46+
R = Frame->getParam<T>(Offset).toAPSInt());
47+
return R;
48+
}
49+
4150
PrimType getIntPrimType(const InterpState &S) {
4251
const TargetInfo &TI = S.getASTContext().getTargetInfo();
4352
unsigned IntWidth = TI.getIntWidth();
@@ -1273,6 +1282,39 @@ static bool interp__builtin_ia32_pext(InterpState &S, CodePtr OpPC,
12731282
return true;
12741283
}
12751284

1285+
static bool interp__builtin_ia32_addcarry_subborrow(InterpState &S,
1286+
CodePtr OpPC,
1287+
const InterpFrame *Frame,
1288+
const Function *Func,
1289+
const CallExpr *Call) {
1290+
unsigned BuiltinOp = Func->getBuiltinID();
1291+
APSInt CarryIn = getAPSIntParam(Frame, 0);
1292+
APSInt LHS = getAPSIntParam(Frame, 1);
1293+
APSInt RHS = getAPSIntParam(Frame, 2);
1294+
1295+
bool IsAdd = BuiltinOp == clang::X86::BI__builtin_ia32_addcarryx_u32 ||
1296+
BuiltinOp == clang::X86::BI__builtin_ia32_addcarryx_u64;
1297+
1298+
unsigned BitWidth = LHS.getBitWidth();
1299+
unsigned CarryInBit = CarryIn.ugt(0) ? 1 : 0;
1300+
APInt ExResult =
1301+
IsAdd ? (LHS.zext(BitWidth + 1) + (RHS.zext(BitWidth + 1) + CarryInBit))
1302+
: (LHS.zext(BitWidth + 1) - (RHS.zext(BitWidth + 1) + CarryInBit));
1303+
1304+
APInt Result = ExResult.extractBits(BitWidth, 0);
1305+
APSInt CarryOut =
1306+
APSInt(ExResult.extractBits(1, BitWidth), /*IsUnsigned=*/true);
1307+
1308+
Pointer &CarryOutPtr = S.Stk.peek<Pointer>();
1309+
QualType CarryOutType = Call->getArg(3)->getType()->getPointeeType();
1310+
PrimType CarryOutT = *S.getContext().classify(CarryOutType);
1311+
assignInteger(CarryOutPtr, CarryOutT, APSInt(Result, true));
1312+
1313+
pushInteger(S, CarryOut, Call->getType());
1314+
1315+
return true;
1316+
}
1317+
12761318
static bool interp__builtin_os_log_format_buffer_size(InterpState &S,
12771319
CodePtr OpPC,
12781320
const InterpFrame *Frame,
@@ -1898,6 +1940,14 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
18981940
return false;
18991941
break;
19001942

1943+
case clang::X86::BI__builtin_ia32_addcarryx_u32:
1944+
case clang::X86::BI__builtin_ia32_addcarryx_u64:
1945+
case clang::X86::BI__builtin_ia32_subborrow_u32:
1946+
case clang::X86::BI__builtin_ia32_subborrow_u64:
1947+
if (!interp__builtin_ia32_addcarry_subborrow(S, OpPC, Frame, F, Call))
1948+
return false;
1949+
break;
1950+
19011951
case Builtin::BI__builtin_os_log_format_buffer_size:
19021952
if (!interp__builtin_os_log_format_buffer_size(S, OpPC, Frame, F, Call))
19031953
return false;

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9107,13 +9107,6 @@ void OffloadPackager::ConstructJob(Compilation &C, const JobAction &JA,
91079107
llvm::copy_if(Features, std::back_inserter(FeatureArgs),
91089108
[](StringRef Arg) { return !Arg.starts_with("-target"); });
91099109

9110-
if (TC->getTriple().isAMDGPU()) {
9111-
for (StringRef Feature : llvm::split(Arch.split(':').second, ':')) {
9112-
FeatureArgs.emplace_back(
9113-
Args.MakeArgString(Feature.take_back() + Feature.drop_back()));
9114-
}
9115-
}
9116-
91179110
// TODO: We need to pass in the full target-id and handle it properly in the
91189111
// linker wrapper.
91199112
SmallVector<std::string> Parts{
@@ -9123,7 +9116,7 @@ void OffloadPackager::ConstructJob(Compilation &C, const JobAction &JA,
91239116
"kind=" + Kind.str(),
91249117
};
91259118

9126-
if (TC->getDriver().isUsingOffloadLTO() || TC->getTriple().isAMDGPU())
9119+
if (TC->getDriver().isUsingOffloadLTO())
91279120
for (StringRef Feature : FeatureArgs)
91289121
Parts.emplace_back("feature=" + Feature.str());
91299122

clang/lib/Driver/ToolChains/Cuda.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,10 @@ void CudaToolChain::addClangTargetOptions(
848848
if (CudaInstallation.version() >= CudaVersion::CUDA_90)
849849
CC1Args.push_back("-fcuda-allow-variadic-functions");
850850

851+
if (DriverArgs.hasFlag(options::OPT_fcuda_short_ptr,
852+
options::OPT_fno_cuda_short_ptr, false))
853+
CC1Args.append({"-mllvm", "--nvptx-short-ptr"});
854+
851855
if (DriverArgs.hasArg(options::OPT_nogpulib))
852856
return;
853857

@@ -873,10 +877,6 @@ void CudaToolChain::addClangTargetOptions(
873877

874878
clang::CudaVersion CudaInstallationVersion = CudaInstallation.version();
875879

876-
if (DriverArgs.hasFlag(options::OPT_fcuda_short_ptr,
877-
options::OPT_fno_cuda_short_ptr, false))
878-
CC1Args.append({"-mllvm", "--nvptx-short-ptr"});
879-
880880
if (CudaInstallationVersion >= CudaVersion::UNKNOWN)
881881
CC1Args.push_back(
882882
DriverArgs.MakeArgString(Twine("-target-sdk-version=") +

clang/lib/Sema/SemaAvailability.cpp

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,25 +1005,54 @@ bool DiagnoseUnguardedAvailability::VisitTypeLoc(TypeLoc Ty) {
10051005
return true;
10061006
}
10071007

1008+
struct ExtractedAvailabilityExpr {
1009+
const ObjCAvailabilityCheckExpr *E = nullptr;
1010+
bool isNegated = false;
1011+
};
1012+
1013+
ExtractedAvailabilityExpr extractAvailabilityExpr(const Expr *IfCond) {
1014+
const auto *E = IfCond;
1015+
bool IsNegated = false;
1016+
while (true) {
1017+
E = E->IgnoreParens();
1018+
if (const auto *AE = dyn_cast<ObjCAvailabilityCheckExpr>(E)) {
1019+
return ExtractedAvailabilityExpr{AE, IsNegated};
1020+
}
1021+
1022+
const auto *UO = dyn_cast<UnaryOperator>(E);
1023+
if (!UO || UO->getOpcode() != UO_LNot) {
1024+
return ExtractedAvailabilityExpr{};
1025+
}
1026+
E = UO->getSubExpr();
1027+
IsNegated = !IsNegated;
1028+
}
1029+
}
1030+
10081031
bool DiagnoseUnguardedAvailability::TraverseIfStmt(IfStmt *If) {
1009-
VersionTuple CondVersion;
1010-
if (auto *E = dyn_cast<ObjCAvailabilityCheckExpr>(If->getCond())) {
1011-
CondVersion = E->getVersion();
1012-
1013-
// If we're using the '*' case here or if this check is redundant, then we
1014-
// use the enclosing version to check both branches.
1015-
if (CondVersion.empty() || CondVersion <= AvailabilityStack.back())
1016-
return TraverseStmt(If->getThen()) && TraverseStmt(If->getElse());
1017-
} else {
1032+
ExtractedAvailabilityExpr IfCond = extractAvailabilityExpr(If->getCond());
1033+
if (!IfCond.E) {
10181034
// This isn't an availability checking 'if', we can just continue.
10191035
return Base::TraverseIfStmt(If);
10201036
}
10211037

1038+
VersionTuple CondVersion = IfCond.E->getVersion();
1039+
// If we're using the '*' case here or if this check is redundant, then we
1040+
// use the enclosing version to check both branches.
1041+
if (CondVersion.empty() || CondVersion <= AvailabilityStack.back()) {
1042+
return TraverseStmt(If->getThen()) && TraverseStmt(If->getElse());
1043+
}
1044+
1045+
auto *Guarded = If->getThen();
1046+
auto *Unguarded = If->getElse();
1047+
if (IfCond.isNegated) {
1048+
std::swap(Guarded, Unguarded);
1049+
}
1050+
10221051
AvailabilityStack.push_back(CondVersion);
1023-
bool ShouldContinue = TraverseStmt(If->getThen());
1052+
bool ShouldContinue = TraverseStmt(Guarded);
10241053
AvailabilityStack.pop_back();
10251054

1026-
return ShouldContinue && TraverseStmt(If->getElse());
1055+
return ShouldContinue && TraverseStmt(Unguarded);
10271056
}
10281057

10291058
} // end anonymous namespace

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8429,7 +8429,8 @@ ExprResult Sema::ActOnPseudoDestructorExpr(Scope *S, Expr *Base,
84298429
QualType ObjectType;
84308430
QualType T;
84318431
TypeLocBuilder TLB;
8432-
if (CheckArrow(*this, ObjectType, Base, OpKind, OpLoc))
8432+
if (CheckArrow(*this, ObjectType, Base, OpKind, OpLoc) ||
8433+
DS.getTypeSpecType() == DeclSpec::TST_error)
84338434
return ExprError();
84348435

84358436
switch (DS.getTypeSpecType()) {

0 commit comments

Comments
 (0)