Skip to content

Commit 83e2a04

Browse files
authored
Merge branch 'main' into convert-ceil-op-assume-static-shaped-type
2 parents aff592e + cd4c30b commit 83e2a04

File tree

428 files changed

+17726
-8533
lines changed

Some content is hidden

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

428 files changed

+17726
-8533
lines changed

.github/workflows/release-binaries.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ jobs:
142142
# 2-3 hours to build on macOS, much slower than on Linux.
143143
# The long build time causes the release build to time out on x86_64,
144144
# so we need to disable flang there.
145-
target_cmake_flags="$target_cmake_flags -DLLVM_RELEASE_ENABLE_PROJECTS='clang;lld;lldb;clang-tools-extra;bolt;polly;mlir'"
145+
target_cmake_flags="$target_cmake_flags -DLLVM_RELEASE_ENABLE_PROJECTS='clang;lld;lldb;clang-tools-extra;polly;mlir'"
146146
fi
147147
target_cmake_flags="$target_cmake_flags -DBOOTSTRAP_BOOTSTRAP_DARWIN_osx_ARCHS=$arches -DBOOTSTRAP_BOOTSTRAP_DARWIN_osx_BUILTIN_ARCHS=$arches"
148148
fi

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "bolt/Core/DynoStats.h"
1616
#include "bolt/Core/HashUtilities.h"
1717
#include "bolt/Core/MCPlusBuilder.h"
18+
#include "bolt/Utils/CommandLineOpts.h"
1819
#include "bolt/Utils/NameResolver.h"
1920
#include "bolt/Utils/NameShortener.h"
2021
#include "bolt/Utils/Utils.h"
@@ -1753,8 +1754,8 @@ void BinaryFunction::postProcessEntryPoints() {
17531754
// In non-relocation mode there's potentially an external undetectable
17541755
// reference to the entry point and hence we cannot move this entry
17551756
// point. Optimizing without moving could be difficult.
1756-
// In BAT mode, register any known entry points for CFG construction.
1757-
if (!BC.HasRelocations && !BC.HasBATSection)
1757+
// In aggregation, register any known entry points for CFG construction.
1758+
if (!BC.HasRelocations && !opts::AggregateOnly)
17581759
setSimple(false);
17591760

17601761
const uint32_t Offset = KV.first;

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,9 +831,10 @@ bool DataAggregator::doTrace(const LBREntry &First, const LBREntry &Second,
831831
ParentFunc = FromFunc;
832832
ParentFunc->SampleCountInBytes += Count * (Second.From - First.To);
833833

834+
const uint64_t FuncAddress = FromFunc->getAddress();
834835
std::optional<BoltAddressTranslation::FallthroughListTy> FTs =
835-
BAT ? BAT->getFallthroughsInTrace(FromFunc->getAddress(), First.To,
836-
Second.From)
836+
BAT && BAT->isBATFunction(FuncAddress)
837+
? BAT->getFallthroughsInTrace(FuncAddress, First.To, Second.From)
837838
: getFallthroughsInTrace(*FromFunc, First, Second, Count);
838839
if (!FTs) {
839840
LLVM_DEBUG(

bolt/test/X86/bolt-address-translation-yaml.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ YAML-BAT-CHECK-NEXT: - bid: 0
6161
YAML-BAT-CHECK-NEXT: insns: 26
6262
YAML-BAT-CHECK-NEXT: hash: 0xA900AE79CFD40000
6363
YAML-BAT-CHECK-NEXT: succ: [ { bid: 3, cnt: 0 }, { bid: 1, cnt: 0 } ]
64+
# Check fallthroughs in non-BAT function
65+
YAML-BAT-CHECK-NEXT: - bid: 27
66+
YAML-BAT-CHECK-NEXT: insns: 3
67+
YAML-BAT-CHECK-NEXT: hash: 0x30A1EBA77A903F0
68+
YAML-BAT-CHECK-NEXT: succ: [ { bid: 28, cnt: 1 } ]
6469
# Calls from no-BAT to BAT function
6570
YAML-BAT-CHECK: - bid: 28
6671
YAML-BAT-CHECK-NEXT: insns: 13
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
## Checks that fallthroughs spanning entry points are accepted in aggregation
2+
## mode.
3+
4+
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o
5+
# RUN: ld.lld %t.o -o %t
6+
# RUN: link_fdata %s %t %t.preagg PREAGG
7+
# RUN: perf2bolt %t -p %t.preagg --pa -o %t.fdata | FileCheck %s
8+
# CHECK: traces mismatching disassembled function contents: 0
9+
10+
.globl main
11+
main:
12+
.cfi_startproc
13+
vmovaps %zmm31,%zmm3
14+
15+
next:
16+
add $0x4,%r9
17+
add $0x40,%r10
18+
dec %r14
19+
Ljmp:
20+
jne main
21+
# PREAGG: T #Ljmp# #main# #Ljmp# 1
22+
ret
23+
.cfi_endproc
24+
.size main,.-main

clang/Maintainers.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ Clang static analyzer
136136
137137
| Balázs Benics
138138
| benicsbalazs\@gmail.com (email), steakhal (Phabricator), steakhal (GitHub)
139+
| balazs.benics\@sonarsource.com (email), balazs-benics-sonarsource (GitHub)
139140
140141
Compiler options
141142
~~~~~~~~~~~~~~~~

clang/cmake/caches/Release.cmake

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,21 @@ endfunction()
2929
# cache file to CMake via -C. e.g.
3030
#
3131
# cmake -D LLVM_RELEASE_ENABLE_PGO=ON -C Release.cmake
32+
33+
set (DEFAULT_PROJECTS "clang;lld;lldb;clang-tools-extra;polly;mlir;flang")
34+
# bolt only supports ELF, so only enable it for Linux.
35+
if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux")
36+
list(APPEND DEFAULT_PROJECTS "bolt")
37+
endif()
38+
3239
set (DEFAULT_RUNTIMES "compiler-rt;libcxx")
3340
if (NOT WIN32)
3441
list(APPEND DEFAULT_RUNTIMES "libcxxabi" "libunwind")
3542
endif()
3643
set(LLVM_RELEASE_ENABLE_LTO THIN CACHE STRING "")
3744
set(LLVM_RELEASE_ENABLE_PGO ON CACHE BOOL "")
3845
set(LLVM_RELEASE_ENABLE_RUNTIMES ${DEFAULT_RUNTIMES} CACHE STRING "")
39-
set(LLVM_RELEASE_ENABLE_PROJECTS "clang;lld;lldb;clang-tools-extra;bolt;polly;mlir;flang" CACHE STRING "")
46+
set(LLVM_RELEASE_ENABLE_PROJECTS ${DEFAULT_PROJECTS} CACHE STRING "")
4047
# Note we don't need to add install here, since it is one of the pre-defined
4148
# steps.
4249
set(LLVM_RELEASE_FINAL_STAGE_TARGETS "clang;package;check-all;check-llvm;check-clang" CACHE STRING "")
@@ -118,16 +125,22 @@ if(NOT ${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin")
118125
set(RELEASE_LINKER_FLAGS "${RELEASE_LINKER_FLAGS} -static-libgcc")
119126
endif()
120127

128+
# Set flags for bolt
129+
if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux")
130+
set(RELEASE_LINKER_FLAGS "${RELEASE_LINKER_FLAGS} -Wl,--emit-relocs,-znow")
131+
endif()
132+
121133
set_instrument_and_final_stage_var(CMAKE_EXE_LINKER_FLAGS ${RELEASE_LINKER_FLAGS} STRING)
122134
set_instrument_and_final_stage_var(CMAKE_SHARED_LINKER_FLAGS ${RELEASE_LINKER_FLAGS} STRING)
123135
set_instrument_and_final_stage_var(CMAKE_MODULE_LINKER_FLAGS ${RELEASE_LINKER_FLAGS} STRING)
124136

125137
# Final Stage Config (stage2)
126138
set_final_stage_var(LLVM_ENABLE_RUNTIMES "${LLVM_RELEASE_ENABLE_RUNTIMES}" STRING)
127139
set_final_stage_var(LLVM_ENABLE_PROJECTS "${LLVM_RELEASE_ENABLE_PROJECTS}" STRING)
140+
if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux")
141+
set_final_stage_var(CLANG_BOLT "INSTRUMENT" STRING)
142+
endif()
128143
set_final_stage_var(CPACK_GENERATOR "TXZ" STRING)
129144
set_final_stage_var(CPACK_ARCHIVE_THREADS "0" STRING)
130145

131-
if(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin")
132-
set_final_stage_var(LLVM_USE_STATIC_ZSTD "ON" BOOL)
133-
endif()
146+
set_final_stage_var(LLVM_USE_STATIC_ZSTD "ON" BOOL)

clang/docs/ReleaseNotes.rst

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ Removed Compiler Flags
124124

125125
Attribute Changes in Clang
126126
--------------------------
127+
Adding [[clang::unsafe_buffer_usage]] attribute to a method definition now turns off all -Wunsafe-buffer-usage
128+
related warnings within the method body.
127129

128130
- The ``no_sanitize`` attribute now accepts both ``gnu`` and ``clang`` names.
129131
- Clang now diagnoses use of declaration attributes on void parameters. (#GH108819)
@@ -132,6 +134,50 @@ Attribute Changes in Clang
132134
This forces the global to be considered small or large in regards to the
133135
x86-64 code model, regardless of the code model specified for the compilation.
134136

137+
- There is a new ``format_matches`` attribute to complement the existing
138+
``format`` attribute. ``format_matches`` allows the compiler to verify that
139+
a format string argument is equivalent to a reference format string: it is
140+
useful when a function accepts a format string without its accompanying
141+
arguments to format. For instance:
142+
143+
.. code-block:: c
144+
145+
static int status_code;
146+
static const char *status_string;
147+
148+
void print_status(const char *fmt) {
149+
fprintf(stderr, fmt, status_code, status_string);
150+
// ^ warning: format string is not a string literal [-Wformat-nonliteral]
151+
}
152+
153+
void stuff(void) {
154+
print_status("%s (%#08x)\n");
155+
// order of %s and %x is swapped but there is no diagnostic
156+
}
157+
158+
Before the introducion of ``format_matches``, this code cannot be verified
159+
at compile-time. ``format_matches`` plugs that hole:
160+
161+
.. code-block:: c
162+
163+
__attribute__((format_matches(printf, 1, "%x %s")))
164+
void print_status(const char *fmt) {
165+
fprintf(stderr, fmt, status_code, status_string);
166+
// ^ `fmt` verified as if it was "%x %s" here; no longer triggers
167+
// -Wformat-nonliteral, would warn if arguments did not match "%x %s"
168+
}
169+
170+
void stuff(void) {
171+
print_status("%s (%#08x)\n");
172+
// warning: format specifier 's' is incompatible with 'x'
173+
// warning: format specifier 'x' is incompatible with 's'
174+
}
175+
176+
Like with ``format``, the first argument is the format string flavor and the
177+
second argument is the index of the format string parameter.
178+
``format_matches`` accepts an example valid format string as its third
179+
argument. For more information, see the Clang attributes documentation.
180+
135181
Improvements to Clang's diagnostics
136182
-----------------------------------
137183

clang/include/clang/AST/FormatString.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ class ArgType {
292292
};
293293

294294
private:
295-
const Kind K;
295+
Kind K;
296296
QualType T;
297297
const char *Name = nullptr;
298298
bool Ptr = false;
@@ -338,6 +338,7 @@ class ArgType {
338338
}
339339

340340
MatchKind matchesType(ASTContext &C, QualType argTy) const;
341+
MatchKind matchesArgType(ASTContext &C, const ArgType &other) const;
341342

342343
QualType getRepresentativeType(ASTContext &C) const;
343344

clang/include/clang/Basic/Attr.td

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,6 +1834,16 @@ def Format : InheritableAttr {
18341834
let Documentation = [FormatDocs];
18351835
}
18361836

1837+
def FormatMatches : InheritableAttr {
1838+
let Spellings = [GCC<"format_matches">];
1839+
let Args = [IdentifierArgument<"Type">, IntArgument<"FormatIdx">, ExprArgument<"ExpectedFormat">];
1840+
let AdditionalMembers = [{
1841+
StringLiteral *getFormatString() const;
1842+
}];
1843+
let Subjects = SubjectList<[ObjCMethod, Block, HasFunctionProto]>;
1844+
let Documentation = [FormatMatchesDocs];
1845+
}
1846+
18371847
def FormatArg : InheritableAttr {
18381848
let Spellings = [GCC<"format_arg">];
18391849
let Args = [ParamIdxArgument<"FormatIdx">];

0 commit comments

Comments
 (0)