Skip to content

Commit 04ac394

Browse files
author
z1_cciauto
authored
merge main into amd-staging (llvm#3681)
2 parents 9541a94 + beb2778 commit 04ac394

File tree

87 files changed

+5030
-1832
lines changed

Some content is hidden

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

87 files changed

+5030
-1832
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/docs/LanguageExtensions.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,6 +1760,7 @@ Hexadecimal floating constants (N308) C
17601760
Compound literals (N716) C99 C89, C++
17611761
``//`` comments (N644) C99 C89
17621762
Mixed declarations and code (N740) C99 C89
1763+
init-statement in for (N740) C99 C89
17631764
Variadic macros (N707) C99 C89
17641765
Empty macro arguments (N570) C99 C89
17651766
Trailing comma in enum declaration C99 C89

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ Bug Fixes in This Version
475475
cast chain. (#GH149967).
476476
- Fixed a crash with incompatible pointer to integer conversions in designated
477477
initializers involving string literals. (#GH154046)
478+
- Clang's ``<stddef.h>`` now properly declares ``nullptr_t`` in C++ mode. (#GH154577).
478479

479480
Bug Fixes to Compiler Builtins
480481
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2683,9 +2683,10 @@ static bool interp__builtin_ia32_pmul(InterpState &S, CodePtr OpPC,
26832683
const auto *VT = Call->getArg(0)->getType()->castAs<VectorType>();
26842684
PrimType ElemT = *S.getContext().classify(VT->getElementType());
26852685
unsigned SourceLen = VT->getNumElements();
2686-
SmallVector<APValue, 4> ResultElements;
2687-
ResultElements.reserve(SourceLen / 2);
26882686

2687+
PrimType DstElemT = *S.getContext().classify(
2688+
Call->getType()->castAs<VectorType>()->getElementType());
2689+
unsigned DstElem = 0;
26892690
for (unsigned I = 0; I != SourceLen; I += 2) {
26902691
APSInt Elem1;
26912692
APSInt Elem2;
@@ -2699,16 +2700,19 @@ static bool interp__builtin_ia32_pmul(InterpState &S, CodePtr OpPC,
26992700
case clang::X86::BI__builtin_ia32_pmuludq128:
27002701
case clang::X86::BI__builtin_ia32_pmuludq256:
27012702
case clang::X86::BI__builtin_ia32_pmuludq512:
2702-
Result = APSInt(llvm::APIntOps::muluExtended(Elem1, Elem2), true);
2703+
Result = APSInt(llvm::APIntOps::muluExtended(Elem1, Elem2),
2704+
/*IsUnsigned=*/true);
27032705
break;
27042706
case clang::X86::BI__builtin_ia32_pmuldq128:
27052707
case clang::X86::BI__builtin_ia32_pmuldq256:
27062708
case clang::X86::BI__builtin_ia32_pmuldq512:
2707-
Result = APSInt(llvm::APIntOps::mulsExtended(Elem1, Elem2), false);
2709+
Result = APSInt(llvm::APIntOps::mulsExtended(Elem1, Elem2),
2710+
/*IsUnsigned=*/false);
27082711
break;
27092712
}
2710-
INT_TYPE_SWITCH_NO_BOOL(ElemT,
2711-
{ Dst.elem<T>(I) = static_cast<T>(Result); });
2713+
INT_TYPE_SWITCH_NO_BOOL(DstElemT,
2714+
{ Dst.elem<T>(DstElem) = static_cast<T>(Result); });
2715+
++DstElem;
27122716
}
27132717

27142718
Dst.initializeAllElements();
@@ -3204,6 +3208,7 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
32043208
case clang::X86::BI__builtin_ia32_pmuldq512:
32053209
case clang::X86::BI__builtin_ia32_pmuludq128:
32063210
case clang::X86::BI__builtin_ia32_pmuludq256:
3211+
case clang::X86::BI__builtin_ia32_pmuludq512:
32073212
return interp__builtin_ia32_pmul(S, OpPC, Call, BuiltinID);
32083213
case Builtin::BI__builtin_elementwise_fma:
32093214
return interp__builtin_elementwise_fma(S, OpPC, Call);

clang/lib/CodeGen/CGDecl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,11 +1569,10 @@ CodeGenFunction::EmitAutoVarAlloca(const VarDecl &D) {
15691569
// The named return value optimization: allocate this variable in the
15701570
// return slot, so that we can elide the copy when returning this
15711571
// variable (C++0x [class.copy]p34).
1572-
address = ReturnValue;
15731572
AllocaAddr =
15741573
RawAddress(ReturnValue.emitRawPointer(*this),
15751574
ReturnValue.getElementType(), ReturnValue.getAlignment());
1576-
;
1575+
address = MaybeCastStackAddressSpace(AllocaAddr, Ty.getAddressSpace());
15771576

15781577
if (const RecordType *RecordTy = Ty->getAs<RecordType>()) {
15791578
const auto *RD = RecordTy->getOriginalDecl()->getDefinitionOrSelf();

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,10 @@ CodeGenFunction::CreateTempAllocaWithoutCast(llvm::Type *Ty, CharUnits Align,
108108
return RawAddress(Alloca, Ty, Align, KnownNonNull);
109109
}
110110

111-
RawAddress CodeGenFunction::CreateTempAlloca(llvm::Type *Ty, LangAS DestLangAS,
112-
CharUnits Align, const Twine &Name,
113-
llvm::Value *ArraySize,
114-
RawAddress *AllocaAddr) {
115-
RawAddress Alloca = CreateTempAllocaWithoutCast(Ty, Align, Name, ArraySize);
116-
if (AllocaAddr)
117-
*AllocaAddr = Alloca;
111+
RawAddress CodeGenFunction::MaybeCastStackAddressSpace(RawAddress Alloca,
112+
LangAS DestLangAS,
113+
llvm::Value *ArraySize) {
114+
118115
llvm::Value *V = Alloca.getPointer();
119116
// Alloca always returns a pointer in alloca address space, which may
120117
// be different from the type defined by the language. For example,
@@ -134,7 +131,18 @@ RawAddress CodeGenFunction::CreateTempAlloca(llvm::Type *Ty, LangAS DestLangAS,
134131
/*IsNonNull=*/true);
135132
}
136133

137-
return RawAddress(V, Ty, Align, KnownNonNull);
134+
return RawAddress(V, Alloca.getElementType(), Alloca.getAlignment(),
135+
KnownNonNull);
136+
}
137+
138+
RawAddress CodeGenFunction::CreateTempAlloca(llvm::Type *Ty, LangAS DestLangAS,
139+
CharUnits Align, const Twine &Name,
140+
llvm::Value *ArraySize,
141+
RawAddress *AllocaAddr) {
142+
RawAddress Alloca = CreateTempAllocaWithoutCast(Ty, Align, Name, ArraySize);
143+
if (AllocaAddr)
144+
*AllocaAddr = Alloca;
145+
return MaybeCastStackAddressSpace(Alloca, DestLangAS, ArraySize);
138146
}
139147

140148
/// CreateTempAlloca - This creates an alloca and inserts it into the entry

clang/lib/CodeGen/CodeGenFunction.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2806,6 +2806,13 @@ class CodeGenFunction : public CodeGenTypeCache {
28062806
AllocaTracker Tracker;
28072807
};
28082808

2809+
private:
2810+
/// If \p Alloca is not in the same address space as \p DestLangAS, insert an
2811+
/// address space cast and return a new RawAddress based on this value.
2812+
RawAddress MaybeCastStackAddressSpace(RawAddress Alloca, LangAS DestLangAS,
2813+
llvm::Value *ArraySize = nullptr);
2814+
2815+
public:
28092816
/// CreateTempAlloca - This creates an alloca and inserts it into the entry
28102817
/// block if \p ArraySize is nullptr, otherwise inserts it at the current
28112818
/// insertion point of the builder. The caller is responsible for setting an

0 commit comments

Comments
 (0)