Skip to content

Commit 79912c6

Browse files
committed
Merge from 'main' to 'sycl-web' (167 commits)
CONFLICT (content): Merge conflict in clang/include/clang/Basic/DiagnosticGroups.td CONFLICT (content): Merge conflict in clang/lib/Frontend/InitPreprocessor.cpp
2 parents 36bb6f0 + ff219ea commit 79912c6

File tree

586 files changed

+22724
-7959
lines changed

Some content is hidden

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

586 files changed

+22724
-7959
lines changed
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
# This file defines pre-commit CI for libc++, libc++abi, and libunwind (on Github).
2+
#
3+
# We split the configurations in multiple stages with the intent of saving compute time
4+
# when a job fails early in the pipeline. This is why the jobs are marked as `continue-on-error: false`.
5+
# We try to run the CI configurations with the most signal in the first stage.
6+
#
7+
# Stages 1 & 2 are meant to be "smoke tests", and are meant to catch most build/test failures quickly and without using
8+
# too many resources.
9+
# Stage 3 is "everything else", and is meant to catch breakages on more niche or unique configurations.
10+
#
11+
# Therefore, we "fail-fast" for any failures during stages 1 & 2, meaning any job failing cancels all other running jobs,
12+
# under the assumption that if the "smoke tests" fail, then the other configurations will likely fail in the same way.
13+
# However, stage 3 does not fail fast, as it's more likely that any one job failing is a flake or a configuration-specific
14+
#
15+
name: Build and Test libc++
16+
on:
17+
pull_request:
18+
paths:
19+
- 'libcxx/**'
20+
- 'libcxxabi/**'
21+
- 'libunwind/**'
22+
- 'runtimes/**'
23+
- 'cmake/**'
24+
- '.github/workflows/libcxx-build-and-test.yaml'
25+
26+
concurrency:
27+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
28+
cancel-in-progress: true
29+
30+
31+
env:
32+
CMAKE: "/opt/bin/cmake"
33+
# LLVM POST-BRANCH bump version
34+
# LLVM POST-BRANCH add compiler test for ToT - 1, e.g. "Clang 17"
35+
# LLVM RELEASE bump remove compiler ToT - 3, e.g. "Clang 15"
36+
LLVM_HEAD_VERSION: "18" # Used compiler, update POST-BRANCH.
37+
LLVM_PREVIOUS_VERSION: "17"
38+
LLVM_OLDEST_VERSION: "16"
39+
GCC_STABLE_VERSION: "13"
40+
LLVM_SYMBOLIZER_PATH: "/usr/bin/llvm-symbolizer-18"
41+
CLANG_CRASH_DIAGNOSTICS_DIR: "crash_diagnostics"
42+
43+
44+
jobs:
45+
stage1:
46+
runs-on: libcxx-runners-16
47+
continue-on-error: false
48+
strategy:
49+
fail-fast: true
50+
matrix:
51+
config: [
52+
'generic-cxx03',
53+
'generic-cxx26',
54+
'generic-modules'
55+
]
56+
cc: [ 'clang-18' ]
57+
cxx: [ 'clang++-18' ]
58+
clang_tidy: [ 'ON' ]
59+
include:
60+
- config: 'generic-gcc'
61+
cc: 'gcc-13'
62+
cxx: 'g++-13'
63+
clang_tidy: 'OFF'
64+
steps:
65+
- uses: actions/checkout@v4
66+
- name: ${{ matrix.config }}.${{ matrix.cxx }}
67+
run: libcxx/utils/ci/run-buildbot ${{ matrix.config }}
68+
env:
69+
CC: ${{ matrix.cc }}
70+
CXX: ${{ matrix.cxx }}
71+
ENABLE_CLANG_TIDY: ${{ matrix.clang_tidy }}
72+
- uses: actions/upload-artifact@v3
73+
if: always()
74+
with:
75+
name: ${{ matrix.config }}-${{ matrix.cxx }}-results
76+
path: |
77+
**/test-results.xml
78+
**/*.abilist
79+
**/CMakeError.log
80+
**/CMakeOutput.log
81+
**/crash_diagnostics/*
82+
stage2:
83+
runs-on: libcxx-runners-8
84+
needs: [ stage1 ]
85+
continue-on-error: false
86+
strategy:
87+
fail-fast: true
88+
matrix:
89+
config: [
90+
'generic-cxx11',
91+
'generic-cxx14',
92+
'generic-cxx17',
93+
'generic-cxx20',
94+
'generic-cxx23'
95+
]
96+
cc: [ 'clang-18' ]
97+
cxx: [ 'clang++-18' ]
98+
clang_tidy: [ 'ON' ]
99+
include:
100+
- config: 'generic-gcc-cxx11'
101+
cc: 'gcc-13'
102+
cxx: 'g++-13'
103+
clang_tidy: 'OFF'
104+
- config: 'generic-cxx23'
105+
cc: 'clang-16'
106+
cxx: 'clang++-16'
107+
clang_tidy: 'OFF'
108+
- config: 'generic-cxx23'
109+
cc: 'clang-17'
110+
cxx: 'clang++-17'
111+
clang_tidy: 'OFF'
112+
steps:
113+
- uses: actions/checkout@v4
114+
- name: ${{ matrix.config }}
115+
run: libcxx/utils/ci/run-buildbot ${{ matrix.config }}
116+
env:
117+
CC: ${{ matrix.cc }}
118+
CXX: ${{ matrix.cxx }}
119+
ENABLE_CLANG_TIDY: ${{ matrix.clang_tidy }}
120+
- uses: actions/upload-artifact@v3
121+
if: always() # Upload artifacts even if the build or test suite fails
122+
with:
123+
name: ${{ matrix.config }}-results
124+
path: |
125+
**/test-results.xml
126+
**/*.abilist
127+
**/CMakeError.log
128+
**/CMakeOutput.log
129+
**/crash_diagnostics/*
130+
stage3:
131+
needs: [ stage1, stage2 ]
132+
continue-on-error: false
133+
strategy:
134+
fail-fast: false
135+
max-parallel: 8
136+
matrix:
137+
config: [
138+
'generic-abi-unstable',
139+
'generic-hardening-mode-debug',
140+
'generic-hardening-mode-extensive',
141+
'generic-hardening-mode-fast',
142+
'generic-hardening-mode-fast-with-abi-breaks',
143+
'generic-merged',
144+
'generic-modules-lsv',
145+
'generic-no-exceptions',
146+
'generic-no-experimental',
147+
'generic-no-filesystem',
148+
'generic-no-localization',
149+
'generic-no-random_device',
150+
'generic-no-threads',
151+
'generic-no-tzdb',
152+
'generic-no-unicode',
153+
'generic-no-wide-characters',
154+
'generic-static',
155+
'generic-with_llvm_unwinder'
156+
]
157+
machine: [ 'libcxx-runners-8' ]
158+
std_modules: [ 'OFF' ]
159+
include:
160+
- config: 'generic-cxx26'
161+
machine: libcxx-runners-8
162+
std_modules: 'ON'
163+
- config: 'generic-asan'
164+
machine: libcxx-runners-16
165+
std_modules: 'OFF'
166+
- config: 'generic-tsan'
167+
machine: libcxx-runners-16
168+
std_modules: 'OFF'
169+
- config: 'generic-ubsan'
170+
machine: libcxx-runners-8
171+
std_modules: 'OFF'
172+
# Use a larger machine for MSAN to avoid timeout and memory allocation issues.
173+
- config: 'generic-msan'
174+
machine: libcxx-runners-30
175+
std_modules: 'OFF'
176+
runs-on: ${{ matrix.machine }}
177+
steps:
178+
- uses: actions/checkout@v4
179+
- name: ${{ matrix.config }}
180+
run: libcxx/utils/ci/run-buildbot ${{ matrix.config }}
181+
env:
182+
CC: clang-18
183+
CXX: clang++-18
184+
ENABLE_CLANG_TIDY: "OFF"
185+
ENABLE_STD_MODULES: ${{ matrix.std_modules }}
186+
- uses: actions/upload-artifact@v3
187+
if: always()
188+
with:
189+
name: ${{ matrix.config }}-results
190+
path: |
191+
**/test-results.xml
192+
**/*.abilist
193+
**/CMakeError.log
194+
**/CMakeOutput.log
195+
**/crash_diagnostics/*
196+

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,6 @@ class BinaryFunction {
319319
/// Execution halts whenever this function is entered.
320320
bool TrapsOnEntry{false};
321321

322-
/// True if the function had an indirect branch with a fixed internal
323-
/// destination.
324-
bool HasFixedIndirectBranch{false};
325-
326322
/// True if the function is a fragment of another function. This means that
327323
/// this function could only be entered via its parent or one of its sibling
328324
/// fragments. It could be entered at any basic block. It can also return

bolt/lib/Core/BinaryContext.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,10 +1926,27 @@ BinaryContext::getBaseAddressForMapping(uint64_t MMapAddress,
19261926
// Find a segment with a matching file offset.
19271927
for (auto &KV : SegmentMapInfo) {
19281928
const SegmentInfo &SegInfo = KV.second;
1929-
if (alignDown(SegInfo.FileOffset, SegInfo.Alignment) == FileOffset) {
1930-
// Use segment's aligned memory offset to calculate the base address.
1931-
const uint64_t MemOffset = alignDown(SegInfo.Address, SegInfo.Alignment);
1932-
return MMapAddress - MemOffset;
1929+
// FileOffset is got from perf event,
1930+
// and it is equal to alignDown(SegInfo.FileOffset, pagesize).
1931+
// If the pagesize is not equal to SegInfo.Alignment.
1932+
// FileOffset and SegInfo.FileOffset should be aligned first,
1933+
// and then judge whether they are equal.
1934+
if (alignDown(SegInfo.FileOffset, SegInfo.Alignment) ==
1935+
alignDown(FileOffset, SegInfo.Alignment)) {
1936+
// The function's offset from base address in VAS is aligned by pagesize
1937+
// instead of SegInfo.Alignment. Pagesize can't be got from perf events.
1938+
// However, The ELF document says that SegInfo.FileOffset should equal
1939+
// to SegInfo.Address, modulo the pagesize.
1940+
// Reference: https://refspecs.linuxfoundation.org/elf/elf.pdf
1941+
1942+
// So alignDown(SegInfo.Address, pagesize) can be calculated by:
1943+
// alignDown(SegInfo.Address, pagesize)
1944+
// = SegInfo.Address - (SegInfo.Address % pagesize)
1945+
// = SegInfo.Address - (SegInfo.FileOffset % pagesize)
1946+
// = SegInfo.Address - SegInfo.FileOffset +
1947+
// alignDown(SegInfo.FileOffset, pagesize)
1948+
// = SegInfo.Address - SegInfo.FileOffset + FileOffset
1949+
return MMapAddress - (SegInfo.Address - SegInfo.FileOffset + FileOffset);
19331950
}
19341951
}
19351952

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,9 @@ namespace opts {
5454

5555
extern cl::OptionCategory BoltCategory;
5656
extern cl::OptionCategory BoltOptCategory;
57-
extern cl::OptionCategory BoltRelocCategory;
5857

5958
extern cl::opt<bool> EnableBAT;
6059
extern cl::opt<bool> Instrument;
61-
extern cl::opt<bool> KeepNops;
6260
extern cl::opt<bool> StrictMode;
6361
extern cl::opt<bool> UpdateDebugSections;
6462
extern cl::opt<unsigned> Verbosity;
@@ -432,8 +430,6 @@ void BinaryFunction::print(raw_ostream &OS, std::string Annotation) {
432430
OS << "\n IsSplit : " << isSplit();
433431
OS << "\n BB Count : " << size();
434432

435-
if (HasFixedIndirectBranch)
436-
OS << "\n HasFixedIndirectBranch : true";
437433
if (HasUnknownControlFlow)
438434
OS << "\n Unknown CF : true";
439435
if (getPersonalityFunction())
@@ -1118,7 +1114,7 @@ void BinaryFunction::handleIndirectBranch(MCInst &Instruction, uint64_t Size,
11181114
Instruction.clear();
11191115
MIB->createUncondBranch(Instruction, TargetSymbol, BC.Ctx.get());
11201116
TakenBranches.emplace_back(Offset, IndirectTarget - getAddress());
1121-
HasFixedIndirectBranch = true;
1117+
addEntryPointAtOffset(IndirectTarget - getAddress());
11221118
} else {
11231119
MIB->convertJmpToTailCall(Instruction);
11241120
BC.addInterproceduralReference(this, IndirectTarget);
@@ -1894,9 +1890,6 @@ bool BinaryFunction::postProcessIndirectBranches(
18941890
LastIndirectJumpBB->updateJumpTableSuccessors();
18951891
}
18961892

1897-
if (HasFixedIndirectBranch)
1898-
return false;
1899-
19001893
// Validate that all data references to function offsets are claimed by
19011894
// recognized jump tables. Register externally referenced blocks as entry
19021895
// points.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <unistd.h>
4+
5+
int add(int a, int b) { return a + b; }
6+
int minus(int a, int b) { return a - b; }
7+
int multiple(int a, int b) { return a * b; }
8+
int divide(int a, int b) {
9+
if (b == 0)
10+
return 0;
11+
return a / b;
12+
}
13+
14+
int main() {
15+
int a = 16;
16+
int b = 8;
17+
18+
for (int i = 1; i < 100000; i++) {
19+
add(a, b);
20+
minus(a, b);
21+
multiple(a, b);
22+
divide(a, b);
23+
}
24+
25+
return 0;
26+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
SECTIONS {
2+
. = SIZEOF_HEADERS;
3+
.interp : { *(.interp) }
4+
.note.gnu.build-id : { *(.note.gnu.build-id) }
5+
. = 0x212e8;
6+
.dynsym : { *(.dynsym) }
7+
. = 0x31860;
8+
.text : { *(.text*) }
9+
. = 0x41c20;
10+
.fini_array : { *(.fini_array) }
11+
. = 0x54e18;
12+
.data : { *(.data) }
13+
}

bolt/test/perf2bolt/lit.local.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import shutil
2+
3+
if shutil.which("perf") != None:
4+
config.available_features.add("perf")

bolt/test/perf2bolt/perf_test.test

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Check perf2bolt binary function which was compiled with pie
2+
3+
REQUIRES: system-linux, perf
4+
5+
RUN: %clang %S/Inputs/perf_test.c -fuse-ld=lld -Wl,--script=%S/Inputs/perf_test.lds -o %t
6+
RUN: perf record -e cycles:u -o %t2 -- %t
7+
RUN: perf2bolt %t -p=%t2 -o %t3 -nl -ignore-build-id 2>&1 | FileCheck %s
8+
9+
CHECK-NOT: PERF2BOLT-ERROR
10+
CHECK-NOT: !! WARNING !! This high mismatch ratio indicates the input binary is probably not the same binary used during profiling collection.
11+
12+
RUN: %clang %S/Inputs/perf_test.c -no-pie -fuse-ld=lld -o %t4
13+
RUN: perf record -e cycles:u -o %t5 -- %t4
14+
RUN: perf2bolt %t4 -p=%t5 -o %t6 -nl -ignore-build-id 2>&1 | FileCheck %s --check-prefix=CHECK-NO-PIE
15+
16+
CHECK-NO-PIE-NOT: PERF2BOLT-ERROR
17+
CHECK-NO-PIE-NOT: !! WARNING !! This high mismatch ratio indicates the input binary is probably not the same binary used during profiling collection.

bolt/unittests/Core/BinaryContext.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,24 @@ TEST_P(BinaryContextTester, BaseAddress) {
123123
BaseAddress = BC->getBaseAddressForMapping(0x7f13f5556000, 0x137a000);
124124
ASSERT_FALSE(BaseAddress.has_value());
125125
}
126+
127+
TEST_P(BinaryContextTester, BaseAddress2) {
128+
// Check that base address calculation is correct for a binary if the
129+
// alignment in ELF file are different from pagesize.
130+
// The segment layout is as follows:
131+
BC->SegmentMapInfo[0] = SegmentInfo{0, 0x2177c, 0, 0x2177c, 0x10000};
132+
BC->SegmentMapInfo[0x31860] =
133+
SegmentInfo{0x31860, 0x370, 0x21860, 0x370, 0x10000};
134+
BC->SegmentMapInfo[0x41c20] =
135+
SegmentInfo{0x41c20, 0x1f8, 0x21c20, 0x1f8, 0x10000};
136+
BC->SegmentMapInfo[0x54e18] =
137+
SegmentInfo{0x54e18, 0x51, 0x24e18, 0x51, 0x10000};
138+
139+
std::optional<uint64_t> BaseAddress =
140+
BC->getBaseAddressForMapping(0xaaaaea444000, 0x21000);
141+
ASSERT_TRUE(BaseAddress.has_value());
142+
ASSERT_EQ(*BaseAddress, 0xaaaaea413000ULL);
143+
144+
BaseAddress = BC->getBaseAddressForMapping(0xaaaaea444000, 0x11000);
145+
ASSERT_FALSE(BaseAddress.has_value());
146+
}

clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,18 @@ AST_MATCHER_P2(Expr, hasSideEffect, bool, CheckFunctionCalls,
4141
}
4242

4343
if (const auto *OpCallExpr = dyn_cast<CXXOperatorCallExpr>(E)) {
44+
if (const auto *MethodDecl =
45+
dyn_cast_or_null<CXXMethodDecl>(OpCallExpr->getDirectCallee()))
46+
if (MethodDecl->isConst())
47+
return false;
48+
4449
OverloadedOperatorKind OpKind = OpCallExpr->getOperator();
4550
return OpKind == OO_Equal || OpKind == OO_PlusEqual ||
4651
OpKind == OO_MinusEqual || OpKind == OO_StarEqual ||
4752
OpKind == OO_SlashEqual || OpKind == OO_AmpEqual ||
4853
OpKind == OO_PipeEqual || OpKind == OO_CaretEqual ||
4954
OpKind == OO_LessLessEqual || OpKind == OO_GreaterGreaterEqual ||
55+
OpKind == OO_LessLess || OpKind == OO_GreaterGreater ||
5056
OpKind == OO_PlusPlus || OpKind == OO_MinusMinus ||
5157
OpKind == OO_PercentEqual || OpKind == OO_New ||
5258
OpKind == OO_Delete || OpKind == OO_Array_New ||

0 commit comments

Comments
 (0)