Skip to content

Commit 1ef0c96

Browse files
committed
merge main into amd-staging
2 parents efc4ac5 + 6dba5f6 commit 1ef0c96

File tree

302 files changed

+65706
-66931
lines changed

Some content is hidden

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

302 files changed

+65706
-66931
lines changed

.ci/compute-projects.sh

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ function compute-projects-to-test() {
1818
shift
1919
projects=${@}
2020
for project in ${projects}; do
21+
echo "${project}"
2122
case ${project} in
2223
lld)
23-
for p in lld bolt cross-project-tests; do
24+
for p in bolt cross-project-tests; do
2425
echo $p
2526
done
2627
;;
2728
llvm)
28-
for p in llvm bolt clang clang-tools-extra lld lldb mlir polly; do
29+
for p in bolt clang clang-tools-extra lld lldb mlir polly; do
2930
echo $p
3031
done
3132
# Flang is not stable in Windows CI at the moment
@@ -35,30 +36,21 @@ function compute-projects-to-test() {
3536
;;
3637
clang)
3738
# lldb is temporarily removed to alleviate Linux pre-commit CI waiting times
38-
for p in clang clang-tools-extra compiler-rt cross-project-tests; do
39+
for p in clang-tools-extra compiler-rt cross-project-tests; do
3940
echo $p
4041
done
4142
;;
4243
clang-tools-extra)
43-
for p in clang-tools-extra libc; do
44-
echo $p
45-
done
44+
echo libc
4645
;;
4746
mlir)
48-
echo mlir
49-
# Flang is not stable in Windows CI at the moment
50-
if [[ $isForWindows == 0 ]]; then
51-
echo flang
52-
fi
53-
;;
54-
flang-rt)
5547
# Flang is not stable in Windows CI at the moment
5648
if [[ $isForWindows == 0 ]]; then
5749
echo flang
5850
fi
5951
;;
6052
*)
61-
echo "${project}"
53+
# Nothing to do
6254
;;
6355
esac
6456
done
@@ -73,11 +65,6 @@ function compute-runtimes-to-test() {
7365
echo $p
7466
done
7567
;;
76-
flang)
77-
for p in flang-rt; do
78-
echo $p
79-
done
80-
;;
8168
*)
8269
# Nothing to do
8370
;;

.ci/generate-buildkite-pipeline-premerge

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fi
7373
# needs while letting them run on the infrastructure provided by LLVM.
7474

7575
# Figure out which projects need to be built on each platform
76-
all_projects="bolt clang clang-tools-extra compiler-rt cross-project-tests flang flang-rt libc libclc lld lldb llvm mlir openmp polly pstl"
76+
all_projects="bolt clang clang-tools-extra compiler-rt cross-project-tests flang libc libclc lld lldb llvm mlir openmp polly pstl"
7777
modified_projects="$(keep-modified-projects ${all_projects})"
7878

7979
linux_projects_to_test=$(exclude-linux $(compute-projects-to-test 0 ${modified_projects}))

.ci/monolithic-linux.sh

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ cmake -S "${MONOREPO_ROOT}"/llvm -B "${BUILD_DIR}" \
6565
-D CMAKE_CXX_FLAGS=-gmlt \
6666
-D LLVM_CCACHE_BUILD=ON \
6767
-D MLIR_ENABLE_BINDINGS_PYTHON=ON \
68-
-D FLANG_ENABLE_FLANG_RT=OFF \
6968
-D CMAKE_INSTALL_PREFIX="${INSTALL_DIR}"
7069

7170
echo "--- ninja"
@@ -96,9 +95,6 @@ if [[ "${runtimes}" != "" ]]; then
9695
cmake -S "${MONOREPO_ROOT}/runtimes" -B "${RUNTIMES_BUILD_DIR}" -GNinja \
9796
-D CMAKE_C_COMPILER="${INSTALL_DIR}/bin/clang" \
9897
-D CMAKE_CXX_COMPILER="${INSTALL_DIR}/bin/clang++" \
99-
-D CMAKE_Fortran_COMPILER="${BUILD_DIR}/bin/flang" \
100-
-D CMAKE_Fortran_COMPILER_WORKS=ON \
101-
-D LLVM_BINARY_DIR="${BUILD_DIR}" \
10298
-D LLVM_ENABLE_RUNTIMES="${runtimes}" \
10399
-D LIBCXX_CXX_ABI=libcxxabi \
104100
-D CMAKE_BUILD_TYPE=RelWithDebInfo \
@@ -117,9 +113,6 @@ if [[ "${runtimes}" != "" ]]; then
117113
cmake -S "${MONOREPO_ROOT}/runtimes" -B "${RUNTIMES_BUILD_DIR}" -GNinja \
118114
-D CMAKE_C_COMPILER="${INSTALL_DIR}/bin/clang" \
119115
-D CMAKE_CXX_COMPILER="${INSTALL_DIR}/bin/clang++" \
120-
-D CMAKE_Fortran_COMPILER="${BUILD_DIR}/bin/flang" \
121-
-D CMAKE_Fortran_COMPILER_WORKS=ON \
122-
-D LLVM_BINARY_DIR="${BUILD_DIR}" \
123116
-D LLVM_ENABLE_RUNTIMES="${runtimes}" \
124117
-D LIBCXX_CXX_ABI=libcxxabi \
125118
-D CMAKE_BUILD_TYPE=RelWithDebInfo \
@@ -138,9 +131,6 @@ if [[ "${runtimes}" != "" ]]; then
138131
cmake -S "${MONOREPO_ROOT}/runtimes" -B "${RUNTIMES_BUILD_DIR}" -GNinja \
139132
-D CMAKE_C_COMPILER="${INSTALL_DIR}/bin/clang" \
140133
-D CMAKE_CXX_COMPILER="${INSTALL_DIR}/bin/clang++" \
141-
-D CMAKE_Fortran_COMPILER="${BUILD_DIR}/bin/flang" \
142-
-D CMAKE_Fortran_COMPILER_WORKS=ON \
143-
-D LLVM_BINARY_DIR="${BUILD_DIR}" \
144134
-D LLVM_ENABLE_RUNTIMES="${runtimes}" \
145135
-D LIBCXX_CXX_ABI=libcxxabi \
146136
-D CMAKE_BUILD_TYPE=RelWithDebInfo \

bolt/lib/Target/AArch64/AArch64MCSymbolizer.cpp

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,39 @@ AArch64MCSymbolizer::adjustRelocation(const Relocation &Rel,
125125
// instruction pairs and will perform necessary adjustments.
126126
ErrorOr<uint64_t> SymbolValue = BC.getSymbolValue(*Rel.Symbol);
127127
assert(SymbolValue && "Symbol value should be set");
128-
(void)SymbolValue;
129-
130-
AdjustedRel.Symbol = BC.registerNameAtAddress("__BOLT_got_zero", 0, 0, 0);
131-
AdjustedRel.Addend = Rel.Value;
128+
const uint64_t SymbolPageAddr = *SymbolValue & ~0xfffULL;
129+
130+
// Check if defined symbol and GOT are on the same page. If they are not,
131+
// disambiguate the operand.
132+
if (BC.MIB->isADRP(Inst) && Rel.Addend == 0 &&
133+
SymbolPageAddr == Rel.Value &&
134+
!isPageAddressValidForGOT(SymbolPageAddr)) {
135+
AdjustedRel.Type = ELF::R_AARCH64_ADR_PREL_PG_HI21;
136+
} else {
137+
AdjustedRel.Symbol = BC.registerNameAtAddress("__BOLT_got_zero", 0, 0, 0);
138+
AdjustedRel.Addend = Rel.Value;
139+
}
132140
}
133141

134142
return AdjustedRel;
135143
}
136144

145+
bool AArch64MCSymbolizer::isPageAddressValidForGOT(uint64_t PageAddress) const {
146+
assert(!(PageAddress & 0xfffULL) && "Page address not aligned at 4KB");
147+
148+
ErrorOr<BinarySection &> GOT =
149+
Function.getBinaryContext().getUniqueSectionByName(".got");
150+
if (!GOT || !GOT->getSize())
151+
return false;
152+
153+
const uint64_t GOTFirstPageAddress = GOT->getAddress() & ~0xfffULL;
154+
const uint64_t GOTLastPageAddress =
155+
(GOT->getAddress() + GOT->getSize() - 1) & ~0xfffULL;
156+
157+
return PageAddress >= GOTFirstPageAddress &&
158+
PageAddress <= GOTLastPageAddress;
159+
}
160+
137161
void AArch64MCSymbolizer::tryAddingPcLoadReferenceComment(raw_ostream &CStream,
138162
int64_t Value,
139163
uint64_t Address) {}

bolt/lib/Target/AArch64/AArch64MCSymbolizer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ class AArch64MCSymbolizer : public MCSymbolizer {
2828
std::optional<Relocation> adjustRelocation(const Relocation &Rel,
2929
const MCInst &Inst) const;
3030

31+
/// Return true if \p PageAddress is a valid page address for .got section.
32+
bool isPageAddressValidForGOT(uint64_t PageAddress) const;
33+
3134
public:
3235
AArch64MCSymbolizer(BinaryFunction &Function, bool CreateNewSymbols = true)
3336
: MCSymbolizer(*Function.getBinaryContext().Ctx.get(), nullptr),
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
## Check that BOLT symbolizer properly handles loads from GOT, including
2+
## instruction sequences changed/relaxed by the linker.
3+
4+
# RUN: split-file %s %t
5+
6+
# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %t/main.s \
7+
# RUN: -o %t/main.o
8+
# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %t/near.s \
9+
# RUN: -o %t/near.o
10+
# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %t/far.s \
11+
# RUN: -o %t/far.o
12+
# RUN: %clang %cflags %t/main.o %t/near.o %t/far.o -o %t/main.exe -Wl,-q -static
13+
# RUN: llvm-bolt %t/main.exe -o %t/main.bolt --keep-nops --print-disasm \
14+
# RUN: --print-only=_start | FileCheck %s
15+
16+
#--- main.s
17+
18+
.text
19+
.globl _start
20+
.p2align 2
21+
.type _start, @function
22+
# CHECK-LABEL: _start
23+
_start:
24+
25+
## Function address load relaxable into nop+adr.
26+
# CHECK: nop
27+
# CHECK-NEXT: adr x0, near
28+
adrp x0, :got:near
29+
ldr x0, [x0, :got_lo12:near]
30+
31+
## Function address load relaxable into adrp+add.
32+
# CHECK-NEXT: adrp x1, far
33+
# CHECK-NEXT: add x1, x1, :lo12:far
34+
adrp x1, :got:far
35+
ldr x1, [x1, :got_lo12:far]
36+
37+
## Non-relaxable due to the instruction in-between.
38+
# CHECK-NEXT: adrp x2, __BOLT_got_zero
39+
# CHECK-NEXT: nop
40+
# CHECK-NEXT: ldr x2, [x2, :lo12:__BOLT_got_zero{{.*}}]
41+
adrp x2, :got:near
42+
nop
43+
ldr x2, [x2, :got_lo12:near]
44+
45+
## Load data object with local visibility. Relaxable into adrp+add.
46+
# CHECK-NEXT: adrp x3, "local_far_data/1"
47+
# CHECK-NEXT: add x3, x3, :lo12:"local_far_data/1"
48+
adrp x3, :got:local_far_data
49+
ldr x3, [x3, :got_lo12:local_far_data]
50+
51+
## Global data reference relaxable into adrp+add.
52+
# CHECK-NEXT: adrp x4, far_data
53+
# CHECK-NEXT: add x4, x4, :lo12:far_data
54+
adrp x4, :got:far_data
55+
ldr x4, [x4, :got_lo12:far_data]
56+
57+
ret
58+
.size _start, .-_start
59+
60+
.weak near
61+
.weak far
62+
.weak far_data
63+
64+
## Data object separated by more than 1MB from _start.
65+
.data
66+
.type local_far_data, @object
67+
local_far_data:
68+
.xword 0
69+
.size local_far_data, .-local_far_data
70+
71+
#--- near.s
72+
73+
.text
74+
.globl near
75+
.type near, @function
76+
near:
77+
ret
78+
.size near, .-near
79+
80+
#--- far.s
81+
82+
.text
83+
84+
## Insert 1MB of empty space to make objects after it unreachable by adr
85+
## instructions in _start.
86+
.space 0x100000
87+
88+
.globl far
89+
.type far, @function
90+
far:
91+
ret
92+
.size far, .-far
93+
94+
.data
95+
.globl far_data
96+
.type far_data, @object
97+
far_data:
98+
.xword 0
99+
.size far_data, .-far_data
100+

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ Improvements to Clang's diagnostics
278278

279279
- Improve the diagnostics for shadows template parameter to report correct location (#GH129060).
280280

281+
- Improve the ``-Wundefined-func-template`` warning when a function template is not instantiated due to being unreachable in modules.
282+
281283
Improvements to Clang's time-trace
282284
----------------------------------
283285

@@ -340,6 +342,8 @@ Bug Fixes to C++ Support
340342
- Fixed an assertion failure affecting code that uses C++23 "deducing this". (#GH130272)
341343
- Clang now properly instantiates destructors for initialized members within non-delegating constructors. (#GH93251)
342344
- Correctly diagnoses if unresolved using declarations shadows template paramters (#GH129411)
345+
- Clang was previously coalescing volatile writes to members of volatile base class subobjects.
346+
The issue has been addressed by propagating qualifiers during derived-to-base conversions in the AST. (#GH127824)
343347

344348
Bug Fixes to AST Handling
345349
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/docs/analyzer/checkers.rst

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,42 @@ Do not attempt to create a std::string from a null pointer
543543
}
544544
}
545545
546+
.. _cplusplus-PureVirtualCall:
547+
548+
cplusplus.PureVirtualCall (C++)
549+
"""""""""""""""""""""""""""""""
550+
551+
When `virtual methods are called during construction and destruction
552+
<https://en.cppreference.com/w/cpp/language/virtual#During_construction_and_destruction>`__
553+
the polymorphism is restricted to the class that's being constructed or
554+
destructed because the more derived contexts are either not yet initialized or
555+
already destructed.
556+
557+
This checker reports situations where this restricted polymorphism causes a
558+
call to a pure virtual method, which is undefined behavior. (See also the
559+
related checker :ref:`optin-cplusplus-VirtualCall` which reports situations
560+
where the restricted polymorphism affects a call and the called method is not
561+
pure virtual – but may be still surprising for the programmer.)
562+
563+
.. code-block:: cpp
564+
565+
struct A {
566+
virtual int getKind() = 0;
567+
568+
A() {
569+
// warn: This calls the pure virtual method A::getKind().
570+
log << "Constructing " << getKind();
571+
}
572+
virtual ~A() {
573+
releaseResources();
574+
}
575+
void releaseResources() {
576+
// warn: This can call the pure virtual method A::getKind() when this is
577+
// called from the destructor.
578+
callSomeFunction(getKind())
579+
}
580+
};
581+
546582
.. _deadcode-checkers:
547583
548584
deadcode
@@ -833,24 +869,40 @@ This checker has several options which can be set from command line (e.g.
833869
834870
optin.cplusplus.VirtualCall (C++)
835871
"""""""""""""""""""""""""""""""""
836-
Check virtual function calls during construction or destruction.
872+
873+
When `virtual methods are called during construction and destruction
874+
<https://en.cppreference.com/w/cpp/language/virtual#During_construction_and_destruction>`__
875+
the polymorphism is restricted to the class that's being constructed or
876+
destructed because the more derived contexts are either not yet initialized or
877+
already destructed.
878+
879+
Although this behavior is well-defined, it can surprise the programmer and
880+
cause unintended behavior, so this checker reports calls that appear to be
881+
virtual calls but can be affected by this restricted polymorphism.
882+
883+
Note that situations where this restricted polymorphism causes a call to a pure
884+
virtual method (which is definitely invalid, triggers undefined behavior) are
885+
**reported by another checker:** :ref:`cplusplus-PureVirtualCall` and **this
886+
checker does not report them**.
837887
838888
.. code-block:: cpp
839889
840-
class A {
841-
public:
890+
struct A {
891+
virtual int getKind();
892+
842893
A() {
843-
f(); // warn
894+
// warn: This calls A::getKind() even if we are constructing an instance
895+
// of a different class that is derived from A.
896+
log << "Constructing " << getKind();
844897
}
845-
virtual void f();
846-
};
847-
848-
class A {
849-
public:
850-
~A() {
851-
this->f(); // warn
898+
virtual ~A() {
899+
releaseResources();
900+
}
901+
void releaseResources() {
902+
// warn: This can be called within ~A() and calls A::getKind() even if
903+
// we are destructing a class that is derived from A.
904+
callSomeFunction(getKind())
852905
}
853-
virtual void f();
854906
};
855907
856908
.. _optin-mpi-MPI-Checker:

clang/include/clang/Basic/DiagnosticFrontendKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def err_test_module_file_extension_version : Error<
266266
"(%3.%4)">;
267267

268268
def warn_eagerly_load_for_standard_cplusplus_modules : Warning<
269-
"the form '-fmodule-file=<BMI-path>' is deprecated for standard C++ named modules;"
269+
"the form '-fmodule-file=<BMI-path>' is deprecated for standard C++ named modules; "
270270
"consider to use '-fmodule-file=<module-name>=<BMI-path>' instead">,
271271
InGroup<DiagGroup<"eager-load-cxx-named-modules">>;
272272

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5700,6 +5700,8 @@ def warn_func_template_missing : Warning<"instantiation of function %q0 "
57005700
InGroup<UndefinedFuncTemplate>, DefaultIgnore;
57015701
def note_forward_template_decl : Note<
57025702
"forward declaration of template entity is here">;
5703+
def note_unreachable_template_decl
5704+
: Note<"unreachable declaration of template entity is here">;
57035705
def note_inst_declaration_hint : Note<"add an explicit instantiation "
57045706
"declaration to suppress this warning if %q0 is explicitly instantiated in "
57055707
"another translation unit">;

0 commit comments

Comments
 (0)