Skip to content

Commit e1f37f3

Browse files
committed
Merge branch 'main' of github.com:llvm/llvm-project into loop-vectorize/evl-exit-cond-avlnext-zero
2 parents 2931aa7 + 13ae82d commit e1f37f3

Some content is hidden

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

60 files changed

+11005
-1489
lines changed

clang-tools-extra/clangd/FeatureModule.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ FeatureModule::Facilities &FeatureModule::facilities() {
2222
return *Fac;
2323
}
2424

25-
void FeatureModuleSet::add(std::unique_ptr<FeatureModule> M) {
26-
Modules.push_back(std::move(M));
27-
}
28-
2925
bool FeatureModuleSet::addImpl(void *Key, std::unique_ptr<FeatureModule> M,
3026
const char *Source) {
3127
if (!Map.try_emplace(Key, M.get()).second) {
@@ -39,5 +35,3 @@ bool FeatureModuleSet::addImpl(void *Key, std::unique_ptr<FeatureModule> M,
3935

4036
} // namespace clangd
4137
} // namespace clang
42-
43-
LLVM_INSTANTIATE_REGISTRY(clang::clangd::FeatureModuleRegistry)

clang-tools-extra/clangd/FeatureModule.h

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "llvm/ADT/FunctionExtras.h"
1616
#include "llvm/Support/Compiler.h"
1717
#include "llvm/Support/JSON.h"
18-
#include "llvm/Support/Registry.h"
1918
#include <memory>
2019
#include <optional>
2120
#include <type_traits>
@@ -144,14 +143,9 @@ class FeatureModule {
144143

145144
/// A FeatureModuleSet is a collection of feature modules installed in clangd.
146145
///
147-
/// Modules added with explicit type specification can be looked up by type, or
148-
/// used via the FeatureModule interface. This allows individual modules to
149-
/// expose a public API. For this reason, there can be only one feature module
150-
/// of each type.
151-
///
152-
/// Modules added using a base class pointer can be used only via the
153-
/// FeatureModule interface and can't be looked up by type, thus custom public
154-
/// API (if provided by the module) can't be used.
146+
/// Modules can be looked up by type, or used via the FeatureModule interface.
147+
/// This allows individual modules to expose a public API.
148+
/// For this reason, there can be only one feature module of each type.
155149
///
156150
/// The set owns the modules. It is itself owned by main, not ClangdServer.
157151
class FeatureModuleSet {
@@ -178,7 +172,6 @@ class FeatureModuleSet {
178172
const_iterator begin() const { return const_iterator(Modules.begin()); }
179173
const_iterator end() const { return const_iterator(Modules.end()); }
180174

181-
void add(std::unique_ptr<FeatureModule> M);
182175
template <typename Mod> bool add(std::unique_ptr<Mod> M) {
183176
return addImpl(&ID<Mod>::Key, std::move(M), LLVM_PRETTY_FUNCTION);
184177
}
@@ -192,8 +185,6 @@ class FeatureModuleSet {
192185

193186
template <typename Mod> int FeatureModuleSet::ID<Mod>::Key;
194187

195-
using FeatureModuleRegistry = llvm::Registry<FeatureModule>;
196-
197188
} // namespace clangd
198189
} // namespace clang
199190
#endif

clang-tools-extra/clangd/tool/ClangdMain.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,14 +1017,6 @@ clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment var
10171017
: static_cast<int>(ErrorResultCode::CheckFailed);
10181018
}
10191019

1020-
FeatureModuleSet ModuleSet;
1021-
for (FeatureModuleRegistry::entry E : FeatureModuleRegistry::entries()) {
1022-
vlog("Adding feature module '{0}' ({1})", E.getName(), E.getDesc());
1023-
ModuleSet.add(E.instantiate());
1024-
}
1025-
if (ModuleSet.begin() != ModuleSet.end())
1026-
Opts.FeatureModules = &ModuleSet;
1027-
10281020
// Initialize and run ClangdLSPServer.
10291021
// Change stdin to binary to not lose \r\n on windows.
10301022
llvm::sys::ChangeStdinToBinary();

clang/lib/AST/ByteCode/Interp.h

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,6 +1640,9 @@ bool InitField(InterpState &S, CodePtr OpPC, uint32_t I) {
16401640
const Pointer &Ptr = S.Stk.peek<Pointer>();
16411641
if (!CheckRange(S, OpPC, Ptr, CSK_Field))
16421642
return false;
1643+
if (!CheckArray(S, OpPC, Ptr))
1644+
return false;
1645+
16431646
const Pointer &Field = Ptr.atField(I);
16441647
Field.deref<T>() = Value;
16451648
Field.initialize();
@@ -1652,6 +1655,9 @@ bool InitFieldActivate(InterpState &S, CodePtr OpPC, uint32_t I) {
16521655
const Pointer &Ptr = S.Stk.peek<Pointer>();
16531656
if (!CheckRange(S, OpPC, Ptr, CSK_Field))
16541657
return false;
1658+
if (!CheckArray(S, OpPC, Ptr))
1659+
return false;
1660+
16551661
const Pointer &Field = Ptr.atField(I);
16561662
Field.deref<T>() = Value;
16571663
Field.activate();
@@ -1663,7 +1669,13 @@ template <PrimType Name, class T = typename PrimConv<Name>::T>
16631669
bool InitBitField(InterpState &S, CodePtr OpPC, const Record::Field *F) {
16641670
assert(F->isBitField());
16651671
const T &Value = S.Stk.pop<T>();
1666-
const Pointer &Field = S.Stk.peek<Pointer>().atField(F->Offset);
1672+
const Pointer &Ptr = S.Stk.peek<Pointer>();
1673+
if (!CheckRange(S, OpPC, Ptr, CSK_Field))
1674+
return false;
1675+
if (!CheckArray(S, OpPC, Ptr))
1676+
return false;
1677+
1678+
const Pointer &Field = Ptr.atField(F->Offset);
16671679

16681680
if constexpr (needsAlloc<T>()) {
16691681
T Result = S.allocAP<T>(Value.bitWidth());
@@ -1689,7 +1701,13 @@ bool InitBitFieldActivate(InterpState &S, CodePtr OpPC,
16891701
const Record::Field *F) {
16901702
assert(F->isBitField());
16911703
const T &Value = S.Stk.pop<T>();
1692-
const Pointer &Field = S.Stk.peek<Pointer>().atField(F->Offset);
1704+
const Pointer &Ptr = S.Stk.peek<Pointer>();
1705+
if (!CheckRange(S, OpPC, Ptr, CSK_Field))
1706+
return false;
1707+
if (!CheckArray(S, OpPC, Ptr))
1708+
return false;
1709+
1710+
const Pointer &Field = Ptr.atField(F->Offset);
16931711

16941712
if constexpr (needsAlloc<T>()) {
16951713
T Result = S.allocAP<T>(Value.bitWidth());
@@ -1788,6 +1806,8 @@ inline bool GetPtrBase(InterpState &S, CodePtr OpPC, uint32_t Off) {
17881806
return false;
17891807

17901808
if (!Ptr.isBlockPointer()) {
1809+
if (!Ptr.isIntegralPointer())
1810+
return false;
17911811
S.Stk.push<Pointer>(Ptr.asIntPointer().baseCast(S.getASTContext(), Off));
17921812
return true;
17931813
}
@@ -1809,6 +1829,8 @@ inline bool GetPtrBasePop(InterpState &S, CodePtr OpPC, uint32_t Off,
18091829
return false;
18101830

18111831
if (!Ptr.isBlockPointer()) {
1832+
if (!Ptr.isIntegralPointer())
1833+
return false;
18121834
S.Stk.push<Pointer>(Ptr.asIntPointer().baseCast(S.getASTContext(), Off));
18131835
return true;
18141836
}
@@ -2437,9 +2459,17 @@ inline bool Destroy(InterpState &S, CodePtr OpPC, uint32_t I) {
24372459
const Pointer &Ptr = S.Current->getLocalPointer(Local.Offset);
24382460

24392461
if (Ptr.getLifetime() == Lifetime::Ended) {
2440-
auto *D = cast<NamedDecl>(Ptr.getFieldDesc()->asDecl());
2441-
S.FFDiag(D->getLocation(), diag::note_constexpr_destroy_out_of_lifetime)
2442-
<< D->getNameAsString();
2462+
// Try to use the declaration for better diagnostics
2463+
if (const Decl *D = Ptr.getDeclDesc()->asDecl()) {
2464+
auto *ND = cast<NamedDecl>(D);
2465+
S.FFDiag(ND->getLocation(),
2466+
diag::note_constexpr_destroy_out_of_lifetime)
2467+
<< ND->getNameAsString();
2468+
} else {
2469+
S.FFDiag(Ptr.getDeclDesc()->getLocation(),
2470+
diag::note_constexpr_destroy_out_of_lifetime)
2471+
<< Ptr.toDiagnosticString(S.getASTContext());
2472+
}
24432473
return false;
24442474
}
24452475
}

clang/test/AST/ByteCode/arrays.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,3 +800,23 @@ namespace ZeroSizeArrayRead {
800800
static_assert(s[0] == '0', ""); // both-error {{not an integral constant expression}} \
801801
// both-note {{read of dereferenced one-past-the-end pointer}}
802802
}
803+
804+
namespace FAM {
805+
char *strchr(const char *, int);
806+
807+
struct A {
808+
char n, a[2];
809+
};
810+
struct B {
811+
int n;
812+
struct A a[]; // both-note {{here}}
813+
};
814+
815+
const struct B b = {0, {{1, {2, 3}}, {4, {5, 6}}}};
816+
void foo(void) { int sch = 0 != strchr(b.a[1].a, '\0'); }
817+
818+
int foo2() {
819+
struct B b = {0, {{1, {2, 3}}, {4, {5, 6}}}}; // both-error {{initialization of flexible array member is not allowed}}
820+
return 1;
821+
}
822+
}

clang/test/AST/ByteCode/lifetimes.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,15 @@ namespace CallScope {
104104
// expected-note {{member call on variable whose lifetime has ended}} \
105105
// ref-note {{member call on object outside its lifetime}}
106106
}
107+
108+
namespace ExprDoubleDestroy {
109+
template <typename T>
110+
constexpr bool test() {
111+
T{}.~T(); // both-note {{lifetime has already ended}}
112+
return true;
113+
}
114+
115+
struct S { int x; };
116+
constexpr bool t = test<S>(); // both-error {{must be initialized by a constant expression}} \
117+
// both-note {{in call to}}
118+
}

clang/test/AST/ByteCode/typeid.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ struct __type_info_implementations {
1313
typedef __unique_impl __impl;
1414
};
1515

16-
class type_info {
16+
class __pointer_type_info {
17+
public:
18+
int __flags = 0;
19+
};
20+
21+
class type_info : public __pointer_type_info {
1722
protected:
1823
typedef __type_info_implementations::__impl __impl;
1924
__impl::__type_name_t __type_name;
@@ -40,3 +45,10 @@ constexpr bool test() {
4045
return true;
4146
}
4247
static_assert(test());
48+
49+
int dontcrash() {
50+
auto& pti = static_cast<const std::__pointer_type_info&>(
51+
typeid(int)
52+
);
53+
return pti.__flags == 0 ? 1 : 0;
54+
}

llvm/include/llvm/ADT/APInt.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2410,6 +2410,35 @@ LLVM_ABI std::optional<unsigned> GetMostSignificantDifferentBit(const APInt &A,
24102410
/// A.getBitwidth() or NewBitWidth must be a whole multiples of the other.
24112411
LLVM_ABI APInt ScaleBitMask(const APInt &A, unsigned NewBitWidth,
24122412
bool MatchAllBits = false);
2413+
2414+
/// Perform a funnel shift left.
2415+
///
2416+
/// Concatenate Hi and Lo (Hi is the most significant bits of the wide value),
2417+
/// the combined value is shifted left by Shift (modulo the bit width of the
2418+
/// original arguments), and the most significant bits are extracted to produce
2419+
/// a result that is the same size as the original arguments.
2420+
///
2421+
/// Examples:
2422+
/// (1) fshl(i8 255, i8 0, i8 15) = 128 (0b10000000)
2423+
/// (2) fshl(i8 15, i8 15, i8 11) = 120 (0b01111000)
2424+
/// (3) fshl(i8 0, i8 255, i8 8) = 0 (0b00000000)
2425+
/// (4) fshl(i8 255, i8 0, i8 15) = fshl(i8 255, i8 0, i8 7) // 15 % 8
2426+
LLVM_ABI APInt fshl(const APInt &Hi, const APInt &Lo, const APInt &Shift);
2427+
2428+
/// Perform a funnel shift right.
2429+
///
2430+
/// Concatenate Hi and Lo (Hi is the most significant bits of the wide value),
2431+
/// the combined value is shifted right by Shift (modulo the bit width of the
2432+
/// original arguments), and the least significant bits are extracted to produce
2433+
/// a result that is the same size as the original arguments.
2434+
///
2435+
/// Examples:
2436+
/// (1) fshr(i8 255, i8 0, i8 15) = 254 (0b11111110)
2437+
/// (2) fshr(i8 15, i8 15, i8 11) = 225 (0b11100001)
2438+
/// (3) fshr(i8 0, i8 255, i8 8) = 255 (0b11111111)
2439+
/// (4) fshr(i8 255, i8 0, i8 9) = fshr(i8 255, i8 0, i8 1) // 9 % 8
2440+
LLVM_ABI APInt fshr(const APInt &Hi, const APInt &Lo, const APInt &Shift);
2441+
24132442
} // namespace APIntOps
24142443

24152444
// See friend declaration above. This additional declaration is required in

llvm/lib/Support/APInt.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3169,3 +3169,21 @@ APInt APIntOps::pow(const APInt &X, int64_t N) {
31693169
}
31703170
return Acc;
31713171
}
3172+
3173+
APInt llvm::APIntOps::fshl(const APInt &Hi, const APInt &Lo,
3174+
const APInt &Shift) {
3175+
assert(Hi.getBitWidth() == Lo.getBitWidth());
3176+
unsigned ShiftAmt = rotateModulo(Hi.getBitWidth(), Shift);
3177+
if (ShiftAmt == 0)
3178+
return Hi;
3179+
return Hi.shl(ShiftAmt) | Lo.lshr(Hi.getBitWidth() - ShiftAmt);
3180+
}
3181+
3182+
APInt llvm::APIntOps::fshr(const APInt &Hi, const APInt &Lo,
3183+
const APInt &Shift) {
3184+
assert(Hi.getBitWidth() == Lo.getBitWidth());
3185+
unsigned ShiftAmt = rotateModulo(Hi.getBitWidth(), Shift);
3186+
if (ShiftAmt == 0)
3187+
return Lo;
3188+
return Hi.shl(Hi.getBitWidth() - ShiftAmt) | Lo.lshr(ShiftAmt);
3189+
}

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,13 @@ AArch64TTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
643643
LT.second.getScalarSizeInBits() == RetTy->getScalarSizeInBits() ? 1 : 4;
644644
if (any_of(ValidSatTys, [&LT](MVT M) { return M == LT.second; }))
645645
return LT.first * Instrs;
646+
647+
TypeSize TS = getDataLayout().getTypeSizeInBits(RetTy);
648+
uint64_t VectorSize = TS.getKnownMinValue();
649+
650+
if (ST->isSVEAvailable() && VectorSize >= 128 && isPowerOf2_64(VectorSize))
651+
return LT.first * Instrs;
652+
646653
break;
647654
}
648655
case Intrinsic::abs: {

0 commit comments

Comments
 (0)