Skip to content

Commit b495090

Browse files
Merge branch 'main' into sve_neon_fp8
2 parents bb7cd6d + 4cda28c commit b495090

File tree

769 files changed

+41314
-8477
lines changed

Some content is hidden

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

769 files changed

+41314
-8477
lines changed

bolt/lib/Passes/LongJmp.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,8 @@ uint64_t LongJmpPass::tentativeLayoutRelocColdPart(
324324
uint64_t LongJmpPass::tentativeLayoutRelocMode(
325325
const BinaryContext &BC, std::vector<BinaryFunction *> &SortedFunctions,
326326
uint64_t DotAddress) {
327-
328327
// Compute hot cold frontier
329-
uint32_t LastHotIndex = -1u;
328+
int64_t LastHotIndex = -1u;
330329
uint32_t CurrentIndex = 0;
331330
if (opts::HotFunctionsAtEnd) {
332331
for (BinaryFunction *BF : SortedFunctions) {
@@ -351,19 +350,20 @@ uint64_t LongJmpPass::tentativeLayoutRelocMode(
351350
// Hot
352351
CurrentIndex = 0;
353352
bool ColdLayoutDone = false;
353+
auto runColdLayout = [&]() {
354+
DotAddress = tentativeLayoutRelocColdPart(BC, SortedFunctions, DotAddress);
355+
ColdLayoutDone = true;
356+
if (opts::HotFunctionsAtEnd)
357+
DotAddress = alignTo(DotAddress, opts::AlignText);
358+
};
354359
for (BinaryFunction *Func : SortedFunctions) {
355360
if (!BC.shouldEmit(*Func)) {
356361
HotAddresses[Func] = Func->getAddress();
357362
continue;
358363
}
359364

360-
if (!ColdLayoutDone && CurrentIndex >= LastHotIndex) {
361-
DotAddress =
362-
tentativeLayoutRelocColdPart(BC, SortedFunctions, DotAddress);
363-
ColdLayoutDone = true;
364-
if (opts::HotFunctionsAtEnd)
365-
DotAddress = alignTo(DotAddress, opts::AlignText);
366-
}
365+
if (!ColdLayoutDone && CurrentIndex >= LastHotIndex)
366+
runColdLayout();
367367

368368
DotAddress = alignTo(DotAddress, Func->getMinAlignment());
369369
uint64_t Pad =
@@ -382,6 +382,11 @@ uint64_t LongJmpPass::tentativeLayoutRelocMode(
382382
DotAddress += Func->estimateConstantIslandSize();
383383
++CurrentIndex;
384384
}
385+
386+
// Ensure that tentative code layout always runs for cold blocks.
387+
if (!ColdLayoutDone)
388+
runColdLayout();
389+
385390
// BBs
386391
for (BinaryFunction *Func : SortedFunctions)
387392
tentativeBBLayout(*Func);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This test checks that tentative code layout for cold blocks always runs.
2+
# It commonly happens when using lite mode with split functions.
3+
4+
# REQUIRES: system-linux, asserts
5+
6+
# RUN: %clang %cflags -o %t %s
7+
# RUN: %clang %s %cflags -Wl,-q -o %t
8+
# RUN: link_fdata --no-lbr %s %t %t.fdata
9+
# RUN: llvm-bolt %t -o %t.bolt --data %t.fdata -split-functions \
10+
# RUN: -debug 2>&1 | FileCheck %s
11+
12+
.text
13+
.globl foo
14+
.type foo, %function
15+
foo:
16+
.entry_bb:
17+
# FDATA: 1 foo #.entry_bb# 10
18+
cmp x0, #0
19+
b.eq .Lcold_bb1
20+
ret
21+
.Lcold_bb1:
22+
ret
23+
24+
## Force relocation mode.
25+
.reloc 0, R_AARCH64_NONE
26+
27+
# CHECK: foo{{.*}} cold tentative: {{.*}}

clang-tools-extra/clang-tidy/ClangTidy.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,6 @@ ClangTidyASTConsumerFactory::createASTConsumer(
458458
if (!AnalyzerOptions.CheckersAndPackages.empty()) {
459459
setStaticAnalyzerCheckerOpts(Context.getOptions(), AnalyzerOptions);
460460
AnalyzerOptions.AnalysisDiagOpt = PD_NONE;
461-
AnalyzerOptions.eagerlyAssumeBinOpBifurcation = true;
462461
std::unique_ptr<ento::AnalysisASTConsumer> AnalysisConsumer =
463462
ento::CreateAnalysisConsumer(Compiler);
464463
AnalysisConsumer->AddDiagnosticConsumer(

clang-tools-extra/include-cleaner/test/tool.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,13 @@ int x = foo();
4848
// RUN: clang-include-cleaner -edit --ignore-headers="foobar\.h,foo\.h" %t.cpp -- -I%S/Inputs/
4949
// RUN: FileCheck --match-full-lines --check-prefix=EDIT2 %s < %t.cpp
5050
// EDIT2-NOT: {{^}}#include "foo.h"{{$}}
51+
52+
// RUN: rm -rf %t.dir && mkdir -p %t.dir
53+
// RUN: cp %s %t.cpp
54+
// RUN: echo "[{\"directory\":\"%t.dir\",\"file\":\"../%{t:stem}.tmp.cpp\",\"command\":\":clang++ -I%S/Inputs/ ../%{t:stem}.tmp.cpp\"}]" | sed -e 's/\\/\\\\/g' > %t.dir/compile_commands.json
55+
// RUN: pushd %t.dir
56+
// RUN: clang-include-cleaner -p %{t:stem}.tmp.dir -edit ../%{t:stem}.tmp.cpp
57+
// RUN: popd
58+
// RUN: FileCheck --match-full-lines --check-prefix=EDIT3 %s < %t.cpp
59+
// EDIT3: #include "foo.h"
60+
// EDIT3-NOT: {{^}}#include "foobar.h"{{$}}

clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,11 @@ class Action : public clang::ASTFrontendAction {
173173
if (!HTMLReportPath.empty())
174174
writeHTML();
175175

176-
llvm::StringRef Path =
177-
SM.getFileEntryRefForID(SM.getMainFileID())->getName();
178-
assert(!Path.empty() && "Main file path not known?");
176+
// Source File's path of compiler invocation, converted to absolute path.
177+
llvm::SmallString<256> AbsPath(
178+
SM.getFileEntryRefForID(SM.getMainFileID())->getName());
179+
assert(!AbsPath.empty() && "Main file path not known?");
180+
SM.getFileManager().makeAbsolutePath(AbsPath);
179181
llvm::StringRef Code = SM.getBufferData(SM.getMainFileID());
180182

181183
auto Results =
@@ -185,7 +187,7 @@ class Action : public clang::ASTFrontendAction {
185187
Results.Missing.clear();
186188
if (!Remove)
187189
Results.Unused.clear();
188-
std::string Final = fixIncludes(Results, Path, Code, getStyle(Path));
190+
std::string Final = fixIncludes(Results, AbsPath, Code, getStyle(AbsPath));
189191

190192
if (Print.getNumOccurrences()) {
191193
switch (Print) {
@@ -202,7 +204,7 @@ class Action : public clang::ASTFrontendAction {
202204
}
203205

204206
if (!Results.Missing.empty() || !Results.Unused.empty())
205-
EditedFiles.try_emplace(Path, Final);
207+
EditedFiles.try_emplace(AbsPath, Final);
206208
}
207209

208210
void writeHTML() {
@@ -280,6 +282,48 @@ std::function<bool(llvm::StringRef)> headerFilter() {
280282
};
281283
}
282284

285+
// Maps absolute path of each files of each compilation commands to the
286+
// absolute path of the input file.
287+
llvm::Expected<std::map<std::string, std::string>>
288+
mapInputsToAbsPaths(clang::tooling::CompilationDatabase &CDB,
289+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
290+
const std::vector<std::string> &Inputs) {
291+
std::map<std::string, std::string> CDBToAbsPaths;
292+
// Factory.editedFiles()` will contain the final code, along with the
293+
// path given in the compilation database. That path can be
294+
// absolute or relative, and if it is relative, it is relative to the
295+
// "Directory" field in the compilation database. We need to make it
296+
// absolute to write the final code to the correct path.
297+
for (auto &Source : Inputs) {
298+
llvm::SmallString<256> AbsPath(Source);
299+
if (auto Err = VFS->makeAbsolute(AbsPath)) {
300+
llvm::errs() << "Failed to get absolute path for " << Source << " : "
301+
<< Err.message() << '\n';
302+
return std::move(llvm::errorCodeToError(Err));
303+
}
304+
std::vector<clang::tooling::CompileCommand> Cmds =
305+
CDB.getCompileCommands(AbsPath);
306+
if (Cmds.empty()) {
307+
// It should be found in the compilation database, even user didn't
308+
// specify the compilation database, the `FixedCompilationDatabase` will
309+
// create an entry from the arguments. So it is an error if we can't
310+
// find the compile commands.
311+
std::string ErrorMsg =
312+
llvm::formatv("No compile commands found for {0}", AbsPath).str();
313+
llvm::errs() << ErrorMsg << '\n';
314+
return llvm::make_error<llvm::StringError>(
315+
ErrorMsg, llvm::inconvertibleErrorCode());
316+
}
317+
for (const auto &Cmd : Cmds) {
318+
llvm::SmallString<256> CDBPath(Cmd.Filename);
319+
std::string Directory(Cmd.Directory);
320+
llvm::sys::fs::make_absolute(Cmd.Directory, CDBPath);
321+
CDBToAbsPaths[std::string(CDBPath)] = std::string(AbsPath);
322+
}
323+
}
324+
return CDBToAbsPaths;
325+
}
326+
283327
} // namespace
284328
} // namespace include_cleaner
285329
} // namespace clang
@@ -305,8 +349,16 @@ int main(int argc, const char **argv) {
305349
}
306350
}
307351

308-
clang::tooling::ClangTool Tool(OptionsParser->getCompilations(),
309-
OptionsParser->getSourcePathList());
352+
auto VFS = llvm::vfs::getRealFileSystem();
353+
auto &CDB = OptionsParser->getCompilations();
354+
// CDBToAbsPaths is a map from the path in the compilation database to the
355+
// writable absolute path of the file.
356+
auto CDBToAbsPaths =
357+
mapInputsToAbsPaths(CDB, VFS, OptionsParser->getSourcePathList());
358+
if (!CDBToAbsPaths)
359+
return 1;
360+
361+
clang::tooling::ClangTool Tool(CDB, OptionsParser->getSourcePathList());
310362

311363
auto HeaderFilter = headerFilter();
312364
if (!HeaderFilter)
@@ -316,6 +368,10 @@ int main(int argc, const char **argv) {
316368
if (Edit) {
317369
for (const auto &NameAndContent : Factory.editedFiles()) {
318370
llvm::StringRef FileName = NameAndContent.first();
371+
if (auto It = CDBToAbsPaths->find(FileName.str());
372+
It != CDBToAbsPaths->end())
373+
FileName = It->second;
374+
319375
const std::string &FinalCode = NameAndContent.second;
320376
if (auto Err = llvm::writeToOutput(
321377
FileName, [&](llvm::raw_ostream &OS) -> llvm::Error {

clang/docs/ReleaseNotes.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,19 @@ C++ Specific Potentially Breaking Changes
9999
// Was error, now evaluates to false.
100100
constexpr bool b = f() == g();
101101
102+
- Clang will now correctly not consider pointers to non classes for covariance.
103+
104+
.. code-block:: c++
105+
106+
struct A {
107+
virtual const int *f() const;
108+
};
109+
struct B : A {
110+
// Return type has less cv-qualification but doesn't point to a class.
111+
// Error will be generated.
112+
int *f() const override;
113+
};
114+
102115
- The warning ``-Wdeprecated-literal-operator`` is now on by default, as this is
103116
something that WG21 has shown interest in removing from the language. The
104117
result is that anyone who is compiling with ``-Werror`` should see this
@@ -605,6 +618,8 @@ Android Support
605618
Windows Support
606619
^^^^^^^^^^^^^^^
607620

621+
- clang-cl now supports ``/std:c++23preview`` which enables C++23 features.
622+
608623
- Clang no longer allows references inside a union when emulating MSVC 1900+ even if `fms-extensions` is enabled.
609624
Starting with VS2015, MSVC 1900, this Microsoft extension is no longer allowed and always results in an error.
610625
Clang now follows the MSVC behavior in this scenario.

0 commit comments

Comments
 (0)