Skip to content

Commit db2a306

Browse files
authored
Merge pull request #69080 from nate-chandler/test/20231009/1/stdout
[Test] Print to stdout.
2 parents ccaf427 + 9ca6b9a commit db2a306

19 files changed

+71
-79
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/Test.swift

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ private func functionTestThunk(
164164
let invocation = castToInvocation(fromOpaquePointer: erasedInvocation)
165165
let context = FunctionPassContext(_bridged: BridgedPassContext(invocation: passInvocation.invocation))
166166
invocation(function.function, arguments.native, context)
167+
fflush(stdout)
167168
}
168169

169170
/// Bitcast a thin test closure to void *.
@@ -202,46 +203,36 @@ private func castToInvocation(fromOpaquePointer erasedInvocation: UnsafeMutableR
202203
// - something to identify the instance (mostly this means calling dump)
203204
let parseTestSpecificationTest =
204205
FunctionTest(name: "test_specification_parsing") { function, arguments, context in
205-
struct _Stderr : TextOutputStream {
206-
public init() {}
207-
208-
public mutating func write(_ string: String) {
209-
for c in string.utf8 {
210-
writeCharToStderr(CInt(c))
211-
}
212-
}
213-
}
214-
var stderr = _Stderr()
215206
let expectedFields = arguments.takeString()
216207
for expectedField in expectedFields.string {
217208
switch expectedField {
218209
case "A":
219210
let argument = arguments.takeArgument()
220-
print("argument:\n\(argument)", to: &stderr)
211+
print("argument:\n\(argument)")
221212
case "F":
222213
let function = arguments.takeFunction()
223-
print("function: \(function.name)", to: &stderr)
214+
print("function: \(function.name)")
224215
case "B":
225216
let block = arguments.takeBlock()
226-
print("block:\n\(block)", to: &stderr)
217+
print("block:\n\(block)")
227218
case "I":
228219
let instruction = arguments.takeInstruction()
229-
print("instruction: \(instruction)", to: &stderr)
220+
print("instruction: \(instruction)")
230221
case "V":
231222
let value = arguments.takeValue()
232-
print("value: \(value)", to: &stderr)
223+
print("value: \(value)")
233224
case "O":
234225
let operand = arguments.takeOperand()
235-
print("operand: \(operand)", to: &stderr)
226+
print("operand: \(operand)")
236227
case "u":
237228
let u = arguments.takeInt()
238-
print("uint: \(u)", to: &stderr)
229+
print("uint: \(u)")
239230
case "b":
240231
let b = arguments.takeBool()
241-
print("bool: \(b)", to: &stderr)
232+
print("bool: \(b)")
242233
case "s":
243234
let s = arguments.takeString()
244-
print("string: \(s)", to: &stderr)
235+
print("string: \(s)")
245236
default:
246237
fatalError("unknown field type was expected?!");
247238
}

lib/SIL/IR/SILValue.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ static FunctionTest IsLexicalTest("is-lexical", [](auto &function,
166166
auto &test) {
167167
auto value = arguments.takeValue();
168168
auto isLexical = value->isLexical();
169-
value->dump();
169+
value->print(llvm::outs());
170170
auto *boolString = isLexical ? "true" : "false";
171-
llvm::errs() << boolString << "\n";
171+
llvm::outs() << boolString << "\n";
172172
});
173173
} // end namespace swift::test
174174

lib/SIL/IR/TypeLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2758,7 +2758,7 @@ static FunctionTest PrintTypeLowering("print-type-lowering", [](auto &function,
27582758
auto &test) {
27592759
auto value = arguments.takeValue();
27602760
auto ty = value->getType();
2761-
function.getModule().Types.getTypeLowering(ty, function).print(llvm::dbgs());
2761+
function.getModule().Types.getTypeLowering(ty, function).print(llvm::outs());
27622762
});
27632763
} // end namespace swift::test
27642764

lib/SIL/Utils/FieldSensitivePrunedLiveness.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,12 +1024,12 @@ static FunctionTest FieldSensitiveMultiDefUseLiveRangeTest(
10241024
TypeTreeLeafTypeRange range(begin, end);
10251025
liveness.updateForUse(inst, range, lifetimeEnding);
10261026
}
1027-
liveness.print(llvm::errs());
1027+
liveness.print(llvm::outs());
10281028

10291029
FieldSensitivePrunedLivenessBoundary boundary(
10301030
liveness.getNumSubElements());
10311031
liveness.computeBoundary(boundary);
1032-
boundary.print(llvm::errs());
1032+
boundary.print(llvm::outs());
10331033
});
10341034
} // end namespace swift::test
10351035

lib/SIL/Utils/MemAccessUtils.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -375,10 +375,10 @@ static FunctionTest
375375
GetTypedAccessAddress("get_typed_access_address",
376376
[](auto &function, auto &arguments, auto &test) {
377377
auto address = arguments.takeValue();
378-
function.dump();
379-
llvm::dbgs() << "Address: " << address;
378+
function.print(llvm::outs());
379+
llvm::outs() << "Address: " << address;
380380
auto access = getTypedAccessAddress(address);
381-
llvm::dbgs() << "Access: " << access;
381+
llvm::outs() << "Access: " << access;
382382
});
383383
} // end namespace swift::test
384384

@@ -404,10 +404,10 @@ static FunctionTest GetAccessBaseTest("get_access_base",
404404
[](auto &function, auto &arguments,
405405
auto &test) {
406406
auto address = arguments.takeValue();
407-
function.dump();
408-
llvm::dbgs() << "Address: " << address;
407+
function.print(llvm::outs());
408+
llvm::outs() << "Address: " << address;
409409
auto base = getAccessBase(address);
410-
llvm::dbgs() << "Base: " << base;
410+
llvm::outs() << "Base: " << base;
411411
});
412412
} // end namespace swift::test
413413

@@ -1196,10 +1196,10 @@ static FunctionTest ComputeAccessStorage("compute_access_storage",
11961196
[](auto &function, auto &arguments,
11971197
auto &test) {
11981198
auto address = arguments.takeValue();
1199-
function.dump();
1200-
llvm::dbgs() << "Address: " << address;
1199+
function.print(llvm::outs());
1200+
llvm::outs() << "Address: " << address;
12011201
auto accessStorage = AccessStorage::compute(address);
1202-
accessStorage.dump();
1202+
accessStorage.print(llvm::outs());
12031203
});
12041204
} // end namespace swift::test
12051205

@@ -2070,7 +2070,7 @@ static FunctionTest AccessPathBaseTest("accesspath-base", [](auto &function,
20702070
auto &arguments,
20712071
auto &test) {
20722072
auto value = arguments.takeValue();
2073-
function.dump();
2073+
function.print(llvm::outs());
20742074
llvm::outs() << "Access path base: " << value;
20752075
auto accessPathWithBase = AccessPathWithBase::compute(value);
20762076
AccessUseTestVisitor visitor;

lib/SIL/Utils/OSSALifetimeCompletion.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,10 @@ static FunctionTest OSSALifetimeCompletionTest(
364364
"ossa-lifetime-completion",
365365
[](auto &function, auto &arguments, auto &test) {
366366
SILValue value = arguments.takeValue();
367-
llvm::dbgs() << "OSSA lifetime completion: " << value;
367+
llvm::outs() << "OSSA lifetime completion: " << value;
368368
OSSALifetimeCompletion completion(&function, /*domInfo*/ nullptr);
369369
completion.completeOSSALifetime(value);
370-
function.dump();
370+
function.print(llvm::outs());
371371
});
372372
} // end namespace swift::test
373373

lib/SIL/Utils/OwnershipLiveness.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,8 @@ static FunctionTest LinearLivenessTest("linear-liveness", [](auto &function,
378378
auto &arguments,
379379
auto &test) {
380380
SILValue value = arguments.takeValue();
381-
function.dump();
382-
llvm::dbgs() << "Linear liveness: " << value;
381+
function.print(llvm::outs());
382+
llvm::outs() << "Linear liveness: " << value;
383383
LinearLiveness liveness(value);
384384
liveness.compute();
385385
liveness.print(llvm::outs());
@@ -399,8 +399,8 @@ static FunctionTest
399399
InteriorLivenessTest("interior-liveness",
400400
[](auto &function, auto &arguments, auto &test) {
401401
SILValue value = arguments.takeValue();
402-
function.dump();
403-
llvm::dbgs() << "Interior liveness: " << value;
402+
function.print(llvm::outs());
403+
llvm::outs() << "Interior liveness: " << value;
404404
auto *domTree = test.getDominanceInfo();
405405
InteriorLiveness liveness(value);
406406
auto handleInnerScope = [](SILValue innerBorrow) {
@@ -423,8 +423,8 @@ static FunctionTest
423423
static FunctionTest ExtendedLinearLivenessTest(
424424
"extended-liveness", [](auto &function, auto &arguments, auto &test) {
425425
SILValue value = arguments.takeValue();
426-
function.dump();
427-
llvm::dbgs() << "Extended liveness: " << value;
426+
function.print(llvm::outs());
427+
llvm::outs() << "Extended liveness: " << value;
428428
ExtendedLinearLiveness liveness(value);
429429
liveness.compute();
430430
liveness.print(llvm::outs());

lib/SIL/Utils/OwnershipUtils.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ static FunctionTest OwnershipUtilsHasPointerEscape(
105105
"has-pointer-escape", [](auto &function, auto &arguments, auto &test) {
106106
auto value = arguments.takeValue();
107107
auto has = findPointerEscape(value);
108-
value->print(llvm::errs());
108+
value->print(llvm::outs());
109109
auto *boolString = has ? "true" : "false";
110-
llvm::errs() << boolString << "\n";
110+
llvm::outs() << boolString << "\n";
111111
});
112112
} // end namespace swift::test
113113

@@ -2057,10 +2057,10 @@ namespace swift::test {
20572057
// - the enclosing defs
20582058
static FunctionTest FindEnclosingDefsTest(
20592059
"find-enclosing-defs", [](auto &function, auto &arguments, auto &test) {
2060-
function.dump();
2061-
llvm::dbgs() << "Enclosing Defs:\n";
2060+
function.print(llvm::outs());
2061+
llvm::outs() << "Enclosing Defs:\n";
20622062
visitEnclosingDefs(arguments.takeValue(), [](SILValue def) {
2063-
def->dump();
2063+
def->print(llvm::outs());
20642064
return true;
20652065
});
20662066
});
@@ -2082,10 +2082,10 @@ namespace swift::test {
20822082
// - the borrow introducers
20832083
static FunctionTest FindBorrowIntroducers(
20842084
"find-borrow-introducers", [](auto &function, auto &arguments, auto &test) {
2085-
function.dump();
2086-
llvm::dbgs() << "Introducers:\n";
2085+
function.print(llvm::outs());
2086+
llvm::outs() << "Introducers:\n";
20872087
visitBorrowIntroducers(arguments.takeValue(), [](SILValue def) {
2088-
def->dump();
2088+
def->print(llvm::outs());
20892089
return true;
20902090
});
20912091
});
@@ -2202,10 +2202,10 @@ namespace swift::test {
22022202
static FunctionTest VisitInnerAdjacentPhisTest(
22032203
"visit-inner-adjacent-phis",
22042204
[](auto &function, auto &arguments, auto &test) {
2205-
function.dump();
2205+
function.print(llvm::outs());
22062206
visitInnerAdjacentPhis(cast<SILPhiArgument>(arguments.takeValue()),
22072207
[](auto *argument) -> bool {
2208-
argument->dump();
2208+
argument->print(llvm::outs());
22092209
return true;
22102210
});
22112211
});

lib/SIL/Utils/PrunedLiveness.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,9 @@ static FunctionTest
182182
while (arguments.hasUntaken()) {
183183
boundary.lastUsers.push_back(arguments.takeInstruction());
184184
}
185-
boundary.visitInsertionPoints(
186-
[](SILBasicBlock::iterator point) { point->dump(); });
185+
boundary.visitInsertionPoints([](SILBasicBlock::iterator point) {
186+
point->print(llvm::outs());
187+
});
187188
});
188189
} // end namespace swift::test
189190

lib/SIL/Utils/Test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ void FunctionTest::run(SILFunction &function, Arguments &arguments,
9797
auto fn = invocation.get<Invocation>();
9898
fn(function, arguments, *this);
9999
} else {
100+
llvm::outs().flush();
100101
auto *fn = invocation.get<NativeSwiftInvocation>();
101102
Registry::get().getFunctionTestThunk()(fn, {&function}, {&arguments},
102103
{getInvocation()});

lib/SILOptimizer/Analysis/BasicCalleeAnalysis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,8 @@ static FunctionTest IsDeinitBarrierTest("is-deinit-barrier", [](auto &function,
394394
auto *instruction = arguments.takeInstruction();
395395
auto *analysis = test.template getAnalysis<BasicCalleeAnalysis>();
396396
auto isBarrier = isDeinitBarrier(instruction, analysis);
397-
instruction->dump();
397+
instruction->print(llvm::outs());
398398
auto *boolString = isBarrier ? "true" : "false";
399-
llvm::errs() << boolString << "\n";
399+
llvm::outs() << boolString << "\n";
400400
});
401401
} // namespace swift::test

lib/SILOptimizer/UtilityPasses/TestRunner.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void TestRunner::printTestLifetime(bool begin, unsigned testIndex,
7777
unsigned testCount, StringRef name,
7878
ArrayRef<StringRef> components) {
7979
StringRef word = begin ? "\nbegin" : "end";
80-
llvm::errs() << word << " running test " << testIndex + 1 << " of "
80+
llvm::outs() << word << " running test " << testIndex + 1 << " of "
8181
<< testCount << " on " << getFunction()->getName() << ": "
8282
<< name << " with: ";
8383
for (unsigned long index = 0, size = components.size(); index < size;
@@ -86,18 +86,18 @@ void TestRunner::printTestLifetime(bool begin, unsigned testIndex,
8686
if (componentString.empty())
8787
continue;
8888

89-
llvm::errs() << componentString;
89+
llvm::outs() << componentString;
9090
if (index != size - 1) {
91-
llvm::errs() << ", ";
91+
llvm::outs() << ", ";
9292
}
9393
}
94-
llvm::errs() << "\n";
94+
llvm::outs() << "\n";
9595
}
9696

9797
void TestRunner::runTest(StringRef name, Arguments &arguments) {
9898
auto *test = FunctionTest::get(name);
9999
if (!test) {
100-
llvm::errs() << "No test named: " << name << "\n";
100+
llvm::outs() << "No test named: " << name << "\n";
101101
assert(false && "Invalid test name");
102102
}
103103
auto *function = getFunction();
@@ -137,15 +137,15 @@ void TestRunner::run() {
137137
// - the function
138138
static FunctionTest DumpFunctionTest("dump-function",
139139
[](auto &function, auto &, auto &) {
140-
function.dump();
140+
function.print(llvm::outs());
141141
});
142142

143143
// Arguments: NONE
144144
// Dumps: the index of the self argument of the current function
145145
static FunctionTest FunctionGetSelfArgumentIndex(
146146
"function-get-self-argument-index", [](auto &function, auto &, auto &) {
147147
auto index = BridgedFunction{&function}.getSelfArgumentIndex();
148-
llvm::errs() << "self argument index = " << index << "\n";
148+
llvm::outs() << "self argument index = " << index << "\n";
149149
});
150150

151151
} // namespace swift::test

lib/SILOptimizer/Utils/CanonicalizeBorrowScope.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,6 @@ static FunctionTest CanonicalizeBorrowScopeTest(
867867
InstructionDeleter deleter;
868868
CanonicalizeBorrowScope canonicalizer(value->getFunction(), deleter);
869869
canonicalizer.canonicalizeBorrowScope(borrowedValue);
870-
function.dump();
870+
function.print(llvm::outs());
871871
});
872872
} // end namespace swift::test

lib/SILOptimizer/Utils/CanonicalizeOSSALifetime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,7 @@ static FunctionTest CanonicalizeOSSALifetimeTest(
12491249
calleeAnalysis, deleter);
12501250
auto value = arguments.takeValue();
12511251
canonicalizer.canonicalizeValueLifetime(value);
1252-
function.dump();
1252+
function.print(llvm::outs());
12531253
});
12541254
} // end namespace swift::test
12551255

lib/SILOptimizer/Utils/InstructionDeleter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,10 @@ static FunctionTest DeleterDeleteIfDeadTest(
314314
"deleter-delete-if-dead", [](auto &function, auto &arguments, auto &test) {
315315
auto *inst = arguments.takeInstruction();
316316
InstructionDeleter deleter;
317-
llvm::dbgs() << "Deleting-if-dead " << *inst;
317+
llvm::outs() << "Deleting-if-dead " << *inst;
318318
auto deleted = deleter.deleteIfDead(inst);
319-
llvm::dbgs() << "deleteIfDead returned " << deleted << "\n";
320-
function.dump();
319+
llvm::outs() << "deleteIfDead returned " << deleted << "\n";
320+
function.print(llvm::outs());
321321
});
322322
} // namespace swift::test
323323

lib/SILOptimizer/Utils/LexicalDestroyFolding.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,6 @@ static FunctionTest LexicalDestroyFoldingTest(
814814
auto *bbi = cast<BeginBorrowInst>(value);
815815
InstructionDeleter deleter;
816816
foldDestroysOfCopiedLexicalBorrow(bbi, *domTree, deleter);
817-
function.dump();
817+
function.print(llvm::outs());
818818
});
819819
} // end namespace swift::test

lib/SILOptimizer/Utils/LexicalDestroyHoisting.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,6 @@ static FunctionTest LexicalDestroyHoistingTest(
426426
auto value = arguments.takeValue();
427427
hoistDestroysOfOwnedLexicalValue(value, *value->getFunction(), deleter,
428428
calleeAnalysis);
429-
function.dump();
429+
function.print(llvm::outs());
430430
});
431431
} // end namespace swift::test

0 commit comments

Comments
 (0)