Skip to content

Commit d0757f4

Browse files
Merge branch 'main' into users/minglotus-6/typeprofrawformat
2 parents c74bde7 + 300425c commit d0757f4

File tree

157 files changed

+4137
-5066
lines changed

Some content is hidden

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

157 files changed

+4137
-5066
lines changed

bolt/include/bolt/Core/BinarySection.h

+13-7
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,7 @@ class BinarySection {
139139
Alignment = NewAlignment;
140140
ELFType = NewELFType;
141141
ELFFlags = NewELFFlags;
142-
OutputSize = NewSize;
143-
OutputContents = StringRef(reinterpret_cast<const char *>(NewData),
144-
NewData ? NewSize : 0);
145-
IsFinalized = true;
142+
updateContents(NewData, NewSize);
146143
}
147144

148145
public:
@@ -484,9 +481,18 @@ class BinarySection {
484481
void flushPendingRelocations(raw_pwrite_stream &OS,
485482
SymbolResolverFuncTy Resolver);
486483

487-
/// Change contents of the section.
488-
void updateContents(const uint8_t *Data, size_t NewSize) {
489-
OutputContents = StringRef(reinterpret_cast<const char *>(Data), NewSize);
484+
/// Change contents of the section. Unless the section has a valid SectionID,
485+
/// the memory passed in \p NewData will be managed by the instance of
486+
/// BinarySection.
487+
void updateContents(const uint8_t *NewData, size_t NewSize) {
488+
if (getOutputData() && !hasValidSectionID() &&
489+
(!hasSectionRef() ||
490+
OutputContents.data() != getContentsOrQuit(Section).data())) {
491+
delete[] getOutputData();
492+
}
493+
494+
OutputContents = StringRef(reinterpret_cast<const char *>(NewData),
495+
NewData ? NewSize : 0);
490496
OutputSize = NewSize;
491497
IsFinalized = true;
492498
}

bolt/lib/Core/BinarySection.cpp

+1-12
Original file line numberDiff line numberDiff line change
@@ -190,18 +190,7 @@ void BinarySection::flushPendingRelocations(raw_pwrite_stream &OS,
190190
clearList(PendingRelocations);
191191
}
192192

193-
BinarySection::~BinarySection() {
194-
if (isReordered()) {
195-
delete[] getData();
196-
return;
197-
}
198-
199-
if (!isAllocatable() && !hasValidSectionID() &&
200-
(!hasSectionRef() ||
201-
OutputContents.data() != getContentsOrQuit(Section).data())) {
202-
delete[] getOutputData();
203-
}
204-
}
193+
BinarySection::~BinarySection() { updateContents(nullptr, 0); }
205194

206195
void BinarySection::clearRelocations() { clearList(Relocations); }
207196

bolt/lib/Rewrite/RewriteInstance.cpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -4092,12 +4092,9 @@ void RewriteInstance::rewriteNoteSections() {
40924092
return getNewValueForSymbol(S->getName());
40934093
});
40944094

4095-
// Set/modify section info.
4096-
BinarySection &NewSection = BC->registerOrUpdateNoteSection(
4097-
SectionName, SectionData, Size, Section.sh_addralign,
4098-
!BSec->isWritable(), BSec->getELFType());
4099-
NewSection.setOutputAddress(0);
4100-
NewSection.setOutputFileOffset(NextAvailableOffset);
4095+
// Section contents are no longer needed, but we need to update the size so
4096+
// that it will be reflected in the section header table.
4097+
BSec->updateContents(nullptr, Size);
41014098

41024099
NextAvailableOffset += Size;
41034100
}

bolt/unittests/Core/BinaryContext.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,11 @@ TEST_P(BinaryContextTester, FlushPendingRelocCALL26) {
7777
// 12: bl func2
7878
// 16: func2
7979

80-
char Data[20] = {};
80+
constexpr size_t DataSize = 20;
81+
uint8_t *Data = new uint8_t[DataSize];
8182
BinarySection &BS = BC->registerOrUpdateSection(
82-
".text", ELF::SHT_PROGBITS, ELF::SHF_EXECINSTR | ELF::SHF_ALLOC,
83-
(uint8_t *)Data, sizeof(Data), 4);
83+
".text", ELF::SHT_PROGBITS, ELF::SHF_EXECINSTR | ELF::SHF_ALLOC, Data,
84+
DataSize, 4);
8485
MCSymbol *RelSymbol1 = BC->getOrCreateGlobalSymbol(4, "Func1");
8586
ASSERT_TRUE(RelSymbol1);
8687
BS.addRelocation(8, RelSymbol1, ELF::R_AARCH64_CALL26, 0, 0, true);
@@ -89,7 +90,7 @@ TEST_P(BinaryContextTester, FlushPendingRelocCALL26) {
8990
BS.addRelocation(12, RelSymbol2, ELF::R_AARCH64_CALL26, 0, 0, true);
9091

9192
std::error_code EC;
92-
SmallVector<char> Vect(sizeof(Data));
93+
SmallVector<char> Vect(DataSize);
9394
raw_svector_ostream OS(Vect);
9495

9596
BS.flushPendingRelocations(OS, [&](const MCSymbol *S) {

clang/docs/ReleaseNotes.rst

+12-26
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,6 @@ Clang Frontend Potentially Breaking Changes
6262
of ``-Wno-gnu-binary-literal`` will no longer silence this pedantic warning,
6363
which may break existing uses with ``-Werror``.
6464

65-
Target OS macros extension
66-
^^^^^^^^^^^^^^^^^^^^^^^^^^
67-
A new Clang extension (see :ref:`here <target_os_detail>`) is enabled for
68-
Darwin (Apple platform) targets. Clang now defines ``TARGET_OS_*`` macros for
69-
these targets, which could break existing code bases with improper checks for
70-
the ``TARGET_OS_`` macros. For example, existing checks might fail to include
71-
the ``TargetConditionals.h`` header from Apple SDKs and therefore leaving the
72-
macros undefined and guarded code unexercised.
73-
74-
Affected code should be checked to see if it's still intended for the specific
75-
target and fixed accordingly.
76-
77-
The extension can be turned off by the option ``-fno-define-target-os-macros``
78-
as a workaround.
79-
8065
What's New in Clang |release|?
8166
==============================
8267
Some of the major new features and improvements to Clang are listed
@@ -161,17 +146,6 @@ Non-comprehensive list of changes in this release
161146
New Compiler Flags
162147
------------------
163148

164-
.. _target_os_detail:
165-
166-
Target OS macros extension
167-
^^^^^^^^^^^^^^^^^^^^^^^^^^
168-
A pair of new flags ``-fdefine-target-os-macros`` and
169-
``-fno-define-target-os-macros`` has been added to Clang to enable/disable the
170-
extension to provide built-in definitions of a list of ``TARGET_OS_*`` macros
171-
based on the target triple.
172-
173-
The extension is enabled by default for Darwin (Apple platform) targets.
174-
175149
Deprecated Compiler Flags
176150
-------------------------
177151

@@ -297,6 +271,10 @@ Bug Fixes to C++ Support
297271
was only accepted at namespace scope but not at local function scope.
298272
- Clang no longer tries to call consteval constructors at runtime when they appear in a member initializer.
299273
(`#782154 <https://github.com/llvm/llvm-project/issues/82154>`_`)
274+
- Fix crash when using an immediate-escalated function at global scope.
275+
(`#82258 <https://github.com/llvm/llvm-project/issues/82258>`_)
276+
- Correctly immediate-escalate lambda conversion functions.
277+
(`#82258 <https://github.com/llvm/llvm-project/issues/82258>`_)
300278

301279
Bug Fixes to AST Handling
302280
^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -404,6 +382,14 @@ Moved checkers
404382
Sanitizers
405383
----------
406384

385+
- ``-fsanitize=signed-integer-overflow`` now instruments signed arithmetic even
386+
when ``-fwrapv`` is enabled. Previously, only division checks were enabled.
387+
388+
Users with ``-fwrapv`` as well as a sanitizer group like
389+
``-fsanitize=undefined`` or ``-fsanitize=integer`` enabled may want to
390+
manually disable potentially noisy signed integer overflow checks with
391+
``-fno-sanitize=signed-integer-overflow``
392+
407393
Python Binding Changes
408394
----------------------
409395

clang/docs/UndefinedBehaviorSanitizer.rst

+5-4
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,11 @@ Available checks are:
190190
- ``-fsanitize=signed-integer-overflow``: Signed integer overflow, where the
191191
result of a signed integer computation cannot be represented in its type.
192192
This includes all the checks covered by ``-ftrapv``, as well as checks for
193-
signed division overflow (``INT_MIN/-1``), but not checks for
194-
lossy implicit conversions performed before the computation
195-
(see ``-fsanitize=implicit-conversion``). Both of these two issues are
196-
handled by ``-fsanitize=implicit-conversion`` group of checks.
193+
signed division overflow (``INT_MIN/-1``). Note that checks are still
194+
added even when ``-fwrapv`` is enabled. This sanitizer does not check for
195+
lossy implicit conversions performed before the computation (see
196+
``-fsanitize=implicit-conversion``). Both of these two issues are handled
197+
by ``-fsanitize=implicit-conversion`` group of checks.
197198
- ``-fsanitize=unreachable``: If control flow reaches an unreachable
198199
program point.
199200
- ``-fsanitize=unsigned-integer-overflow``: Unsigned integer overflow, where

clang/include/clang/InstallAPI/Context.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct InstallAPIContext {
2828
llvm::Triple TargetTriple{};
2929

3030
/// File Path of output location.
31-
StringRef OutputLoc{};
31+
llvm::StringRef OutputLoc{};
3232

3333
/// What encoding to write output as.
3434
llvm::MachO::FileType FT = llvm::MachO::FileType::TBD_V5;

clang/include/clang/InstallAPI/HeaderFile.h

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
namespace clang::installapi {
2323
enum class HeaderType {
24+
/// Unset or unknown type.
25+
Unknown,
2426
/// Represents declarations accessible to all clients.
2527
Public,
2628
/// Represents declarations accessible to a disclosed set of clients.
@@ -41,6 +43,7 @@ class HeaderFile {
4143
std::optional<clang::Language> Language;
4244

4345
public:
46+
HeaderFile() = delete;
4447
HeaderFile(StringRef FullPath, HeaderType Type,
4548
StringRef IncludeName = StringRef(),
4649
std::optional<clang::Language> Language = std::nullopt)

clang/include/clang/Sema/Sema.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,9 @@ class Sema final {
11581158
if (FD) {
11591159
FD->setWillHaveBody(true);
11601160
S.ExprEvalContexts.back().InImmediateFunctionContext =
1161-
FD->isImmediateFunction();
1161+
FD->isImmediateFunction() ||
1162+
S.ExprEvalContexts[S.ExprEvalContexts.size() - 2]
1163+
.isConstantEvaluated();
11621164
S.ExprEvalContexts.back().InImmediateEscalatingFunctionContext =
11631165
S.getLangOpts().CPlusPlus20 && FD->isImmediateEscalating();
11641166
} else

clang/lib/CodeGen/CGExprScalar.cpp

+12-4
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,9 @@ class ScalarExprEmitter
723723
if (Ops.Ty->isSignedIntegerOrEnumerationType()) {
724724
switch (CGF.getLangOpts().getSignedOverflowBehavior()) {
725725
case LangOptions::SOB_Defined:
726-
return Builder.CreateMul(Ops.LHS, Ops.RHS, "mul");
726+
if (!CGF.SanOpts.has(SanitizerKind::SignedIntegerOverflow))
727+
return Builder.CreateMul(Ops.LHS, Ops.RHS, "mul");
728+
[[fallthrough]];
727729
case LangOptions::SOB_Undefined:
728730
if (!CGF.SanOpts.has(SanitizerKind::SignedIntegerOverflow))
729731
return Builder.CreateNSWMul(Ops.LHS, Ops.RHS, "mul");
@@ -2568,7 +2570,9 @@ llvm::Value *ScalarExprEmitter::EmitIncDecConsiderOverflowBehavior(
25682570
StringRef Name = IsInc ? "inc" : "dec";
25692571
switch (CGF.getLangOpts().getSignedOverflowBehavior()) {
25702572
case LangOptions::SOB_Defined:
2571-
return Builder.CreateAdd(InVal, Amount, Name);
2573+
if (!CGF.SanOpts.has(SanitizerKind::SignedIntegerOverflow))
2574+
return Builder.CreateAdd(InVal, Amount, Name);
2575+
[[fallthrough]];
25722576
case LangOptions::SOB_Undefined:
25732577
if (!CGF.SanOpts.has(SanitizerKind::SignedIntegerOverflow))
25742578
return Builder.CreateNSWAdd(InVal, Amount, Name);
@@ -3913,7 +3917,9 @@ Value *ScalarExprEmitter::EmitAdd(const BinOpInfo &op) {
39133917
if (op.Ty->isSignedIntegerOrEnumerationType()) {
39143918
switch (CGF.getLangOpts().getSignedOverflowBehavior()) {
39153919
case LangOptions::SOB_Defined:
3916-
return Builder.CreateAdd(op.LHS, op.RHS, "add");
3920+
if (!CGF.SanOpts.has(SanitizerKind::SignedIntegerOverflow))
3921+
return Builder.CreateAdd(op.LHS, op.RHS, "add");
3922+
[[fallthrough]];
39173923
case LangOptions::SOB_Undefined:
39183924
if (!CGF.SanOpts.has(SanitizerKind::SignedIntegerOverflow))
39193925
return Builder.CreateNSWAdd(op.LHS, op.RHS, "add");
@@ -4067,7 +4073,9 @@ Value *ScalarExprEmitter::EmitSub(const BinOpInfo &op) {
40674073
if (op.Ty->isSignedIntegerOrEnumerationType()) {
40684074
switch (CGF.getLangOpts().getSignedOverflowBehavior()) {
40694075
case LangOptions::SOB_Defined:
4070-
return Builder.CreateSub(op.LHS, op.RHS, "sub");
4076+
if (!CGF.SanOpts.has(SanitizerKind::SignedIntegerOverflow))
4077+
return Builder.CreateSub(op.LHS, op.RHS, "sub");
4078+
[[fallthrough]];
40714079
case LangOptions::SOB_Undefined:
40724080
if (!CGF.SanOpts.has(SanitizerKind::SignedIntegerOverflow))
40734081
return Builder.CreateNSWSub(op.LHS, op.RHS, "sub");

clang/lib/InstallAPI/FileList.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ InstallAPI JSON Input Format specification.
2222
{
2323
"headers" : [ # Required: Key must exist.
2424
{ # Optional: May contain 0 or more header inputs.
25-
"path" : "/usr/include/mach-o/dlfn.h", # Required: Path should point to destination
25+
"path" : "/usr/include/mach-o/dlfn.h", # Required: Path should point to destination
2626
# location where applicable.
2727
"type" : "public", # Required: Maps to HeaderType for header.
2828
"language": "c++" # Optional: Language mode for header.
2929
}
3030
],
31-
"version" : "3" # Required: Version 3 supports language mode
31+
"version" : "3" # Required: Version 3 supports language mode
3232
& project header input.
3333
}
3434
*/

clang/lib/Sema/SemaExpr.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -18311,7 +18311,6 @@ void Sema::CheckUnusedVolatileAssignment(Expr *E) {
1831118311
}
1831218312

1831318313
void Sema::MarkExpressionAsImmediateEscalating(Expr *E) {
18314-
assert(!FunctionScopes.empty() && "Expected a function scope");
1831518314
assert(getLangOpts().CPlusPlus20 &&
1831618315
ExprEvalContexts.back().InImmediateEscalatingFunctionContext &&
1831718316
"Cannot mark an immediate escalating expression outside of an "
@@ -18328,7 +18327,8 @@ void Sema::MarkExpressionAsImmediateEscalating(Expr *E) {
1832818327
} else {
1832918328
assert(false && "expected an immediately escalating expression");
1833018329
}
18331-
getCurFunction()->FoundImmediateEscalatingExpression = true;
18330+
if (FunctionScopeInfo *FI = getCurFunction())
18331+
FI->FoundImmediateEscalatingExpression = true;
1833218332
}
1833318333

1833418334
ExprResult Sema::CheckForImmediateInvocation(ExprResult E, FunctionDecl *Decl) {

clang/test/CodeGen/integer-overflow.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - | FileCheck %s --check-prefix=DEFAULT
22
// RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - -fwrapv | FileCheck %s --check-prefix=WRAPV
33
// RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - -ftrapv | FileCheck %s --check-prefix=TRAPV
4-
// RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - -fsanitize=signed-integer-overflow | FileCheck %s --check-prefix=CATCH_UB
4+
// RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - -fsanitize=signed-integer-overflow | FileCheck %s --check-prefixes=CATCH_UB,CATCH_UB_POINTER
5+
// RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - -fsanitize=signed-integer-overflow -fwrapv | FileCheck %s --check-prefixes=CATCH_UB,NOCATCH_UB_POINTER
56
// RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - -ftrapv -ftrapv-handler foo | FileCheck %s --check-prefix=TRAPV_HANDLER
67

78

@@ -62,7 +63,8 @@ void test1(void) {
6263
// DEFAULT: getelementptr inbounds i32, ptr
6364
// WRAPV: getelementptr i32, ptr
6465
// TRAPV: getelementptr inbounds i32, ptr
65-
// CATCH_UB: getelementptr inbounds i32, ptr
66+
// CATCH_UB_POINTER: getelementptr inbounds i32, ptr
67+
// NOCATCH_UB_POINTER: getelementptr i32, ptr
6668

6769
// PR9350: char pre-increment never overflows.
6870
extern volatile signed char PR9350_char_inc;

clang/test/SemaCXX/cxx2b-consteval-propagate.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -368,3 +368,29 @@ vector<void> v{};
368368
// expected-note@-2 {{in call to 'vector()'}}
369369

370370
}
371+
372+
373+
namespace GH82258 {
374+
375+
template <class R, class Pred>
376+
constexpr auto none_of(R&& r, Pred pred) -> bool { return true; }
377+
378+
struct info { int value; };
379+
consteval auto is_invalid(info i) -> bool { return false; }
380+
constexpr info types[] = { {1}, {3}, {5}};
381+
382+
static_assert(none_of(
383+
types,
384+
+[](info i) consteval {
385+
return is_invalid(i);
386+
}
387+
));
388+
389+
static_assert(none_of(
390+
types,
391+
[]{
392+
return is_invalid;
393+
}()
394+
));
395+
396+
}

clang/tools/clang-installapi/Options.cpp

+4-10
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,7 @@ namespace installapi {
2222

2323
bool Options::processDriverOptions(InputArgList &Args) {
2424
// Handle inputs.
25-
llvm::vfs::Status Stat;
26-
for (const auto &Path : Args.getAllArgValues(OPT_INPUT)) {
27-
if (FM->getNoncachedStatValue(Path, Stat) || !Stat.exists()) {
28-
Diags->Report(clang::diag::err_drv_no_such_file) << Path;
29-
return false;
30-
}
31-
DriverOpts.FileLists.push_back(std::move(Path));
32-
}
25+
llvm::append_range(DriverOpts.FileLists, Args.getAllArgValues(OPT_INPUT));
3326

3427
// Handle output.
3528
SmallString<PATH_MAX> OutputPath;
@@ -61,8 +54,9 @@ bool Options::processDriverOptions(InputArgList &Args) {
6154

6255
// Capture target triples first.
6356
if (ArgTarget) {
64-
for (auto *Arg : Args.filtered(OPT_target)) {
65-
llvm::Triple TargetTriple(Arg->getValue());
57+
for (const Arg *A : Args.filtered(OPT_target)) {
58+
A->claim();
59+
llvm::Triple TargetTriple(A->getValue());
6660
Target TAPITarget = Target(TargetTriple);
6761
if ((TAPITarget.Arch == AK_unknown) ||
6862
(TAPITarget.Platform == PLATFORM_UNKNOWN)) {

compiler-rt/lib/builtins/divtc3.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#define QUAD_PRECISION
1414
#include "fp_lib.h"
1515

16-
#if defined(CRT_HAS_TF_MODE)
16+
#if defined(CRT_HAS_F128)
1717

1818
// Returns: the quotient of (a + ib) / (c + id)
1919

0 commit comments

Comments
 (0)