Skip to content

Commit 462114a

Browse files
author
git apple-llvm automerger
committed
Merge commit 'da59fe7f15f5' from llvm.org/main into experimental/cas/main
2 parents f1275d6 + da59fe7 commit 462114a

File tree

64 files changed

+3708
-638
lines changed

Some content is hidden

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

64 files changed

+3708
-638
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ Improvements to Clang's diagnostics
136136
- no_sanitize("...") on a global variable for known but not relevant sanitizers
137137
is now just a warning. It now says that this will be ignored instead of
138138
incorrectly saying no_sanitize only applies to functions and methods.
139+
- No longer mention ``reinterpet_cast`` in the invalid constant expression
140+
diagnostic note when in C mode.
139141

140142
Non-comprehensive list of changes in this release
141143
-------------------------------------------------

clang/include/clang/Basic/DiagnosticASTKinds.td

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ let Component = "AST" in {
1111
// Constant expression diagnostics. These (and their users) belong in Sema.
1212
def note_expr_divide_by_zero : Note<"division by zero">;
1313
def note_constexpr_invalid_cast : Note<
14-
"%select{reinterpret_cast|dynamic_cast|cast that performs the conversions of"
15-
" a reinterpret_cast|cast from %1}0 is not allowed in a constant expression"
14+
"%select{reinterpret_cast|dynamic_cast|%select{this conversion|cast that"
15+
" performs the conversions of a reinterpret_cast}1|cast from %1}0"
16+
" is not allowed in a constant expression"
1617
"%select{| in C++ standards before C++20||}0">;
1718
def note_constexpr_invalid_downcast : Note<
1819
"cannot cast object of dynamic type %0 to type %1">;

clang/lib/AST/ExprConstant.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8178,7 +8178,8 @@ class LValueExprEvaluator
81788178
return LValueExprEvaluatorBaseTy::VisitCastExpr(E);
81798179

81808180
case CK_LValueBitCast:
8181-
this->CCEDiag(E, diag::note_constexpr_invalid_cast) << 2;
8181+
this->CCEDiag(E, diag::note_constexpr_invalid_cast)
8182+
<< 2 << Info.Ctx.getLangOpts().CPlusPlus;
81828183
if (!Visit(E->getSubExpr()))
81838184
return false;
81848185
Result.Designator.setInvalid();
@@ -8889,9 +8890,10 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr *E) {
88898890
Result.Designator.setInvalid();
88908891
if (SubExpr->getType()->isVoidPointerType())
88918892
CCEDiag(E, diag::note_constexpr_invalid_cast)
8892-
<< 3 << SubExpr->getType();
8893+
<< 3 << SubExpr->getType();
88938894
else
8894-
CCEDiag(E, diag::note_constexpr_invalid_cast) << 2;
8895+
CCEDiag(E, diag::note_constexpr_invalid_cast)
8896+
<< 2 << Info.Ctx.getLangOpts().CPlusPlus;
88958897
}
88968898
}
88978899
if (E->getCastKind() == CK_AddressSpaceConversion && Result.IsNullPtr)
@@ -8928,7 +8930,8 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr *E) {
89288930
return ZeroInitialization(E);
89298931

89308932
case CK_IntegralToPointer: {
8931-
CCEDiag(E, diag::note_constexpr_invalid_cast) << 2;
8933+
CCEDiag(E, diag::note_constexpr_invalid_cast)
8934+
<< 2 << Info.Ctx.getLangOpts().CPlusPlus;
89328935

89338936
APValue Value;
89348937
if (!EvaluateIntegerOrLValue(SubExpr, Value, Info))
@@ -13587,7 +13590,8 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) {
1358713590
}
1358813591

1358913592
case CK_PointerToIntegral: {
13590-
CCEDiag(E, diag::note_constexpr_invalid_cast) << 2;
13593+
CCEDiag(E, diag::note_constexpr_invalid_cast)
13594+
<< 2 << Info.Ctx.getLangOpts().CPlusPlus;
1359113595

1359213596
LValue LV;
1359313597
if (!EvaluatePointer(SubExpr, LV, Info))

clang/test/Sema/cast.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
// RUN: %clang_cc1 -fsyntax-only -triple x86_64-unknown-unknown %s -verify
1+
// RUN: %clang_cc1 -fsyntax-only -triple x86_64-unknown-unknown %s -verify -Wvla
2+
3+
int array[(long)(char *)0]; // expected-warning {{variable length array used}} \
4+
// expected-warning {{variable length array folded to constant array as an extension}} \
5+
// expected-note {{this conversion is not allowed in a constant expression}}
26

37
typedef struct { unsigned long bits[(((1) + (64) - 1) / (64))]; } cpumask_t;
48
cpumask_t x;

clang/test/SemaCXX/constant-expression-cxx11.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ static_assert(false, "test"); // expected-error {{test}}
1111

1212
}
1313

14+
int array[(long)(char *)0]; // expected-warning {{variable length arrays are a C99 feature}} \
15+
// expected-warning {{variable length array folded to constant array as an extension}} \
16+
// expected-note {{cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression}}
17+
1418
typedef decltype(sizeof(char)) size_t;
1519

1620
template<typename T> constexpr T id(const T &t) { return t; }

clang/unittests/Lex/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ clang_target_link_libraries(LexTests
2020
clangLex
2121
clangParse
2222
clangSema
23+
)
2324

25+
target_link_libraries(LexTests
26+
PRIVATE
2427
LLVMTestingSupport
2528
)

lld/test/COFF/pdb-natvis.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ RUN: --check-prefix=CHECK-THIRD %s
1414
RUN: lld-link /DEBUG %t.obj /nodefaultlib /entry:main /NATVIS:%p/Inputs/test2.natvis \
1515
RUN: /OUT:%t.exe /PDB:%t.pdb 2>&1 | FileCheck --check-prefix=CHECK-MISSING %s
1616

17-
CHECK-FIRST: {{.*}}natvis-1.natvis (16 bytes): obj=<null>, vname={{.*}}natvis-1.natvis, crc=355285096, compression=None
17+
CHECK-FIRST: {{.*}}natvis-1.natvis ({{16|17}} bytes): obj=<null>, vname={{.*}}natvis-1.natvis, crc={{355285096|3974675339}}, compression=None
1818
CHECK-FIRST-NEXT: 1st Natvis Test
1919

20-
CHECK-SECOND: {{.*}}natvis-2.natvis (19 bytes): obj=<null>, vname={{.*}}natvis-2.natvis, crc=4252640062, compression=None
20+
CHECK-SECOND: {{.*}}natvis-2.natvis ({{19|20}} bytes): obj=<null>, vname={{.*}}natvis-2.natvis, crc={{4252640062|1846024273}}, compression=None
2121
CHECK-SECOND-NEXT: Second Natvis Test
2222

23-
CHECK-THIRD: {{.*}}natvis-3.natvis (18 bytes): obj=<null>, vname={{.*}}natvis-3.natvis, crc=2069719849, compression=None
23+
CHECK-THIRD: {{.*}}natvis-3.natvis ({{18|19}} bytes): obj=<null>, vname={{.*}}natvis-3.natvis, crc={{2069719849|3982342878}}, compression=None
2424
CHECK-THIRD-NEXT: Third Natvis Test
2525

2626
CHECK-MISSING: Cannot open input file: {{.*}}test2.natvis

llvm/docs/LangRef.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5813,7 +5813,7 @@ The current supported opcode vocabulary is limited:
58135813
- ``DW_OP_LLVM_arg, N`` is used in debug intrinsics that refer to more than one
58145814
value, such as one that calculates the sum of two registers. This is always
58155815
used in combination with an ordered list of values, such that
5816-
``DW_OP_LLVM_arg, N`` refers to the ``N``th element in that list. For
5816+
``DW_OP_LLVM_arg, N`` refers to the ``N``\ :sup:`th` element in that list. For
58175817
example, ``!DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_minus,
58185818
DW_OP_stack_value)`` used with the list ``(%reg1, %reg2)`` would evaluate to
58195819
``%reg1 - reg2``. This list of values should be provided by the containing

llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class MachineInstr;
4747
class MachineRegisterInfo;
4848
class OptimizationRemarkEmitter;
4949
class PHINode;
50+
class TargetLibraryInfo;
5051
class TargetPassConfig;
5152
class User;
5253
class Value;
@@ -570,6 +571,7 @@ class IRTranslator : public MachineFunctionPass {
570571
std::unique_ptr<OptimizationRemarkEmitter> ORE;
571572

572573
AAResults *AA;
574+
const TargetLibraryInfo *LibInfo;
573575
FunctionLoweringInfo FuncInfo;
574576

575577
// True when either the Target Machine specifies no optimizations or the

llvm/include/llvm/CodeGen/TargetRegisterInfo.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,14 @@ class TargetRegisterInfo : public MCRegisterInfo {
637637
return RC;
638638
}
639639

640+
/// Return a register class that can be used for a subregister copy from/into
641+
/// \p SuperRC at \p SubRegIdx.
642+
virtual const TargetRegisterClass *
643+
getSubRegisterClass(const TargetRegisterClass *SuperRC,
644+
unsigned SubRegIdx) const {
645+
return nullptr;
646+
}
647+
640648
/// Return the subregister index you get from composing
641649
/// two subregister indices.
642650
///

llvm/lib/Analysis/BasicAliasAnalysis.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -585,13 +585,6 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL,
585585

586586
assert(GEPOp->getSourceElementType()->isSized() && "GEP must be sized");
587587

588-
// Don't attempt to analyze GEPs if index scale is not a compile-time
589-
// constant.
590-
if (isa<ScalableVectorType>(GEPOp->getSourceElementType())) {
591-
Decomposed.Base = V;
592-
return Decomposed;
593-
}
594-
595588
unsigned AS = GEPOp->getPointerAddressSpace();
596589
// Walk the indices of the GEP, accumulating them into BaseOff/VarIndices.
597590
gep_type_iterator GTI = gep_type_begin(GEPOp);
@@ -612,16 +605,28 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL,
612605
continue;
613606
}
614607

608+
TypeSize AllocaTypeSize = DL.getTypeAllocSize(GTI.getIndexedType());
615609
// For an array/pointer, add the element offset, explicitly scaled.
616610
if (const ConstantInt *CIdx = dyn_cast<ConstantInt>(Index)) {
617611
if (CIdx->isZero())
618612
continue;
619-
Decomposed.Offset +=
620-
DL.getTypeAllocSize(GTI.getIndexedType()).getFixedSize() *
621-
CIdx->getValue().sextOrTrunc(MaxIndexSize);
613+
614+
// Don't attempt to analyze GEPs if the scalable index is not zero.
615+
if (AllocaTypeSize.isScalable()) {
616+
Decomposed.Base = V;
617+
return Decomposed;
618+
}
619+
620+
Decomposed.Offset += AllocaTypeSize.getFixedSize() *
621+
CIdx->getValue().sextOrTrunc(MaxIndexSize);
622622
continue;
623623
}
624624

625+
if (AllocaTypeSize.isScalable()) {
626+
Decomposed.Base = V;
627+
return Decomposed;
628+
}
629+
625630
GepHasConstantOffset = false;
626631

627632
// If the integer type is smaller than the index size, it is implicitly
@@ -633,8 +638,7 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL,
633638
CastedValue(Index, 0, SExtBits, TruncBits), DL, 0, AC, DT);
634639

635640
// Scale by the type size.
636-
unsigned TypeSize =
637-
DL.getTypeAllocSize(GTI.getIndexedType()).getFixedSize();
641+
unsigned TypeSize = AllocaTypeSize.getFixedSize();
638642
LE = LE.mul(APInt(IndexSize, TypeSize), GEPOp->isInBounds());
639643
Decomposed.Offset += LE.Offset.sext(MaxIndexSize);
640644
APInt Scale = LE.Scale.sext(MaxIndexSize);

llvm/lib/CodeGen/CalcSpillWeights.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ float VirtRegAuxInfo::weightCalcHelper(LiveInterval &LI, SlotIndex *Start,
278278
if (TargetHint.first == 0 && TargetHint.second)
279279
MRI.clearSimpleHint(LI.reg());
280280

281-
std::set<Register> HintedRegs;
281+
SmallSet<Register, 4> HintedRegs;
282282
for (const auto &Hint : CopyHints) {
283283
if (!HintedRegs.insert(Hint.Reg).second ||
284284
(TargetHint.first != 0 && Hint.Reg == TargetHint.second))

llvm/lib/CodeGen/DeadMachineInstructionElim.cpp

Lines changed: 9 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "llvm/ADT/PostOrderIterator.h"
1414
#include "llvm/ADT/Statistic.h"
15+
#include "llvm/CodeGen/LiveRegUnits.h"
1516
#include "llvm/CodeGen/MachineFunctionPass.h"
1617
#include "llvm/CodeGen/MachineRegisterInfo.h"
1718
#include "llvm/CodeGen/TargetSubtargetInfo.h"
@@ -30,10 +31,9 @@ namespace {
3031
class DeadMachineInstructionElim : public MachineFunctionPass {
3132
bool runOnMachineFunction(MachineFunction &MF) override;
3233

33-
const TargetRegisterInfo *TRI;
3434
const MachineRegisterInfo *MRI;
3535
const TargetInstrInfo *TII;
36-
BitVector LivePhysRegs;
36+
LiveRegUnits LivePhysRegs;
3737

3838
public:
3939
static char ID; // Pass identification, replacement for typeid
@@ -78,9 +78,9 @@ bool DeadMachineInstructionElim::isDead(const MachineInstr *MI) const {
7878
for (const MachineOperand &MO : MI->operands()) {
7979
if (MO.isReg() && MO.isDef()) {
8080
Register Reg = MO.getReg();
81-
if (Register::isPhysicalRegister(Reg)) {
81+
if (Reg.isPhysical()) {
8282
// Don't delete live physreg defs, or any reserved register defs.
83-
if (LivePhysRegs.test(Reg) || MRI->isReserved(Reg))
83+
if (!LivePhysRegs.available(Reg) || MRI->isReserved(Reg))
8484
return false;
8585
} else {
8686
if (MO.isDead()) {
@@ -117,26 +117,19 @@ bool DeadMachineInstructionElim::runOnMachineFunction(MachineFunction &MF) {
117117
bool DeadMachineInstructionElim::eliminateDeadMI(MachineFunction &MF) {
118118
bool AnyChanges = false;
119119
MRI = &MF.getRegInfo();
120-
TRI = MF.getSubtarget().getRegisterInfo();
121120
TII = MF.getSubtarget().getInstrInfo();
122121

122+
LivePhysRegs.init(*MF.getSubtarget().getRegisterInfo());
123+
123124
// Loop over all instructions in all blocks, from bottom to top, so that it's
124125
// more likely that chains of dependent but ultimately dead instructions will
125126
// be cleaned up.
126127
for (MachineBasicBlock *MBB : post_order(&MF)) {
127-
// Start out assuming that reserved registers are live out of this block.
128-
LivePhysRegs = MRI->getReservedRegs();
129-
130-
// Add live-ins from successors to LivePhysRegs. Normally, physregs are not
131-
// live across blocks, but some targets (x86) can have flags live out of a
132-
// block.
133-
for (const MachineBasicBlock *Succ : MBB->successors())
134-
for (const auto &LI : Succ->liveins())
135-
LivePhysRegs.set(LI.PhysReg);
128+
LivePhysRegs.addLiveOuts(*MBB);
136129

137130
// Now scan the instructions and delete dead ones, tracking physreg
138131
// liveness as we go.
139-
for (MachineInstr &MI : llvm::make_early_inc_range(llvm::reverse(*MBB))) {
132+
for (MachineInstr &MI : make_early_inc_range(reverse(*MBB))) {
140133
// If the instruction is dead, delete it!
141134
if (isDead(&MI)) {
142135
LLVM_DEBUG(dbgs() << "DeadMachineInstructionElim: DELETING: " << MI);
@@ -149,34 +142,7 @@ bool DeadMachineInstructionElim::eliminateDeadMI(MachineFunction &MF) {
149142
continue;
150143
}
151144

152-
// Record the physreg defs.
153-
for (const MachineOperand &MO : MI.operands()) {
154-
if (MO.isReg() && MO.isDef()) {
155-
Register Reg = MO.getReg();
156-
if (Register::isPhysicalRegister(Reg)) {
157-
// Check the subreg set, not the alias set, because a def
158-
// of a super-register may still be partially live after
159-
// this def.
160-
for (MCSubRegIterator SR(Reg, TRI,/*IncludeSelf=*/true);
161-
SR.isValid(); ++SR)
162-
LivePhysRegs.reset(*SR);
163-
}
164-
} else if (MO.isRegMask()) {
165-
// Register mask of preserved registers. All clobbers are dead.
166-
LivePhysRegs.clearBitsNotInMask(MO.getRegMask());
167-
}
168-
}
169-
// Record the physreg uses, after the defs, in case a physreg is
170-
// both defined and used in the same instruction.
171-
for (const MachineOperand &MO : MI.operands()) {
172-
if (MO.isReg() && MO.isUse()) {
173-
Register Reg = MO.getReg();
174-
if (Register::isPhysicalRegister(Reg)) {
175-
for (MCRegAliasIterator AI(Reg, TRI, true); AI.isValid(); ++AI)
176-
LivePhysRegs.set(*AI);
177-
}
178-
}
179-
}
145+
LivePhysRegs.stepBackward(MI);
180146
}
181147
}
182148

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "llvm/ADT/SmallVector.h"
1818
#include "llvm/Analysis/AliasAnalysis.h"
1919
#include "llvm/Analysis/BranchProbabilityInfo.h"
20+
#include "llvm/Analysis/Loads.h"
2021
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
2122
#include "llvm/Analysis/ValueTracking.h"
2223
#include "llvm/CodeGen/Analysis.h"
@@ -1307,12 +1308,13 @@ bool IRTranslator::translateLoad(const User &U, MachineIRBuilder &MIRBuilder) {
13071308
if (AA->pointsToConstantMemory(
13081309
MemoryLocation(Ptr, LocationSize::precise(StoreSize), AAInfo))) {
13091310
Flags |= MachineMemOperand::MOInvariant;
1311+
}
1312+
}
13101313

1311-
// FIXME: pointsToConstantMemory probably does not imply dereferenceable,
1312-
// but the previous usage implied it did. Probably should check
1313-
// isDereferenceableAndAlignedPointer.
1314+
if (!(Flags & MachineMemOperand::MODereferenceable)) {
1315+
if (isDereferenceableAndAlignedPointer(Ptr, LI.getType(), LI.getAlign(),
1316+
*DL, &LI, nullptr, LibInfo))
13141317
Flags |= MachineMemOperand::MODereferenceable;
1315-
}
13161318
}
13171319

13181320
const MDNode *Ranges =
@@ -1883,10 +1885,8 @@ bool IRTranslator::translateKnownIntrinsic(const CallInst &CI, Intrinsic::ID ID,
18831885
MachineIRBuilder &MIRBuilder) {
18841886
if (auto *MI = dyn_cast<AnyMemIntrinsic>(&CI)) {
18851887
if (ORE->enabled()) {
1886-
const Function &F = *MI->getParent()->getParent();
1887-
auto &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(F);
1888-
if (MemoryOpRemark::canHandle(MI, TLI)) {
1889-
MemoryOpRemark R(*ORE, "gisel-irtranslator-memsize", *DL, TLI);
1888+
if (MemoryOpRemark::canHandle(MI, *LibInfo)) {
1889+
MemoryOpRemark R(*ORE, "gisel-irtranslator-memsize", *DL, *LibInfo);
18901890
R.visit(MI);
18911891
}
18921892
}
@@ -2363,10 +2363,8 @@ bool IRTranslator::translateCallBase(const CallBase &CB,
23632363

23642364
if (auto *CI = dyn_cast<CallInst>(&CB)) {
23652365
if (ORE->enabled()) {
2366-
const Function &F = *CI->getParent()->getParent();
2367-
auto &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(F);
2368-
if (MemoryOpRemark::canHandle(CI, TLI)) {
2369-
MemoryOpRemark R(*ORE, "gisel-irtranslator-memsize", *DL, TLI);
2366+
if (MemoryOpRemark::canHandle(CI, *LibInfo)) {
2367+
MemoryOpRemark R(*ORE, "gisel-irtranslator-memsize", *DL, *LibInfo);
23702368
R.visit(CI);
23712369
}
23722370
}
@@ -3399,6 +3397,7 @@ bool IRTranslator::runOnMachineFunction(MachineFunction &CurMF) {
33993397
FuncInfo.BPI = nullptr;
34003398
}
34013399

3400+
LibInfo = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(F);
34023401
FuncInfo.CanLowerReturn = CLI->checkReturnTypeForCallConv(*MF);
34033402

34043403
const auto &TLI = *MF->getSubtarget().getTargetLowering();

0 commit comments

Comments
 (0)