Skip to content

Commit 135ac90

Browse files
authored
Merge branch 'main' into issue143668
2 parents 849ea65 + b2c38f1 commit 135ac90

File tree

1,293 files changed

+60488
-35457
lines changed

Some content is hidden

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

1,293 files changed

+60488
-35457
lines changed

.github/workflows/premerge.yaml

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ jobs:
3434
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3535
with:
3636
fetch-depth: 2
37-
- name: Setup ccache
38-
uses: hendrikmuhs/ccache-action@a1209f81afb8c005c13b4296c32e363431bffea5 # v1.2.17
39-
with:
40-
variant: "sccache"
41-
max-size: "2000M"
4237
- name: Build and Test
4338
# Mark the job as a success even if the step fails so that people do
4439
# not get notified while the new premerge pipeline is in an
@@ -62,6 +57,13 @@ jobs:
6257
export CC=/opt/llvm/bin/clang
6358
export CXX=/opt/llvm/bin/clang++
6459
60+
# This environment variable is passes into the container through the
61+
# runner pod definition. This differs between our two clusters which
62+
# why we do not hardcode it.
63+
export SCCACHE_GCS_BUCKET=$CACHE_GCS_BUCKET
64+
export SCCACHE_GCS_RW_MODE=READ_WRITE
65+
sccache --start-server
66+
6567
./.ci/monolithic-linux.sh "${projects_to_build}" "${project_check_targets}" "${runtimes_to_build}" "${runtimes_check_targets}" "${runtimes_check_targets_needs_reconfig}" "${enable_cir}"
6668
- name: Upload Artifacts
6769
if: '!cancelled()'
@@ -86,11 +88,6 @@ jobs:
8688
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
8789
with:
8890
fetch-depth: 2
89-
- name: Setup ccache
90-
uses: hendrikmuhs/ccache-action@a1209f81afb8c005c13b4296c32e363431bffea5 # v1.2.17
91-
with:
92-
variant: "sccache"
93-
max-size: "2000M"
9491
- name: Compute Projects
9592
id: vars
9693
run: |
@@ -113,7 +110,7 @@ jobs:
113110
shell: cmd
114111
run: |
115112
call C:\\BuildTools\\Common7\\Tools\\VsDevCmd.bat -arch=amd64 -host_arch=amd64
116-
bash .ci/monolithic-windows.sh "${{ steps.vars.outputs.windows-projects }}" "${{ steps.vars.outputs.windows-check-targets }}"
113+
bash -c "export SCCACHE_GCS_BUCKET=$CACHE_GCS_BUCKET; export SCCACHE_GCS_RW_MODE=READ_WRITE; sccache --start-server; .ci/monolithic-windows.sh \"${{ steps.vars.outputs.windows-projects }}\" \"${{ steps.vars.outputs.windows-check-targets }}\""
117114
- name: Upload Artifacts
118115
if: '!cancelled()'
119116
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0

bolt/utils/nfc-check-setup.py

Lines changed: 102 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import sys
88
import textwrap
99

10+
msg_prefix = "\n> NFC-Mode:"
11+
1012
def get_relevant_bolt_changes(dir: str) -> str:
1113
# Return a list of bolt source changes that are relevant to testing.
1214
all_changes = subprocess.run(
@@ -42,14 +44,32 @@ def get_git_ref_or_rev(dir: str) -> str:
4244
cmd_rev = "git rev-parse --short HEAD"
4345
return subprocess.check_output(shlex.split(cmd_rev), cwd=dir, text=True).strip()
4446

47+
def switch_back(
48+
switch_back: bool, stash: bool, source_dir: str, old_ref: str, new_ref: str
49+
):
50+
# Switch back to the current revision if needed and inform the user of where
51+
# the HEAD is. Must be called after checking out the previous commit on all
52+
# exit paths.
53+
if switch_back:
54+
print(f"{msg_prefix} Switching back to current revision..")
55+
if stash:
56+
subprocess.run(shlex.split("git stash pop"), cwd=source_dir)
57+
subprocess.run(shlex.split(f"git checkout {old_ref}"), cwd=source_dir)
58+
else:
59+
print(
60+
f"The repository {source_dir} has been switched from {old_ref} "
61+
f"to {new_ref}. Local changes were stashed. Switch back using\n\t"
62+
f"git checkout {old_ref}\n"
63+
)
4564

4665
def main():
4766
parser = argparse.ArgumentParser(
4867
description=textwrap.dedent(
4968
"""
50-
This script builds two versions of BOLT (with the current and
51-
previous revision) and sets up symlink for llvm-bolt-wrapper.
52-
Passes the options through to llvm-bolt-wrapper.
69+
This script builds two versions of BOLT:
70+
llvm-bolt.new, using the current revision, and llvm-bolt.old using
71+
the previous revision. These can be used to check whether the
72+
current revision changes BOLT's functional behavior.
5373
"""
5474
)
5575
)
@@ -59,6 +79,12 @@ def main():
5979
default=os.getcwd(),
6080
help="Path to BOLT build directory, default is current " "directory",
6181
)
82+
parser.add_argument(
83+
"--create-wrapper",
84+
default=False,
85+
action="store_true",
86+
help="Sets up llvm-bolt as a symlink to llvm-bolt-wrapper. Passes the options through to llvm-bolt-wrapper.",
87+
)
6288
parser.add_argument(
6389
"--check-bolt-sources",
6490
default=False,
@@ -76,28 +102,42 @@ def main():
76102
default="HEAD^",
77103
help="Revision to checkout to compare vs HEAD",
78104
)
105+
106+
# When creating a wrapper, pass any unknown arguments to it. Otherwise, die.
79107
args, wrapper_args = parser.parse_known_args()
80-
bolt_path = f"{args.build_dir}/bin/llvm-bolt"
108+
if not args.create_wrapper and len(wrapper_args) > 0:
109+
parser.parse_args()
81110

111+
# Find the repo directory.
82112
source_dir = None
83-
# find the repo directory
84-
with open(f"{args.build_dir}/CMakeCache.txt") as f:
85-
for line in f:
86-
m = re.match(r"LLVM_SOURCE_DIR:STATIC=(.*)", line)
87-
if m:
88-
source_dir = m.groups()[0]
89-
if not source_dir:
90-
sys.exit("Source directory is not found")
91-
92-
script_dir = os.path.dirname(os.path.abspath(__file__))
93-
wrapper_path = f"{script_dir}/llvm-bolt-wrapper.py"
94-
# build the current commit
113+
try:
114+
CMCacheFilename = f"{args.build_dir}/CMakeCache.txt"
115+
with open(CMCacheFilename) as f:
116+
for line in f:
117+
m = re.match(r"LLVM_SOURCE_DIR:STATIC=(.*)", line)
118+
if m:
119+
source_dir = m.groups()[0]
120+
if not source_dir:
121+
raise Exception(f"Source directory not found: '{CMCacheFilename}'")
122+
except Exception as e:
123+
sys.exit(e)
124+
125+
# Clean the previous llvm-bolt if it exists.
126+
bolt_path = f"{args.build_dir}/bin/llvm-bolt"
127+
if os.path.exists(bolt_path):
128+
os.remove(bolt_path)
129+
130+
# Build the current commit.
131+
print(f"{msg_prefix} Building current revision..")
95132
subprocess.run(
96133
shlex.split("cmake --build . --target llvm-bolt"), cwd=args.build_dir
97134
)
98-
# rename llvm-bolt
135+
136+
if not os.path.exists(bolt_path):
137+
sys.exit(f"Failed to build the current revision: '{bolt_path}'")
138+
139+
# Rename llvm-bolt and memorize the old hash for logging.
99140
os.replace(bolt_path, f"{bolt_path}.new")
100-
# memorize the old hash for logging
101141
old_ref = get_git_ref_or_rev(source_dir)
102142

103143
if args.check_bolt_sources:
@@ -110,7 +150,7 @@ def main():
110150
print(f"BOLT source changes were found:\n{file_changes}")
111151
open(marker, "a").close()
112152

113-
# determine whether a stash is needed
153+
# Determine whether a stash is needed.
114154
stash = subprocess.run(
115155
shlex.split("git status --porcelain"),
116156
cwd=source_dir,
@@ -119,42 +159,59 @@ def main():
119159
text=True,
120160
).stdout
121161
if stash:
122-
# save local changes before checkout
162+
# Save local changes before checkout.
123163
subprocess.run(shlex.split("git stash push -u"), cwd=source_dir)
124-
# check out the previous/cmp commit
164+
165+
# Check out the previous/cmp commit and get its commit hash for logging.
125166
subprocess.run(shlex.split(f"git checkout -f {args.cmp_rev}"), cwd=source_dir)
126-
# get the parent commit hash for logging
127167
new_ref = get_git_ref_or_rev(source_dir)
128-
# build the previous commit
168+
169+
# Build the previous commit.
170+
print(f"{msg_prefix} Building previous revision..")
129171
subprocess.run(
130172
shlex.split("cmake --build . --target llvm-bolt"), cwd=args.build_dir
131173
)
132-
# rename llvm-bolt
174+
175+
# Rename llvm-bolt.
176+
if not os.path.exists(bolt_path):
177+
print(f"Failed to build the previous revision: '{bolt_path}'")
178+
switch_back(args.switch_back, stash, source_dir, old_ref, new_ref)
179+
sys.exit(1)
133180
os.replace(bolt_path, f"{bolt_path}.old")
134-
# set up llvm-bolt-wrapper.ini
135-
ini = subprocess.check_output(
136-
shlex.split(f"{wrapper_path} {bolt_path}.old {bolt_path}.new") + wrapper_args,
137-
text=True,
181+
182+
# Symlink llvm-bolt-wrapper
183+
if args.create_wrapper:
184+
print(f"{msg_prefix} Creating llvm-bolt wrapper..")
185+
script_dir = os.path.dirname(os.path.abspath(__file__))
186+
wrapper_path = f"{script_dir}/llvm-bolt-wrapper.py"
187+
try:
188+
# Set up llvm-bolt-wrapper.ini
189+
ini = subprocess.check_output(
190+
shlex.split(f"{wrapper_path} {bolt_path}.old {bolt_path}.new")
191+
+ wrapper_args,
192+
text=True,
193+
)
194+
with open(f"{args.build_dir}/bin/llvm-bolt-wrapper.ini", "w") as f:
195+
f.write(ini)
196+
os.symlink(wrapper_path, bolt_path)
197+
except Exception as e:
198+
print("Failed to create a wrapper:\n" + str(e))
199+
switch_back(args.switch_back, stash, source_dir, old_ref, new_ref)
200+
sys.exit(1)
201+
202+
switch_back(args.switch_back, stash, source_dir, old_ref, new_ref)
203+
204+
print(
205+
f"{msg_prefix} Completed!\nBuild directory {args.build_dir} is ready for"
206+
" NFC-Mode comparison between the two revisions."
138207
)
139-
with open(f"{args.build_dir}/bin/llvm-bolt-wrapper.ini", "w") as f:
140-
f.write(ini)
141-
# symlink llvm-bolt-wrapper
142-
os.symlink(wrapper_path, bolt_path)
143-
if args.switch_back:
144-
if stash:
145-
subprocess.run(shlex.split("git stash pop"), cwd=source_dir)
146-
subprocess.run(shlex.split(f"git checkout {old_ref}"), cwd=source_dir)
147-
else:
208+
209+
if args.create_wrapper:
148210
print(
149-
f"The repository {source_dir} has been switched from {old_ref} "
150-
f"to {new_ref}. Local changes were stashed. Switch back using\n\t"
151-
f"git checkout {old_ref}\n"
211+
"Can run BOLT tests using:\n"
212+
"\tbin/llvm-lit -sv tools/bolt/test\nor\n"
213+
"\tbin/llvm-lit -sv tools/bolttests"
152214
)
153-
print(
154-
f"Build directory {args.build_dir} is ready to run BOLT tests, e.g.\n"
155-
"\tbin/llvm-lit -sv tools/bolt/test\nor\n"
156-
"\tbin/llvm-lit -sv tools/bolttests"
157-
)
158215

159216

160217
if __name__ == "__main__":

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

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static Matcher<Stmt> loopEndingStmt(Matcher<Stmt> Internal) {
4949
}
5050

5151
/// Return whether `Var` was changed in `LoopStmt`.
52-
static bool isChanged(const Stmt *LoopStmt, const VarDecl *Var,
52+
static bool isChanged(const Stmt *LoopStmt, const ValueDecl *Var,
5353
ASTContext *Context) {
5454
if (const auto *ForLoop = dyn_cast<ForStmt>(LoopStmt))
5555
return (ForLoop->getInc() &&
@@ -64,24 +64,35 @@ static bool isChanged(const Stmt *LoopStmt, const VarDecl *Var,
6464
return ExprMutationAnalyzer(*LoopStmt, *Context).isMutated(Var);
6565
}
6666

67+
static bool isVarPossiblyChanged(const Decl *Func, const Stmt *LoopStmt,
68+
const ValueDecl *VD, ASTContext *Context) {
69+
const VarDecl *Var = nullptr;
70+
if (const auto *VarD = dyn_cast<VarDecl>(VD)) {
71+
Var = VarD;
72+
} else if (const auto *BD = dyn_cast<BindingDecl>(VD)) {
73+
if (const auto *DD = dyn_cast<DecompositionDecl>(BD->getDecomposedDecl()))
74+
Var = DD;
75+
}
76+
77+
if (!Var)
78+
return false;
79+
80+
if (!Var->isLocalVarDeclOrParm() || Var->getType().isVolatileQualified())
81+
return true;
82+
83+
if (!VD->getType().getTypePtr()->isIntegerType())
84+
return true;
85+
86+
return hasPtrOrReferenceInFunc(Func, VD) || isChanged(LoopStmt, VD, Context);
87+
// FIXME: Track references.
88+
}
89+
6790
/// Return whether `Cond` is a variable that is possibly changed in `LoopStmt`.
6891
static bool isVarThatIsPossiblyChanged(const Decl *Func, const Stmt *LoopStmt,
6992
const Stmt *Cond, ASTContext *Context) {
7093
if (const auto *DRE = dyn_cast<DeclRefExpr>(Cond)) {
71-
if (const auto *Var = dyn_cast<VarDecl>(DRE->getDecl())) {
72-
if (!Var->isLocalVarDeclOrParm())
73-
return true;
74-
75-
if (Var->getType().isVolatileQualified())
76-
return true;
77-
78-
if (!Var->getType().getTypePtr()->isIntegerType())
79-
return true;
80-
81-
return hasPtrOrReferenceInFunc(Func, Var) ||
82-
isChanged(LoopStmt, Var, Context);
83-
// FIXME: Track references.
84-
}
94+
if (const auto *VD = dyn_cast<ValueDecl>(DRE->getDecl()))
95+
return isVarPossiblyChanged(Func, LoopStmt, VD, Context);
8596
} else if (isa<MemberExpr, CallExpr, ObjCIvarRefExpr, ObjCPropertyRefExpr,
8697
ObjCMessageExpr>(Cond)) {
8798
// FIXME: Handle MemberExpr.
@@ -123,6 +134,10 @@ static std::string getCondVarNames(const Stmt *Cond) {
123134
if (const auto *DRE = dyn_cast<DeclRefExpr>(Cond)) {
124135
if (const auto *Var = dyn_cast<VarDecl>(DRE->getDecl()))
125136
return std::string(Var->getName());
137+
138+
if (const auto *BD = dyn_cast<BindingDecl>(DRE->getDecl())) {
139+
return std::string(BD->getName());
140+
}
126141
}
127142

128143
std::string Result;
@@ -214,10 +229,17 @@ static bool overlap(ArrayRef<CallGraphNode *> SCC,
214229

215230
/// returns true iff `Cond` involves at least one static local variable.
216231
static bool hasStaticLocalVariable(const Stmt *Cond) {
217-
if (const auto *DRE = dyn_cast<DeclRefExpr>(Cond))
232+
if (const auto *DRE = dyn_cast<DeclRefExpr>(Cond)) {
218233
if (const auto *VD = dyn_cast<VarDecl>(DRE->getDecl()))
219234
if (VD->isStaticLocal())
220235
return true;
236+
237+
if (const auto *BD = dyn_cast<BindingDecl>(DRE->getDecl()))
238+
if (const auto *DD = dyn_cast<DecompositionDecl>(BD->getDecomposedDecl()))
239+
if (DD->isStaticLocal())
240+
return true;
241+
}
242+
221243
for (const Stmt *Child : Cond->children())
222244
if (Child && hasStaticLocalVariable(Child))
223245
return true;

0 commit comments

Comments
 (0)