Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e84f811

Browse files
authored
Merge branch 'main' into refactoring/using-enums-yaml
2 parents 3ebaa29 + 13ae9ea commit e84f811

File tree

12 files changed

+163
-40
lines changed

12 files changed

+163
-40
lines changed

.github/workflows/libcxx-run-benchmarks.yml

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
name: Benchmark libc++
1111

1212
permissions:
13-
contents: read # Default everything to read-only
13+
contents: read
1414

1515
on:
1616
issue_comment:
@@ -24,6 +24,9 @@ env:
2424

2525
jobs:
2626
run-benchmarks:
27+
permissions:
28+
pull-requests: write
29+
2730
if: >-
2831
github.event.issue.pull_request &&
2932
contains(github.event.comment.body, '/libcxx-bot benchmark')
@@ -40,6 +43,7 @@ jobs:
4043
python3 -m venv .venv
4144
source .venv/bin/activate
4245
python -m pip install pygithub
46+
4347
cat <<EOF | python >> ${GITHUB_OUTPUT}
4448
import github
4549
repo = github.Github("${{ github.token }}").get_repo("${{ github.repository }}")
@@ -59,18 +63,47 @@ jobs:
5963

6064
- name: Run baseline
6165
run: |
62-
source .venv/bin/activate
63-
python -m pip install -r repo/libcxx/utils/requirements.txt
64-
baseline_commit=$(git -C repo merge-base ${{ steps.vars.outputs.pr_base }} ${{ steps.vars.outputs.pr_head }})
65-
./repo/libcxx/utils/test-at-commit --git-repo repo --commit ${baseline_commit} -B build/baseline -- -sv -j1 --param optimization=speed ${{ steps.vars.outputs.benchmarks }}
66+
source .venv/bin/activate && cd repo
67+
python -m pip install -r libcxx/utils/requirements.txt
68+
baseline_commit=$(git merge-base ${{ steps.vars.outputs.pr_base }} ${{ steps.vars.outputs.pr_head }})
69+
./libcxx/utils/test-at-commit --commit ${baseline_commit} -B build/baseline -- -sv -j1 --param optimization=speed ${{ steps.vars.outputs.benchmarks }}
6670
6771
- name: Run candidate
6872
run: |
69-
source .venv/bin/activate
70-
./repo/libcxx/utils/test-at-commit --git-repo repo --commit ${{ steps.vars.outputs.pr_head }} -B build/candidate -- -sv -j1 --param optimization=speed ${{ steps.vars.outputs.benchmarks }}
73+
source .venv/bin/activate && cd repo
74+
./libcxx/utils/test-at-commit --commit ${{ steps.vars.outputs.pr_head }} -B build/candidate -- -sv -j1 --param optimization=speed ${{ steps.vars.outputs.benchmarks }}
7175
7276
- name: Compare baseline and candidate runs
7377
run: |
74-
source .venv/bin/activate
75-
./repo/libcxx/utils/compare-benchmarks <(./repo/libcxx/utils/consolidate-benchmarks build/baseline) \
76-
<(./repo/libcxx/utils/consolidate-benchmarks build/candidate)
78+
source .venv/bin/activate && cd repo
79+
./libcxx/utils/compare-benchmarks <(./libcxx/utils/consolidate-benchmarks build/baseline) \
80+
<(./libcxx/utils/consolidate-benchmarks build/candidate) > results.txt
81+
82+
- name: Update comment with results
83+
run: |
84+
source .venv/bin/activate && cd repo
85+
cat <<EOF | python
86+
import github
87+
repo = github.Github("${{ github.token }}").get_repo("${{ github.repository }}")
88+
pr = repo.get_pull(${{ github.event.issue.number }})
89+
comment = pr.get_issue_comment(${{ github.event.comment.id }})
90+
with open('results.txt', 'r') as f:
91+
benchmark_results = f.read()
92+
93+
new_comment_text = f"""
94+
{comment.body}
95+
96+
<details>
97+
<summary>
98+
Benchmark results:
99+
</summary>
100+
101+
\`\`\`
102+
{benchmark_results}
103+
\`\`\`
104+
105+
</details>
106+
"""
107+
108+
comment.edit(new_comment_text)
109+
EOF

clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,24 @@ bool tryToFindPtrOrigin(
161161
Name == "NSClassFromString")
162162
return callback(E, true);
163163
}
164+
165+
// Sometimes, canonical type erroneously turns Ref<T> into T.
166+
// Workaround this problem by checking again if the original type was
167+
// a SubstTemplateTypeParmType of a safe smart pointer type (e.g. Ref).
168+
if (auto *CalleeDecl = call->getCalleeDecl()) {
169+
if (auto *FD = dyn_cast<FunctionDecl>(CalleeDecl)) {
170+
auto RetType = FD->getReturnType();
171+
if (auto *Subst = dyn_cast<SubstTemplateTypeParmType>(RetType)) {
172+
if (auto *SubstType = Subst->desugar().getTypePtr()) {
173+
if (auto *RD = dyn_cast<RecordType>(SubstType)) {
174+
if (auto *CXX = dyn_cast<CXXRecordDecl>(RD->getOriginalDecl()))
175+
if (isSafePtr(CXX))
176+
return callback(E, true);
177+
}
178+
}
179+
}
180+
}
181+
}
164182
}
165183
if (auto *ObjCMsgExpr = dyn_cast<ObjCMessageExpr>(E)) {
166184
if (auto *Method = ObjCMsgExpr->getMethodDecl()) {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
2+
// expected-no-diagnostics
3+
4+
#include "mock-types.h"
5+
6+
struct Obj {
7+
void ref() const;
8+
void deref() const;
9+
10+
void someFunction();
11+
};
12+
13+
template<typename T> class Wrapper {
14+
public:
15+
T obj();
16+
};
17+
18+
static void foo(Wrapper<Ref<Obj>>&& wrapper)
19+
{
20+
wrapper.obj()->someFunction();
21+
}

lldb/test/API/commands/dwim-print/TestDWIMPrint.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def _run_cmd(self, cmd: str) -> str:
1616
self.ci.HandleCommand(cmd, result)
1717
return result.GetOutput().rstrip()
1818

19-
VAR_IDENT = re.compile(r"(?:\$\d+|[\w.]+) = ")
19+
VAR_IDENT = re.compile(r"(?:\$\d+|(?:::)?[\w.]+) = ")
2020

2121
def _strip_result_var(self, string: str) -> str:
2222
"""
@@ -185,3 +185,11 @@ def test_direct_child_access(self):
185185
self, "break inside", lldb.SBFileSpec("main.cpp")
186186
)
187187
self._expect_cmd("dwim-print number", "frame variable")
188+
189+
def test_global_variables(self):
190+
"""Test dwim-print supports global variables."""
191+
self.build()
192+
lldbutil.run_to_source_breakpoint(
193+
self, "break here", lldb.SBFileSpec("main.cpp")
194+
)
195+
self._expect_cmd("dwim-print gGlobal", "frame variable")

lldb/test/API/commands/dwim-print/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
extern "C" int puts(const char *s);
22

3+
extern int gGlobal;
4+
int gGlobal = 23;
5+
36
struct Structure {
47
int number = 30;
58
void f() { puts("break inside"); }

llvm/test/TableGen/FixedLenDecoderEmitter/additional-encoding.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,22 @@ class I<dag out_ops, dag in_ops> : Instruction {
3535
// CHECK-NEXT: /* 7 */ MCD::OPC_Scope, 8, 0, // Skip to: 18
3636
// CHECK-NEXT: /* 10 */ MCD::OPC_CheckField, 6, 6, 0,
3737
// CHECK-NEXT: /* 14 */ MCD::OPC_Decode, {{[0-9]+}}, 2, 0, // Opcode: {{.*}}:NOP, DecodeIdx: 0
38-
// CHECK-NEXT: /* 18 */ MCD::OPC_TryDecode, 187, 2, 1,
38+
// CHECK-NEXT: /* 18 */ MCD::OPC_TryDecode, {{[0-9]+}}, 2, 1,
3939
// CHECK-NEXT: /* 22 */ MCD::OPC_FilterValueOrSkip, 1, 15, 0, // Skip to: 41
4040
// CHECK-NEXT: /* 26 */ MCD::OPC_Scope, 8, 0, // Skip to: 37
4141
// CHECK-NEXT: /* 29 */ MCD::OPC_CheckField, 6, 6, 0,
4242
// CHECK-NEXT: /* 33 */ MCD::OPC_Decode, {{[0-9]+}}, 2, 0, // Opcode: {{.*}}:NOP, DecodeIdx: 0
43-
// CHECK-NEXT: /* 37 */ MCD::OPC_TryDecode, 188, 2, 1,
43+
// CHECK-NEXT: /* 37 */ MCD::OPC_TryDecode, {{[0-9]+}}, 2, 1,
4444
// CHECK-NEXT: /* 41 */ MCD::OPC_FilterValueOrSkip, 2, 15, 0, // Skip to: 60
4545
// CHECK-NEXT: /* 45 */ MCD::OPC_Scope, 8, 0, // Skip to: 56
4646
// CHECK-NEXT: /* 48 */ MCD::OPC_CheckField, 6, 6, 0,
4747
// CHECK-NEXT: /* 52 */ MCD::OPC_Decode, {{[0-9]+}}, 2, 0, // Opcode: {{.*}}:NOP, DecodeIdx: 0
48-
// CHECK-NEXT: /* 56 */ MCD::OPC_TryDecode, 189, 2, 1,
48+
// CHECK-NEXT: /* 56 */ MCD::OPC_TryDecode, {{[0-9]+}}, 2, 1,
4949
// CHECK-NEXT: /* 60 */ MCD::OPC_FilterValue, 3,
5050
// CHECK-NEXT: /* 62 */ MCD::OPC_Scope, 8, 0, // Skip to: 73
5151
// CHECK-NEXT: /* 65 */ MCD::OPC_CheckField, 6, 6, 0,
5252
// CHECK-NEXT: /* 69 */ MCD::OPC_Decode, {{[0-9]+}}, 2, 0, // Opcode: {{.*}}:NOP, DecodeIdx: 0
53-
// CHECK-NEXT: /* 73 */ MCD::OPC_TryDecode, 190, 2, 1,
53+
// CHECK-NEXT: /* 73 */ MCD::OPC_TryDecode, {{[0-9]+}}, 2, 1,
5454

5555

5656
class SHIFT<bits<2> opc> : I<(outs), (ins ShAmtOp:$shamt)>, EncSHIFT<opc>;

llvm/utils/lit/lit/DiffUpdater.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import shutil
22
import os
33
import shlex
4+
import pathlib
45

56
"""
67
This file provides the `diff_test_updater` function, which is invoked on failed RUN lines when lit is executed with --update-tests.
@@ -76,14 +77,12 @@ def get_target_dir(commands, test_path):
7677

7778
@staticmethod
7879
def create(path, commands, test_path, target_dir):
79-
filename = path.replace(target_dir, "")
80-
if filename.startswith(os.sep):
81-
filename = filename[len(os.sep) :]
80+
path = pathlib.Path(path)
8281
with open(test_path, "r") as f:
8382
lines = f.readlines()
8483
for i, l in enumerate(lines):
8584
p = SplitFileTarget._get_split_line_path(l)
86-
if p == filename:
85+
if p and path.samefile(os.path.join(target_dir, p)):
8786
idx = i
8887
break
8988
else:

mlir/include/mlir/Analysis/DataFlow/DeadCodeAnalysis.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,13 @@ class DeadCodeAnalysis : public DataFlowAnalysis {
229229
/// considered an external callable.
230230
Operation *analysisScope;
231231

232+
/// Whether the analysis scope has a symbol table. This is used to avoid
233+
/// resolving callables outside the analysis scope.
234+
/// It is updated when recursing into a region in case where the top-level
235+
/// operation does not have a symbol table, but one is encountered in a nested
236+
/// region.
237+
bool hasSymbolTable = false;
238+
232239
/// A symbol table used for O(1) symbol lookups during simplification.
233240
SymbolTableCollection symbolTable;
234241
};

mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "mlir/Interfaces/CallInterfaces.h"
2323
#include "mlir/Interfaces/ControlFlowInterfaces.h"
2424
#include "mlir/Support/LLVM.h"
25+
#include "llvm/ADT/ScopeExit.h"
2526
#include "llvm/Support/Casting.h"
2627
#include "llvm/Support/Debug.h"
2728
#include "llvm/Support/DebugLog.h"
@@ -159,6 +160,7 @@ void DeadCodeAnalysis::initializeSymbolCallables(Operation *top) {
159160
LDBG() << "[init] Entering initializeSymbolCallables for top-level op: "
160161
<< OpWithFlags(top, OpPrintingFlags().skipRegions());
161162
analysisScope = top;
163+
hasSymbolTable = top->hasTrait<OpTrait::SymbolTable>();
162164
auto walkFn = [&](Operation *symTable, bool allUsesVisible) {
163165
LDBG() << "[init] Processing symbol table op: "
164166
<< OpWithFlags(symTable, OpPrintingFlags().skipRegions());
@@ -260,14 +262,25 @@ LogicalResult DeadCodeAnalysis::initializeRecursively(Operation *op) {
260262
return failure();
261263
}
262264
// Recurse on nested operations.
263-
for (Region &region : op->getRegions()) {
264-
LDBG() << "[init] Recursing into region of op: "
265-
<< OpWithFlags(op, OpPrintingFlags().skipRegions());
266-
for (Operation &nestedOp : region.getOps()) {
267-
LDBG() << "[init] Recursing into nested op: "
268-
<< OpWithFlags(&nestedOp, OpPrintingFlags().skipRegions());
269-
if (failed(initializeRecursively(&nestedOp)))
270-
return failure();
265+
if (op->getNumRegions()) {
266+
// If we haven't seen a symbol table yet, check if the current operation
267+
// has one. If so, update the flag to allow for resolving callables in
268+
// nested regions.
269+
bool savedHasSymbolTable = hasSymbolTable;
270+
auto restoreHasSymbolTable =
271+
llvm::make_scope_exit([&]() { hasSymbolTable = savedHasSymbolTable; });
272+
if (!hasSymbolTable && op->hasTrait<OpTrait::SymbolTable>())
273+
hasSymbolTable = true;
274+
275+
for (Region &region : op->getRegions()) {
276+
LDBG() << "[init] Recursing into region of op: "
277+
<< OpWithFlags(op, OpPrintingFlags().skipRegions());
278+
for (Operation &nestedOp : region.getOps()) {
279+
LDBG() << "[init] Recursing into nested op: "
280+
<< OpWithFlags(&nestedOp, OpPrintingFlags().skipRegions());
281+
if (failed(initializeRecursively(&nestedOp)))
282+
return failure();
283+
}
271284
}
272285
}
273286
LDBG() << "[init] Finished initializeRecursively for op: "
@@ -388,7 +401,13 @@ LogicalResult DeadCodeAnalysis::visit(ProgramPoint *point) {
388401
void DeadCodeAnalysis::visitCallOperation(CallOpInterface call) {
389402
LDBG() << "visitCallOperation: "
390403
<< OpWithFlags(call.getOperation(), OpPrintingFlags().skipRegions());
391-
Operation *callableOp = call.resolveCallableInTable(&symbolTable);
404+
405+
Operation *callableOp = nullptr;
406+
if (hasSymbolTable)
407+
callableOp = call.resolveCallableInTable(&symbolTable);
408+
else
409+
LDBG()
410+
<< "No symbol table present in analysis scope, can't resolve callable";
392411

393412
// A call to a externally-defined callable has unknown predecessors.
394413
const auto isExternalCallable = [this](Operation *op) {

mlir/lib/Analysis/DataFlow/DenseAnalysis.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,12 @@ void AbstractDenseForwardDataFlowAnalysis::visitCallOperation(
6464
AbstractDenseLattice *after) {
6565
// Allow for customizing the behavior of calls to external symbols, including
6666
// when the analysis is explicitly marked as non-interprocedural.
67-
auto callable =
68-
dyn_cast_if_present<CallableOpInterface>(call.resolveCallable());
69-
if (!getSolverConfig().isInterprocedural() ||
70-
(callable && !callable.getCallableRegion())) {
67+
auto isExternalCallable = [&]() {
68+
auto callable =
69+
dyn_cast_if_present<CallableOpInterface>(call.resolveCallable());
70+
return callable && !callable.getCallableRegion();
71+
};
72+
if (!getSolverConfig().isInterprocedural() || isExternalCallable()) {
7173
return visitCallControlFlowTransfer(
7274
call, CallControlFlowAction::ExternalCallee, before, after);
7375
}
@@ -290,19 +292,23 @@ AbstractDenseBackwardDataFlowAnalysis::visit(ProgramPoint *point) {
290292
void AbstractDenseBackwardDataFlowAnalysis::visitCallOperation(
291293
CallOpInterface call, const AbstractDenseLattice &after,
292294
AbstractDenseLattice *before) {
295+
// If the solver is not interprocedural, let the hook handle it as an external
296+
// callee.
297+
if (!getSolverConfig().isInterprocedural())
298+
return visitCallControlFlowTransfer(
299+
call, CallControlFlowAction::ExternalCallee, after, before);
300+
293301
// Find the callee.
294302
Operation *callee = call.resolveCallableInTable(&symbolTable);
295303

296304
auto callable = dyn_cast_or_null<CallableOpInterface>(callee);
297305
// No region means the callee is only declared in this module.
298306
// If that is the case or if the solver is not interprocedural,
299307
// let the hook handle it.
300-
if (!getSolverConfig().isInterprocedural() ||
301-
(callable && (!callable.getCallableRegion() ||
302-
callable.getCallableRegion()->empty()))) {
308+
if (callable &&
309+
(!callable.getCallableRegion() || callable.getCallableRegion()->empty()))
303310
return visitCallControlFlowTransfer(
304311
call, CallControlFlowAction::ExternalCallee, after, before);
305-
}
306312

307313
if (!callable)
308314
return setToExitState(before);

0 commit comments

Comments
 (0)