Skip to content

Commit 73dac5a

Browse files
committed
merge main into amd-staging
2 parents 73ddf80 + 5a90168 commit 73dac5a

File tree

130 files changed

+3184
-826
lines changed

Some content is hidden

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

130 files changed

+3184
-826
lines changed

.github/CODEOWNERS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp @nikic
2828
/llvm/lib/Transforms/InstCombine/ @nikic
2929

30-
/clang/include/clang/Sema/Sema.h @Endilll
3130
/clang/test/CXX/drs/ @Endilll
3231
/clang/www/cxx_dr_status.html @Endilll
3332
/clang/www/make_cxx_dr_status @Endilll

clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ getNewFieldsOrder(const RecordDecl *Definition,
6363
NameToIndex[Field->getName()] = Field->getFieldIndex();
6464

6565
if (DesiredFieldsOrder.size() != NameToIndex.size()) {
66-
llvm::errs() << "Number of provided fields doesn't match definition.\n";
66+
llvm::errs() << "Number of provided fields (" << DesiredFieldsOrder.size()
67+
<< ") doesn't match definition (" << NameToIndex.size()
68+
<< ").\n";
6769
return {};
6870
}
6971
SmallVector<unsigned, 4> NewFieldsOrder;
@@ -116,26 +118,77 @@ findMembersUsedInInitExpr(const CXXCtorInitializer *Initializer,
116118
return Results;
117119
}
118120

119-
/// Returns the full source range for the field declaration up to (not
120-
/// including) the trailing semicolumn, including potential macro invocations,
121-
/// e.g. `int a GUARDED_BY(mu);`.
121+
/// Returns the next token after `Loc` (including comment tokens).
122+
static std::optional<Token> getTokenAfter(SourceLocation Loc,
123+
const SourceManager &SM,
124+
const LangOptions &LangOpts) {
125+
if (Loc.isMacroID()) {
126+
return std::nullopt;
127+
}
128+
Loc = Lexer::getLocForEndOfToken(Loc, 0, SM, LangOpts);
129+
130+
// Break down the source location.
131+
std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(Loc);
132+
133+
// Try to load the file buffer.
134+
bool InvalidTemp = false;
135+
StringRef File = SM.getBufferData(LocInfo.first, &InvalidTemp);
136+
if (InvalidTemp)
137+
return std::nullopt;
138+
139+
const char *TokenBegin = File.data() + LocInfo.second;
140+
141+
Lexer lexer(SM.getLocForStartOfFile(LocInfo.first), LangOpts, File.begin(),
142+
TokenBegin, File.end());
143+
lexer.SetCommentRetentionState(true);
144+
// Find the token.
145+
Token Tok;
146+
lexer.LexFromRawLexer(Tok);
147+
return Tok;
148+
}
149+
150+
/// Returns the end of the trailing comments after `Loc`.
151+
static SourceLocation getEndOfTrailingComment(SourceLocation Loc,
152+
const SourceManager &SM,
153+
const LangOptions &LangOpts) {
154+
// We consider any following comment token that is indented more than the
155+
// first comment to be part of the trailing comment.
156+
const unsigned Column = SM.getPresumedColumnNumber(Loc);
157+
std::optional<Token> Tok = getTokenAfter(Loc, SM, LangOpts);
158+
while (Tok && Tok->is(tok::comment) &&
159+
SM.getPresumedColumnNumber(Tok->getLocation()) > Column) {
160+
Loc = Tok->getEndLoc();
161+
Tok = getTokenAfter(Loc, SM, LangOpts);
162+
}
163+
return Loc;
164+
}
165+
166+
/// Returns the full source range for the field declaration up to (including)
167+
/// the trailing semicolumn, including potential macro invocations,
168+
/// e.g. `int a GUARDED_BY(mu);`. If there is a trailing comment, include it.
122169
static SourceRange getFullFieldSourceRange(const FieldDecl &Field,
123170
const ASTContext &Context) {
124-
SourceRange Range = Field.getSourceRange();
171+
const SourceRange Range = Field.getSourceRange();
172+
SourceLocation Begin = Range.getBegin();
125173
SourceLocation End = Range.getEnd();
126174
const SourceManager &SM = Context.getSourceManager();
127175
const LangOptions &LangOpts = Context.getLangOpts();
128176
while (true) {
129177
std::optional<Token> CurrentToken = Lexer::findNextToken(End, SM, LangOpts);
130178

131-
if (!CurrentToken || CurrentToken->is(tok::semi))
132-
break;
179+
if (!CurrentToken)
180+
return SourceRange(Begin, End);
133181

134182
if (CurrentToken->is(tok::eof))
135183
return Range; // Something is wrong, return the original range.
184+
136185
End = CurrentToken->getLastLoc();
186+
187+
if (CurrentToken->is(tok::semi))
188+
break;
137189
}
138-
return SourceRange(Range.getBegin(), End);
190+
End = getEndOfTrailingComment(End, SM, LangOpts);
191+
return SourceRange(Begin, End);
139192
}
140193

141194
/// Reorders fields in the definition of a struct/class.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: clang-reorder-fields -record-name Foo -fields-order e1,e3,e2,a,c,b %s -- | FileCheck %s
2+
3+
class Foo {
4+
int a; // Trailing comment for a.
5+
int b; // Multiline
6+
// trailing for b.
7+
// Prefix comments for c.
8+
int c;
9+
10+
/*c-like*/ int e1;
11+
int /*c-like*/ e2;
12+
int e3 /*c-like*/;
13+
};
14+
15+
// CHECK: /*c-like*/ int e1;
16+
// CHECK-NEXT: int e3 /*c-like*/;
17+
// CHECK-NEXT: int /*c-like*/ e2;
18+
// CHECK-NEXT: int a; // Trailing comment for a.
19+
// CHECK-NEXT: // Prefix comments for c.
20+
// CHECK-NEXT: int c;
21+
// CHECK-NEXT: int b; // Multiline
22+
// CHECK-NEXT: // trailing for b.
23+

clang/cmake/caches/hexagon-unknown-linux-musl-clang-cross.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ set(CLANG_LINKS_TO_CREATE
1010
hexagon-none-elf-clang
1111
hexagon-unknown-none-elf-clang++
1212
hexagon-unknown-none-elf-clang
13+
clang++
14+
clang-cl
15+
clang-cpp
1316
CACHE STRING "")
1417

1518
set(LLVM_INSTALL_TOOLCHAIN_ONLY ON CACHE BOOL "")

clang/include/clang/Driver/Driver.h

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,28 @@ enum ModuleHeaderMode {
7272
HeaderMode_System
7373
};
7474

75+
/// Options for specifying CUID used by CUDA/HIP for uniquely identifying
76+
/// compilation units.
77+
class CUIDOptions {
78+
public:
79+
enum class Kind { Hash, Random, Fixed, None, Invalid };
80+
81+
CUIDOptions() = default;
82+
CUIDOptions(llvm::opt::DerivedArgList &Args, const Driver &D);
83+
84+
// Get the CUID for an input string
85+
std::string getCUID(StringRef InputFile,
86+
llvm::opt::DerivedArgList &Args) const;
87+
88+
bool isEnabled() const {
89+
return UseCUID != Kind::None && UseCUID != Kind::Invalid;
90+
}
91+
92+
private:
93+
Kind UseCUID = Kind::None;
94+
StringRef FixedCUID;
95+
};
96+
7597
/// Driver - Encapsulate logic for constructing compilation processes
7698
/// from a set of gcc-driver-like command line arguments.
7799
class Driver {
@@ -119,6 +141,9 @@ class Driver {
119141
/// LTO mode selected via -f(no-offload-)?lto(=.*)? options.
120142
LTOKind OffloadLTOMode;
121143

144+
/// Options for CUID
145+
CUIDOptions CUIDOpts;
146+
122147
public:
123148
enum OpenMPRuntimeKind {
124149
/// An unknown OpenMP runtime. We can't generate effective OpenMP code
@@ -511,10 +536,11 @@ class Driver {
511536
/// \param C - The compilation that is being built.
512537
/// \param Args - The input arguments.
513538
/// \param Input - The input type and arguments
539+
/// \param CUID - The CUID for \p Input
514540
/// \param HostAction - The host action used in the offloading toolchain.
515541
Action *BuildOffloadingActions(Compilation &C,
516542
llvm::opt::DerivedArgList &Args,
517-
const InputTy &Input,
543+
const InputTy &Input, StringRef CUID,
518544
Action *HostAction) const;
519545

520546
/// Returns the set of bound architectures active for this offload kind.
@@ -744,6 +770,9 @@ class Driver {
744770
/// Set the number of parallel jobs.
745771
void setNumberOfParallelJobs(unsigned N) { NumParallelJobs = N; }
746772

773+
/// Get the CUID option.
774+
const CUIDOptions &getCUIDOpts() const { return CUIDOpts; }
775+
747776
private:
748777

749778
/// Tries to load options from configuration files.

clang/include/clang/Tooling/Tooling.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,11 @@ buildASTFromCode(StringRef Code, StringRef FileName = "input.cc",
223223
/// \param PCHContainerOps The PCHContainerOperations for loading and creating
224224
/// clang modules.
225225
///
226-
/// \param Adjuster A function to filter the command line arguments as specified.
226+
/// \param Adjuster A function to filter the command line arguments as
227+
/// specified.
228+
///
229+
/// \param BaseFS FileSystem for managing and looking up files.
230+
/// VirtualMappedFiles takes precedence.
227231
///
228232
/// \return The resulting AST or null if an error occurred.
229233
std::unique_ptr<ASTUnit> buildASTFromCodeWithArgs(
@@ -233,7 +237,9 @@ std::unique_ptr<ASTUnit> buildASTFromCodeWithArgs(
233237
std::make_shared<PCHContainerOperations>(),
234238
ArgumentsAdjuster Adjuster = getClangStripDependencyFileAdjuster(),
235239
const FileContentMappings &VirtualMappedFiles = FileContentMappings(),
236-
DiagnosticConsumer *DiagConsumer = nullptr);
240+
DiagnosticConsumer *DiagConsumer = nullptr,
241+
IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS =
242+
llvm::vfs::getRealFileSystem());
237243

238244
/// Utility to run a FrontendAction in a single clang invocation.
239245
class ToolInvocation {

clang/lib/AST/ASTImporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6376,7 +6376,7 @@ ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl(
63766376
D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind());
63776377

63786378
if (auto P = D->getInstantiatedFrom()) {
6379-
if (auto *CTD = P.dyn_cast<ClassTemplateDecl *>()) {
6379+
if (auto *CTD = dyn_cast<ClassTemplateDecl *>(P)) {
63806380
if (auto CTDorErr = import(CTD))
63816381
D2->setInstantiationOf(*CTDorErr);
63826382
} else {

clang/lib/Basic/TargetInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ void TargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
425425
// HLSL explicitly defines the sizes and formats of some data types, and we
426426
// need to conform to those regardless of what architecture you are targeting.
427427
if (Opts.HLSL) {
428+
BoolWidth = BoolAlign = 32;
428429
LongWidth = LongAlign = 64;
429430
if (!Opts.NativeHalfType) {
430431
HalfFormat = &llvm::APFloat::IEEEsingle();

clang/lib/Basic/Targets/ARM.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,8 @@ bool ARMTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
617617
case 6:
618618
if (ArchProfile == llvm::ARM::ProfileKind::M)
619619
LDREX = 0;
620-
else if (ArchKind == llvm::ARM::ArchKind::ARMV6K)
620+
else if (ArchKind == llvm::ARM::ArchKind::ARMV6K ||
621+
ArchKind == llvm::ARM::ArchKind::ARMV6KZ)
621622
LDREX = LDREX_D | LDREX_W | LDREX_H | LDREX_B;
622623
else
623624
LDREX = LDREX_W;

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7817,7 +7817,7 @@ class MappableExprsHandler {
78177817
&Data : RecordLayout) {
78187818
if (Data.isNull())
78197819
continue;
7820-
if (const auto *Base = Data.dyn_cast<const CXXRecordDecl *>())
7820+
if (const auto *Base = dyn_cast<const CXXRecordDecl *>(Data))
78217821
getPlainLayout(Base, Layout, /*AsBase=*/true);
78227822
else
78237823
Layout.push_back(cast<const FieldDecl *>(Data));

0 commit comments

Comments
 (0)