Skip to content

Commit f68561b

Browse files
authored
Merge branch 'main' into aarch64-bti-ehpad
2 parents 38698e6 + 7234ae6 commit f68561b

File tree

1,449 files changed

+64783
-37521
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,449 files changed

+64783
-37521
lines changed

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;

clang-tools-extra/clang-tidy/utils/Aliasing.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@
1414
namespace clang::tidy::utils {
1515

1616
/// Return whether \p S is a reference to the declaration of \p Var.
17-
static bool isAccessForVar(const Stmt *S, const VarDecl *Var) {
17+
static bool isAccessForVar(const Stmt *S, const ValueDecl *Var) {
1818
if (const auto *DRE = dyn_cast<DeclRefExpr>(S))
1919
return DRE->getDecl() == Var;
2020

2121
return false;
2222
}
2323

24-
static bool capturesByRef(const CXXRecordDecl *RD, const VarDecl *Var) {
24+
static bool capturesByRef(const CXXRecordDecl *RD, const ValueDecl *Var) {
2525
return llvm::any_of(RD->captures(), [Var](const LambdaCapture &C) {
2626
return C.capturesVariable() && C.getCaptureKind() == LCK_ByRef &&
2727
C.getCapturedVar() == Var;
2828
});
2929
}
3030

3131
/// Return whether \p Var has a pointer or reference in \p S.
32-
static bool isPtrOrReferenceForVar(const Stmt *S, const VarDecl *Var) {
32+
static bool isPtrOrReferenceForVar(const Stmt *S, const ValueDecl *Var) {
3333
// Treat block capture by reference as a form of taking a reference.
34-
if (Var->isEscapingByref())
34+
if (const auto *VD = dyn_cast<VarDecl>(Var); VD && VD->isEscapingByref())
3535
return true;
3636

3737
if (const auto *DS = dyn_cast<DeclStmt>(S)) {
@@ -61,7 +61,7 @@ static bool isPtrOrReferenceForVar(const Stmt *S, const VarDecl *Var) {
6161
}
6262

6363
/// Return whether \p Var has a pointer or reference in \p S.
64-
static bool hasPtrOrReferenceInStmt(const Stmt *S, const VarDecl *Var) {
64+
static bool hasPtrOrReferenceInStmt(const Stmt *S, const ValueDecl *Var) {
6565
if (isPtrOrReferenceForVar(S, Var))
6666
return true;
6767

@@ -77,7 +77,7 @@ static bool hasPtrOrReferenceInStmt(const Stmt *S, const VarDecl *Var) {
7777
}
7878

7979
static bool refersToEnclosingLambdaCaptureByRef(const Decl *Func,
80-
const VarDecl *Var) {
80+
const ValueDecl *Var) {
8181
const auto *MD = dyn_cast<CXXMethodDecl>(Func);
8282
if (!MD)
8383
return false;
@@ -89,7 +89,7 @@ static bool refersToEnclosingLambdaCaptureByRef(const Decl *Func,
8989
return capturesByRef(RD, Var);
9090
}
9191

92-
bool hasPtrOrReferenceInFunc(const Decl *Func, const VarDecl *Var) {
92+
bool hasPtrOrReferenceInFunc(const Decl *Func, const ValueDecl *Var) {
9393
return hasPtrOrReferenceInStmt(Func->getBody(), Var) ||
9494
refersToEnclosingLambdaCaptureByRef(Func, Var);
9595
}

clang-tools-extra/clang-tidy/utils/Aliasing.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace clang::tidy::utils {
2525
/// For `f()` and `n` the function returns ``true`` because `p` is a
2626
/// pointer to `n` created in `f()`.
2727

28-
bool hasPtrOrReferenceInFunc(const Decl *Func, const VarDecl *Var);
28+
bool hasPtrOrReferenceInFunc(const Decl *Func, const ValueDecl *Var);
2929

3030
} // namespace clang::tidy::utils
3131

clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@ set(LLVM_LINK_COMPONENTS
1414
add_clang_library(clangDaemonTweaks OBJECT
1515
AddUsing.cpp
1616
AnnotateHighlightings.cpp
17-
DumpAST.cpp
1817
DefineInline.cpp
1918
DefineOutline.cpp
19+
DumpAST.cpp
2020
ExpandDeducedType.cpp
2121
ExpandMacro.cpp
2222
ExtractFunction.cpp
2323
ExtractVariable.cpp
2424
MemberwiseConstructor.cpp
2525
ObjCLocalizeStringLiteral.cpp
2626
ObjCMemberwiseInitializer.cpp
27+
OverridePureVirtuals.cpp
2728
PopulateSwitch.cpp
2829
RawStringLiteral.cpp
2930
RemoveUsingNamespace.cpp

0 commit comments

Comments
 (0)