Skip to content

Commit f94cdd2

Browse files
committed
Merge "merge main into amd-staging" into amd-staging
2 parents 307e0d3 + cdce91c commit f94cdd2

File tree

176 files changed

+13419
-967
lines changed

Some content is hidden

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

176 files changed

+13419
-967
lines changed

clang/include/clang/Lex/Preprocessor.h

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,22 +1053,6 @@ class Preprocessor {
10531053
std::optional<MacroAnnotationInfo> DeprecationInfo;
10541054
std::optional<MacroAnnotationInfo> RestrictExpansionInfo;
10551055
std::optional<SourceLocation> FinalAnnotationLoc;
1056-
1057-
static MacroAnnotations makeDeprecation(SourceLocation Loc,
1058-
std::string Msg) {
1059-
return MacroAnnotations{MacroAnnotationInfo{Loc, std::move(Msg)},
1060-
std::nullopt, std::nullopt};
1061-
}
1062-
1063-
static MacroAnnotations makeRestrictExpansion(SourceLocation Loc,
1064-
std::string Msg) {
1065-
return MacroAnnotations{
1066-
std::nullopt, MacroAnnotationInfo{Loc, std::move(Msg)}, std::nullopt};
1067-
}
1068-
1069-
static MacroAnnotations makeFinal(SourceLocation Loc) {
1070-
return MacroAnnotations{std::nullopt, std::nullopt, Loc};
1071-
}
10721056
};
10731057

10741058
/// Warning information for macro annotations.
@@ -2884,35 +2868,18 @@ class Preprocessor {
28842868

28852869
void addMacroDeprecationMsg(const IdentifierInfo *II, std::string Msg,
28862870
SourceLocation AnnotationLoc) {
2887-
auto Annotations = AnnotationInfos.find(II);
2888-
if (Annotations == AnnotationInfos.end())
2889-
AnnotationInfos.insert(std::make_pair(
2890-
II,
2891-
MacroAnnotations::makeDeprecation(AnnotationLoc, std::move(Msg))));
2892-
else
2893-
Annotations->second.DeprecationInfo =
2894-
MacroAnnotationInfo{AnnotationLoc, std::move(Msg)};
2871+
AnnotationInfos[II].DeprecationInfo =
2872+
MacroAnnotationInfo{AnnotationLoc, std::move(Msg)};
28952873
}
28962874

28972875
void addRestrictExpansionMsg(const IdentifierInfo *II, std::string Msg,
28982876
SourceLocation AnnotationLoc) {
2899-
auto Annotations = AnnotationInfos.find(II);
2900-
if (Annotations == AnnotationInfos.end())
2901-
AnnotationInfos.insert(
2902-
std::make_pair(II, MacroAnnotations::makeRestrictExpansion(
2903-
AnnotationLoc, std::move(Msg))));
2904-
else
2905-
Annotations->second.RestrictExpansionInfo =
2906-
MacroAnnotationInfo{AnnotationLoc, std::move(Msg)};
2877+
AnnotationInfos[II].RestrictExpansionInfo =
2878+
MacroAnnotationInfo{AnnotationLoc, std::move(Msg)};
29072879
}
29082880

29092881
void addFinalLoc(const IdentifierInfo *II, SourceLocation AnnotationLoc) {
2910-
auto Annotations = AnnotationInfos.find(II);
2911-
if (Annotations == AnnotationInfos.end())
2912-
AnnotationInfos.insert(
2913-
std::make_pair(II, MacroAnnotations::makeFinal(AnnotationLoc)));
2914-
else
2915-
Annotations->second.FinalAnnotationLoc = AnnotationLoc;
2882+
AnnotationInfos[II].FinalAnnotationLoc = AnnotationLoc;
29162883
}
29172884

29182885
const MacroAnnotations &getMacroAnnotations(const IdentifierInfo *II) const {

clang/include/clang/Serialization/ASTReader.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,15 @@ class ASTReader
11881188
/// once recursing loading has been completed.
11891189
llvm::SmallVector<NamedDecl *, 16> PendingOdrMergeChecks;
11901190

1191+
/// Lambdas that need to be loaded right after the function they belong to.
1192+
/// It is required to have canonical declaration for lambda class from the
1193+
/// same module as enclosing function. This is required to correctly resolve
1194+
/// captured variables in the lambda. Without this, due to lazy
1195+
/// deserialization canonical declarations for the function and lambdas can
1196+
/// be from different modules and DeclRefExprs may refer to the AST nodes
1197+
/// that don't exist in the function.
1198+
SmallVector<GlobalDeclID, 4> PendingLambdas;
1199+
11911200
using DataPointers =
11921201
std::pair<CXXRecordDecl *, struct CXXRecordDecl::DefinitionData *>;
11931202
using ObjCInterfaceDataPointers =

clang/lib/APINotes/APINotesWriter.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,9 @@ class APINotesWriter::Implementation {
129129
if (Identifier.empty())
130130
return 0;
131131

132-
auto Known = IdentifierIDs.find(Identifier);
133-
if (Known != IdentifierIDs.end())
134-
return Known->second;
135-
136-
// Add to the identifier table.
137-
Known = IdentifierIDs.insert({Identifier, IdentifierIDs.size() + 1}).first;
138-
return Known->second;
132+
// Add to the identifier table if missing.
133+
return IdentifierIDs.try_emplace(Identifier, IdentifierIDs.size() + 1)
134+
.first->second;
139135
}
140136

141137
/// Retrieve the ID for the given selector.

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,16 +1177,16 @@ bool CallVirt(InterpState &S, CodePtr OpPC, const Function *Func,
11771177
return true;
11781178
}
11791179

1180-
bool CallBI(InterpState &S, CodePtr &PC, const Function *Func,
1180+
bool CallBI(InterpState &S, CodePtr OpPC, const Function *Func,
11811181
const CallExpr *CE, uint32_t BuiltinID) {
11821182
if (S.checkingPotentialConstantExpression())
11831183
return false;
1184-
auto NewFrame = std::make_unique<InterpFrame>(S, Func, PC);
1184+
auto NewFrame = std::make_unique<InterpFrame>(S, Func, OpPC);
11851185

11861186
InterpFrame *FrameBefore = S.Current;
11871187
S.Current = NewFrame.get();
11881188

1189-
if (InterpretBuiltin(S, PC, Func, CE, BuiltinID)) {
1189+
if (InterpretBuiltin(S, OpPC, Func, CE, BuiltinID)) {
11901190
NewFrame.release();
11911191
return true;
11921192
}

clang/lib/AST/ByteCode/Interp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ bool Call(InterpState &S, CodePtr OpPC, const Function *Func,
154154
uint32_t VarArgSize);
155155
bool CallVirt(InterpState &S, CodePtr OpPC, const Function *Func,
156156
uint32_t VarArgSize);
157-
bool CallBI(InterpState &S, CodePtr &PC, const Function *Func,
157+
bool CallBI(InterpState &S, CodePtr OpPC, const Function *Func,
158158
const CallExpr *CE, uint32_t BuiltinID);
159159
bool CallPtr(InterpState &S, CodePtr OpPC, uint32_t ArgSize,
160160
const CallExpr *CE);

clang/lib/Driver/ToolChains/AMDGPU.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,23 @@ RocmInstallationDetector::getCommonBitcodeLibs(
10801080
return BCLibs;
10811081
}
10821082

1083+
bool AMDGPUToolChain::shouldSkipArgument(const llvm::opt::Arg *A) const {
1084+
Option O = A->getOption();
1085+
if (O.matches(options::OPT_fPIE) || O.matches(options::OPT_fpie))
1086+
return true;
1087+
return false;
1088+
}
1089+
1090+
llvm::SmallVector<std::string, 12>
1091+
ROCMToolChain::getCommonDeviceLibNames(const llvm::opt::ArgList &DriverArgs,
1092+
const std::string &GPUArch,
1093+
bool isOpenMP) const {
1094+
RocmInstallationDetector RocmInstallation(getDriver(), getTriple(),
1095+
DriverArgs, true, true);
1096+
return amdgpu::dlr::getCommonDeviceLibNames(DriverArgs, getDriver(), GPUArch,
1097+
isOpenMP, RocmInstallation);
1098+
}
1099+
10831100
bool AMDGPUToolChain::shouldSkipSanitizeOption(
10841101
const ToolChain &TC, const llvm::opt::ArgList &DriverArgs,
10851102
StringRef TargetID, const llvm::opt::Arg *A) const {
@@ -1115,20 +1132,3 @@ bool AMDGPUToolChain::shouldSkipSanitizeOption(
11151132
}
11161133
return false;
11171134
}
1118-
1119-
bool AMDGPUToolChain::shouldSkipArgument(const llvm::opt::Arg *A) const {
1120-
Option O = A->getOption();
1121-
if (O.matches(options::OPT_fPIE) || O.matches(options::OPT_fpie))
1122-
return true;
1123-
return false;
1124-
}
1125-
1126-
llvm::SmallVector<std::string, 12>
1127-
ROCMToolChain::getCommonDeviceLibNames(const llvm::opt::ArgList &DriverArgs,
1128-
const std::string &GPUArch,
1129-
bool isOpenMP) const {
1130-
RocmInstallationDetector RocmInstallation(getDriver(), getTriple(),
1131-
DriverArgs, true, true);
1132-
return amdgpu::dlr::getCommonDeviceLibNames(DriverArgs, getDriver(), GPUArch,
1133-
isOpenMP, RocmInstallation);
1134-
}

clang/lib/Driver/ToolChains/AMDGPU.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUToolChain : public Generic_ELF {
138138
/// Needed for translating LTO options.
139139
const char *getDefaultLinker() const override { return "ld.lld"; }
140140

141-
/// Should skip Sanitize options
141+
/// Should skip sanitize options.
142142
bool shouldSkipSanitizeOption(const ToolChain &TC,
143143
const llvm::opt::ArgList &DriverArgs,
144144
StringRef TargetID,

clang/lib/Driver/ToolChains/HIPAMD.cpp

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -36,43 +36,6 @@ using namespace llvm::opt;
3636
#define NULL_FILE "/dev/null"
3737
#endif
3838

39-
static bool shouldSkipSanitizeOption(const ToolChain &TC,
40-
const llvm::opt::ArgList &DriverArgs,
41-
StringRef TargetID,
42-
const llvm::opt::Arg *A) {
43-
// For actions without targetID, do nothing.
44-
if (TargetID.empty())
45-
return false;
46-
Option O = A->getOption();
47-
if (!O.matches(options::OPT_fsanitize_EQ))
48-
return false;
49-
50-
if (!DriverArgs.hasFlag(options::OPT_fgpu_sanitize,
51-
options::OPT_fno_gpu_sanitize, true))
52-
return true;
53-
54-
auto &Diags = TC.getDriver().getDiags();
55-
56-
// For simplicity, we only allow -fsanitize=address
57-
SanitizerMask K = parseSanitizerValue(A->getValue(), /*AllowGroups=*/false);
58-
if (K != SanitizerKind::Address)
59-
return true;
60-
61-
llvm::StringMap<bool> FeatureMap;
62-
auto OptionalGpuArch = parseTargetID(TC.getTriple(), TargetID, &FeatureMap);
63-
64-
assert(OptionalGpuArch && "Invalid Target ID");
65-
(void)OptionalGpuArch;
66-
auto Loc = FeatureMap.find("xnack");
67-
if (Loc == FeatureMap.end() || !Loc->second) {
68-
Diags.Report(
69-
clang::diag::warn_drv_unsupported_option_for_offload_arch_req_feature)
70-
<< A->getAsString(DriverArgs) << TargetID << "xnack+";
71-
return true;
72-
}
73-
return false;
74-
}
75-
7639
void AMDGCN::Linker::constructLlvmLinkCommand(Compilation &C,
7740
const JobAction &JA,
7841
const InputInfoList &Inputs,

clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,9 @@ void ObjCPropertyAttributeOrderFixer::sortPropertyAttributes(
8686
Value = Tok->TokenText;
8787
}
8888

89-
auto It = SortOrderMap.find(Attribute);
90-
if (It == SortOrderMap.end())
91-
It = SortOrderMap.insert({Attribute, SortOrderMap.size()}).first;
92-
9389
// Sort the indices based on the priority stored in `SortOrderMap`.
94-
const auto Ordinal = It->second;
90+
const auto Ordinal =
91+
SortOrderMap.try_emplace(Attribute, SortOrderMap.size()).first->second;
9592
if (!Ordinals.insert(Ordinal).second) {
9693
HasDuplicates = true;
9794
continue;

clang/lib/Serialization/ASTReader.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9782,7 +9782,8 @@ void ASTReader::finishPendingActions() {
97829782
!PendingDeducedVarTypes.empty() || !PendingIncompleteDeclChains.empty() ||
97839783
!PendingDeclChains.empty() || !PendingMacroIDs.empty() ||
97849784
!PendingDeclContextInfos.empty() || !PendingUpdateRecords.empty() ||
9785-
!PendingObjCExtensionIvarRedeclarations.empty()) {
9785+
!PendingObjCExtensionIvarRedeclarations.empty() ||
9786+
!PendingLambdas.empty()) {
97869787
// If any identifiers with corresponding top-level declarations have
97879788
// been loaded, load those declarations now.
97889789
using TopLevelDeclsMap =
@@ -9927,6 +9928,11 @@ void ASTReader::finishPendingActions() {
99279928
}
99289929
PendingObjCExtensionIvarRedeclarations.pop_back();
99299930
}
9931+
9932+
// Load any pendiong lambdas.
9933+
for (auto ID : PendingLambdas)
9934+
GetDecl(ID);
9935+
PendingLambdas.clear();
99309936
}
99319937

99329938
// At this point, all update records for loaded decls are in place, so any

clang/lib/Serialization/ASTReaderDecl.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,16 @@ void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
11551155
for (unsigned I = 0; I != NumParams; ++I)
11561156
Params.push_back(readDeclAs<ParmVarDecl>());
11571157
FD->setParams(Reader.getContext(), Params);
1158+
1159+
// For the first decl add all lambdas inside for loading them later,
1160+
// otherwise skip them.
1161+
unsigned NumLambdas = Record.readInt();
1162+
if (FD->isFirstDecl()) {
1163+
for (unsigned I = 0; I != NumLambdas; ++I)
1164+
Reader.PendingLambdas.push_back(Record.readDeclID());
1165+
} else {
1166+
Record.skipInts(NumLambdas);
1167+
}
11581168
}
11591169

11601170
void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {

clang/lib/Serialization/ASTWriterDecl.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "clang/AST/Expr.h"
1919
#include "clang/AST/OpenMPClause.h"
2020
#include "clang/AST/PrettyDeclStackTrace.h"
21+
#include "clang/AST/StmtVisitor.h"
2122
#include "clang/Basic/SourceManager.h"
2223
#include "clang/Serialization/ASTReader.h"
2324
#include "clang/Serialization/ASTRecordWriter.h"
@@ -625,6 +626,33 @@ void ASTDeclWriter::VisitDeclaratorDecl(DeclaratorDecl *D) {
625626
: QualType());
626627
}
627628

629+
static llvm::SmallVector<const Decl *, 2> collectLambdas(FunctionDecl *D) {
630+
struct LambdaCollector : public ConstStmtVisitor<LambdaCollector> {
631+
llvm::SmallVectorImpl<const Decl *> &Lambdas;
632+
633+
LambdaCollector(llvm::SmallVectorImpl<const Decl *> &Lambdas)
634+
: Lambdas(Lambdas) {}
635+
636+
void VisitLambdaExpr(const LambdaExpr *E) {
637+
VisitStmt(E);
638+
Lambdas.push_back(E->getLambdaClass());
639+
}
640+
641+
void VisitStmt(const Stmt *S) {
642+
if (!S)
643+
return;
644+
for (const Stmt *Child : S->children())
645+
if (Child)
646+
Visit(Child);
647+
}
648+
};
649+
650+
llvm::SmallVector<const Decl *, 2> Lambdas;
651+
if (D->hasBody())
652+
LambdaCollector(Lambdas).VisitStmt(D->getBody());
653+
return Lambdas;
654+
}
655+
628656
void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
629657
static_assert(DeclContext::NumFunctionDeclBits == 44,
630658
"You need to update the serializer after you change the "
@@ -764,6 +792,19 @@ void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
764792
Record.push_back(D->param_size());
765793
for (auto *P : D->parameters())
766794
Record.AddDeclRef(P);
795+
796+
// Store references to all lambda decls inside function to load them
797+
// immediately after loading the function to make sure that canonical
798+
// decls for lambdas will be from the same module.
799+
if (D->isCanonicalDecl()) {
800+
llvm::SmallVector<const Decl *, 2> Lambdas = collectLambdas(D);
801+
Record.push_back(Lambdas.size());
802+
for (const auto *L : Lambdas)
803+
Record.AddDeclRef(L);
804+
} else {
805+
Record.push_back(0);
806+
}
807+
767808
Code = serialization::DECL_FUNCTION;
768809
}
769810

@@ -2239,6 +2280,7 @@ getFunctionDeclAbbrev(serialization::DeclCode Code) {
22392280
//
22402281
// This is:
22412282
// NumParams and Params[] from FunctionDecl, and
2283+
// NumLambdas, Lambdas[] from FunctionDecl, and
22422284
// NumOverriddenMethods, OverriddenMethods[] from CXXMethodDecl.
22432285
//
22442286
// Add an AbbrevOp for 'size then elements' and use it here.

clang/test/AST/ByteCode/cxx20.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ namespace ThreeWayCmp {
641641
constexpr const int *pa2 = &a[2];
642642
constexpr const int *pb1 = &b[1];
643643
static_assert(pa1 <=> pb1 != 0, ""); // both-error {{not an integral constant expression}} \
644-
// both-note {{has unspecified value}} \
644+
// both-note {{has unspecified value}}
645645
static_assert(pa1 <=> pa1 == 0, "");
646646
static_assert(pa1 <=> pa2 == -1, "");
647647
static_assert(pa2 <=> pa1 == 1, "");

0 commit comments

Comments
 (0)