Skip to content

Commit 26b23c5

Browse files
Merge branch 'main' into deprecate-string-lookup-target
2 parents 35d6787 + e3a376f commit 26b23c5

File tree

73 files changed

+2181
-221
lines changed

Some content is hidden

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

73 files changed

+2181
-221
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
name: Build CI Container
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
push:
8+
branches:
9+
- main
10+
paths:
11+
- .github/workflows/build-ci-container-tooling.yml
12+
- '.github/workflows/containers/github-action-ci-tooling/**'
13+
- llvm/utils/git/requirements_formatting.txt
14+
- llvm/utils/git/requirements_linting.txt
15+
pull_request:
16+
paths:
17+
- .github/workflows/build-ci-container-tooling.yml
18+
- '.github/workflows/containers/github-action-ci-tooling/**'
19+
- llvm/utils/git/requirements_formatting.txt
20+
- llvm/utils/git/requirements_linting.txt
21+
22+
jobs:
23+
build-ci-container-tooling:
24+
if: github.repository_owner == 'llvm'
25+
runs-on: ubuntu-24.04
26+
steps:
27+
- name: Checkout LLVM
28+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
29+
with:
30+
sparse-checkout: |
31+
.github/workflows/containers/github-action-ci-tooling/
32+
llvm/utils/git/requirements_formatting.txt
33+
llvm/utils/git/requirements_linting.txt
34+
clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
35+
36+
- name: Write Variables
37+
id: vars
38+
run: |
39+
tag=$(git rev-parse --short=12 HEAD)
40+
container_name="ghcr.io/$GITHUB_REPOSITORY_OWNER/amd64/ci-ubuntu-24.04"
41+
echo "container-name-format=$container_name-code-format" >> $GITHUB_OUTPUT
42+
echo "container-name-lint=$container_name-code-lint" >> $GITHUB_OUTPUT
43+
echo "container-name-format-tag=$container_name-format:$tag" >> $GITHUB_OUTPUT
44+
echo "container-name-lint-tag=$container_name-lint:$tag" >> $GITHUB_OUTPUT
45+
echo "container-format-filename=$(echo $container_name-format:$tag | sed -e 's/\//-/g' -e 's/:/-/g').tar" >> $GITHUB_OUTPUT
46+
echo "container-lint-filename=$(echo $container_name-lint:$tag | sed -e 's/\//-/g' -e 's/:/-/g').tar" >> $GITHUB_OUTPUT
47+
48+
- name: Build container
49+
run: |
50+
podman build --target ci-container-code-format \
51+
-f .github/workflows/containers/github-action-ci-tooling/Dockerfile \
52+
-t ${{ steps.vars.outputs.container-name-format-tag }} .
53+
podman build --target ci-container-code-lint \
54+
-f .github/workflows/containers/github-action-ci-tooling/Dockerfile \
55+
-t ${{ steps.vars.outputs.container-name-lint-tag }} .
56+
57+
# Save the container so we have it in case the push fails. This also
58+
# allows us to separate the push step into a different job so we can
59+
# maintain minimal permissions while building the container.
60+
- name: Save container image
61+
run: |
62+
podman save ${{ steps.vars.outputs.container-name-format-tag }} > ${{ steps.vars.outputs.container-format-filename }}
63+
podman save ${{ steps.vars.outputs.container-name-lint-tag }} > ${{ steps.vars.outputs.container-lint-filename }}
64+
65+
- name: Upload container image
66+
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
67+
with:
68+
name: container-amd64
69+
path: "*.tar"
70+
retention-days: 14
71+
72+
- name: Test Container
73+
run: |
74+
# Use --pull=never to ensure we are testing the just built image.
75+
podman run --pull=never --rm -it ${{ steps.vars.outputs.container-name-format-tag }} /usr/bin/bash -x -c 'cd $HOME && clang-format --version | grep version && black --version | grep black'
76+
podman run --pull=never --rm -it ${{ steps.vars.outputs.container-name-lint-tag }} /usr/bin/bash -x -c 'cd $HOME && clang-tidy --version | grep version && clang-tidy-diff.py -h | grep usage'
77+
78+
push-ci-container:
79+
if: github.event_name == 'push'
80+
needs:
81+
- build-ci-container-tooling
82+
permissions:
83+
packages: write
84+
runs-on: ubuntu-24.04
85+
env:
86+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
87+
steps:
88+
- name: Download container
89+
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
90+
91+
- name: Push Container
92+
run: |
93+
function push_container {
94+
image_name=$1
95+
latest_name=$(echo $image_name | sed 's/:[a-f0-9]\+$/:latest/g')
96+
podman tag $image_name $latest_name
97+
echo "Pushing $image_name ..."
98+
podman push $image_name
99+
echo "Pushing $latest_name ..."
100+
podman push $latest_name
101+
}
102+
103+
podman login -u ${{ github.actor }} -p $GITHUB_TOKEN ghcr.io
104+
for f in $(find . -iname *.tar); do
105+
image_name=$(podman load -q -i $f | sed 's/Loaded image: //g')
106+
push_container $image_name
107+
108+
if echo $image_name | grep '/amd64/'; then
109+
# For amd64, create an alias with the arch component removed.
110+
# This matches the convention used on dockerhub.
111+
default_image_name=$(echo $(dirname $(dirname $image_name))/$(basename $image_name))
112+
podman tag $image_name $default_image_name
113+
push_container $default_image_name
114+
fi
115+
done
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
ARG LLVM_VERSION=21.1.0
2+
3+
FROM docker.io/library/ubuntu:24.04 AS llvm-downloader
4+
ARG LLVM_VERSION
5+
6+
RUN apt-get update && \
7+
apt-get install -y wget xz-utils && \
8+
wget -O llvm.tar.xz https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/LLVM-${LLVM_VERSION}-Linux-X64.tar.xz && \
9+
mkdir -p /llvm-extract && \
10+
tar -xvJf llvm.tar.xz -C /llvm-extract \
11+
# Only unpack these tools to save space on Github runner.
12+
LLVM-${LLVM_VERSION}-Linux-X64/bin/clang-tidy \
13+
LLVM-${LLVM_VERSION}-Linux-X64/bin/clang-format && \
14+
rm llvm.tar.xz
15+
16+
17+
FROM docker.io/library/ubuntu:24.04 AS base
18+
ENV LLVM_SYSROOT=/opt/llvm
19+
20+
# Need nodejs for some of the GitHub actions.
21+
# Need git for git-clang-format.
22+
RUN apt-get update && \
23+
DEBIAN_FRONTEND=noninteractive apt-get install -y \
24+
git \
25+
nodejs \
26+
sudo \
27+
# These are needed by the premerge pipeline.
28+
# Pip is used to install dependent python packages.
29+
python3-pip \
30+
python-is-python3 && \
31+
apt-get clean && \
32+
rm -rf /var/lib/apt/lists/*
33+
34+
35+
FROM base AS ci-container-code-format
36+
ARG LLVM_VERSION
37+
38+
COPY --from=llvm-downloader /llvm-extract/LLVM-${LLVM_VERSION}-Linux-X64/bin/clang-format ${LLVM_SYSROOT}/bin/clang-format
39+
40+
ENV PATH=${LLVM_SYSROOT}/bin:${PATH}
41+
42+
# Install dependencies for 'pr-code-format.yml' job
43+
COPY llvm/utils/git/requirements_formatting.txt requirements_formatting.txt
44+
RUN pip install -r requirements_formatting.txt --break-system-packages && \
45+
rm requirements_formatting.txt
46+
47+
48+
FROM base AS ci-container-code-lint
49+
ARG LLVM_VERSION
50+
51+
COPY --from=llvm-downloader /llvm-extract/LLVM-${LLVM_VERSION}-Linux-X64/bin/clang-tidy ${LLVM_SYSROOT}/bin/
52+
COPY clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py ${LLVM_SYSROOT}/bin/clang-tidy-diff.py
53+
54+
ENV PATH=${LLVM_SYSROOT}/bin:${PATH}
55+
56+
# Install dependencies for 'pr-code-lint.yml' job
57+
COPY llvm/utils/git/requirements_linting.txt requirements_linting.txt
58+
RUN pip install -r requirements_linting.txt --break-system-packages && \
59+
rm requirements_linting.txt

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -917,9 +917,6 @@ void RewriteInstance::discoverFileObjects() {
917917
bool IsData = false;
918918
uint64_t LastAddr = 0;
919919
for (const auto &SymInfo : SortedSymbols) {
920-
if (LastAddr == SymInfo.Address) // don't repeat markers
921-
continue;
922-
923920
MarkerSymType MarkerType = BC->getMarkerType(SymInfo.Symbol);
924921

925922
// Treat ST_Function as code.
@@ -929,8 +926,14 @@ void RewriteInstance::discoverFileObjects() {
929926
if (IsData) {
930927
Expected<StringRef> NameOrError = SymInfo.Symbol.getName();
931928
consumeError(NameOrError.takeError());
932-
BC->errs() << "BOLT-WARNING: function symbol " << *NameOrError
933-
<< " lacks code marker\n";
929+
if (LastAddr == SymInfo.Address) {
930+
BC->errs() << "BOLT-WARNING: ignoring data marker conflicting with "
931+
"function symbol "
932+
<< *NameOrError << '\n';
933+
} else {
934+
BC->errs() << "BOLT-WARNING: function symbol " << *NameOrError
935+
<< " lacks code marker\n";
936+
}
934937
}
935938
MarkerType = MarkerSymType::CODE;
936939
}

bolt/test/AArch64/data-at-0-offset.c

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## Check that if a data marker is present at the start of a function, the
2+
## underlying bytes are still treated as code.
3+
4+
# RUN: %clang %cflags %s -o %t.exe
5+
# RUN: llvm-bolt %t.exe -o %t.bolt --print-cfg 2>&1 | FileCheck %s
6+
7+
# CHECK: BOLT-WARNING: ignoring data marker conflicting with function symbol _start
8+
9+
.text
10+
.balign 4
11+
12+
## Data marker is emitted because ".long" directive is used instead of ".inst".
13+
.global _start
14+
.type _start, %function
15+
_start:
16+
.long 0xcec08000 // sha512su0 v0.2d, v0.2d
17+
ret
18+
.size _start, .-_start
19+
20+
# CHECK-LABEL: Binary Function "_start"
21+
# CHECK: Entry Point
22+
# CHECK-NEXT: sha512su0 v0.2d, v0.2d
23+

clang/lib/CIR/CodeGen/CIRGenClass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ void CIRGenFunction::emitCXXAggrConstructorCall(
690690
// every temporary created in a default argument expression is sequenced
691691
// before the construction of the next array element, if any.
692692
{
693-
assert(!cir::MissingFeatures::runCleanupsScope());
693+
RunCleanupsScope scope(*this);
694694

695695
// Evaluate the constructor and its arguments in a regular
696696
// partial-destroy cleanup.

clang/lib/CIR/CodeGen/CIRGenCleanup.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ using namespace clang::CIRGen;
2828
// CIRGenFunction cleanup related
2929
//===----------------------------------------------------------------------===//
3030

31+
/// Emits all the code to cause the given temporary to be cleaned up.
32+
void CIRGenFunction::emitCXXTemporary(const CXXTemporary *temporary,
33+
QualType tempType, Address ptr) {
34+
pushDestroy(NormalAndEHCleanup, ptr, tempType, destroyCXXObject);
35+
}
36+
3137
//===----------------------------------------------------------------------===//
3238
// EHScopeStack
3339
//===----------------------------------------------------------------------===//

clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ class AggExprEmitter : public StmtVisitor<AggExprEmitter> {
4646
return dest;
4747
}
4848

49+
void ensureDest(mlir::Location loc, QualType ty) {
50+
if (!dest.isIgnored())
51+
return;
52+
dest = cgf.createAggTemp(ty, loc, "agg.tmp.ensured");
53+
}
54+
4955
public:
5056
AggExprEmitter(CIRGenFunction &cgf, AggValueSlot dest)
5157
: cgf(cgf), dest(dest) {}
@@ -96,10 +102,22 @@ class AggExprEmitter : public StmtVisitor<AggExprEmitter> {
96102
Visit(die->getExpr());
97103
}
98104
void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *e) {
99-
assert(!cir::MissingFeatures::aggValueSlotDestructedFlag());
105+
// Ensure that we have a slot, but if we already do, remember
106+
// whether it was externally destructed.
107+
bool wasExternallyDestructed = dest.isExternallyDestructed();
108+
ensureDest(cgf.getLoc(e->getSourceRange()), e->getType());
109+
110+
// We're going to push a destructor if there isn't already one.
111+
dest.setExternallyDestructed();
112+
100113
Visit(e->getSubExpr());
114+
115+
// Push that destructor we promised.
116+
if (!wasExternallyDestructed)
117+
cgf.emitCXXTemporary(e->getTemporary(), e->getType(), dest.getAddress());
101118
}
102119
void VisitLambdaExpr(LambdaExpr *e);
120+
void VisitExprWithCleanups(ExprWithCleanups *e);
103121

104122
// Stubs -- These should be moved up when they are implemented.
105123
void VisitCastExpr(CastExpr *e) {
@@ -241,11 +259,6 @@ class AggExprEmitter : public StmtVisitor<AggExprEmitter> {
241259
cgf.cgm.errorNYI(e->getSourceRange(),
242260
"AggExprEmitter: VisitCXXStdInitializerListExpr");
243261
}
244-
245-
void VisitExprWithCleanups(ExprWithCleanups *e) {
246-
cgf.cgm.errorNYI(e->getSourceRange(),
247-
"AggExprEmitter: VisitExprWithCleanups");
248-
}
249262
void VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *e) {
250263
cgf.cgm.errorNYI(e->getSourceRange(),
251264
"AggExprEmitter: VisitCXXScalarValueInitExpr");
@@ -588,6 +601,11 @@ void AggExprEmitter::VisitLambdaExpr(LambdaExpr *e) {
588601
}
589602
}
590603

604+
void AggExprEmitter::VisitExprWithCleanups(ExprWithCleanups *e) {
605+
CIRGenFunction::RunCleanupsScope cleanups(cgf);
606+
Visit(e->getSubExpr());
607+
}
608+
591609
void AggExprEmitter::VisitCallExpr(const CallExpr *e) {
592610
if (e->getCallReturnType(cgf.getContext())->isReferenceType()) {
593611
cgf.cgm.errorNYI(e->getSourceRange(), "reference return type");

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,15 +1099,17 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
10991099
CIRGenFunction::LexicalScope lexScope{cgf, loc,
11001100
b.getInsertionBlock()};
11011101
cgf.curLexScope->setAsTernary();
1102-
b.create<cir::YieldOp>(loc, cgf.evaluateExprAsBool(e->getRHS()));
1102+
mlir::Value res = cgf.evaluateExprAsBool(e->getRHS());
1103+
lexScope.forceCleanup();
1104+
cir::YieldOp::create(b, loc, res);
11031105
},
11041106
/*falseBuilder*/
11051107
[&](mlir::OpBuilder &b, mlir::Location loc) {
11061108
CIRGenFunction::LexicalScope lexScope{cgf, loc,
11071109
b.getInsertionBlock()};
11081110
cgf.curLexScope->setAsTernary();
1109-
auto res = b.create<cir::ConstantOp>(loc, builder.getFalseAttr());
1110-
b.create<cir::YieldOp>(loc, res.getRes());
1111+
auto res = cir::ConstantOp::create(b, loc, builder.getFalseAttr());
1112+
cir::YieldOp::create(b, loc, res.getRes());
11111113
});
11121114
return maybePromoteBoolResult(resOp.getResult(), resTy);
11131115
}
@@ -1143,15 +1145,17 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
11431145
CIRGenFunction::LexicalScope lexScope{cgf, loc,
11441146
b.getInsertionBlock()};
11451147
cgf.curLexScope->setAsTernary();
1146-
auto res = b.create<cir::ConstantOp>(loc, builder.getTrueAttr());
1147-
b.create<cir::YieldOp>(loc, res.getRes());
1148+
auto res = cir::ConstantOp::create(b, loc, builder.getTrueAttr());
1149+
cir::YieldOp::create(b, loc, res.getRes());
11481150
},
11491151
/*falseBuilder*/
11501152
[&](mlir::OpBuilder &b, mlir::Location loc) {
11511153
CIRGenFunction::LexicalScope lexScope{cgf, loc,
11521154
b.getInsertionBlock()};
11531155
cgf.curLexScope->setAsTernary();
1154-
b.create<cir::YieldOp>(loc, cgf.evaluateExprAsBool(e->getRHS()));
1156+
mlir::Value res = cgf.evaluateExprAsBool(e->getRHS());
1157+
lexScope.forceCleanup();
1158+
cir::YieldOp::create(b, loc, res);
11551159
});
11561160

11571161
return maybePromoteBoolResult(resOp.getResult(), resTy);

clang/lib/CIR/CodeGen/CIRGenFunction.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,6 +1258,9 @@ class CIRGenFunction : public CIRGenTypeCache {
12581258

12591259
RValue emitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *expr);
12601260

1261+
void emitCXXTemporary(const CXXTemporary *temporary, QualType tempType,
1262+
Address ptr);
1263+
12611264
void emitCXXThrowExpr(const CXXThrowExpr *e);
12621265

12631266
void emitCtorPrologue(const clang::CXXConstructorDecl *ctor,

0 commit comments

Comments
 (0)