mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[ownership-verifier] Improve error message for owned values leaked due to lack of "lifetime ending uses".
The ownership verifier diagnoses leaks of owned objects in two different places/ways: 1. If the owned value does not have any "consuming" uses, we bail early without performing dataflow verification. 2. If the owned value has at least 1 "consuming" uses, we perform dataflow to determine the blocks where the leaked value escapes without being destroyed. In the latter case, we give a nice error message saying that a leak occured. In contrast in the former, we go down a "generic error" path that just says that a "lifetime ending use" is required. This commit changes that generic error message for owned parameters to say that the value was leaked, resulting in a clearer message. The other cases are still left along though. I also added a test file to specifically test leaks/leak error messages. I added a few tests to make sure this error message is correct and a few more tests just for fun.
This commit is contained in:
@@ -1921,11 +1921,16 @@ bool SILValueOwnershipChecker::checkValueWithoutLifetimeEndingUses() {
|
||||
|
||||
if (!isValueAddressOrTrivial(Value, Mod)) {
|
||||
return !handleError([&] {
|
||||
llvm::errs() << "Function: '" << Value->getFunction()->getName() << "'\n"
|
||||
<< "Non trivial values, non address values, and non "
|
||||
"guaranteed function args must have at least one "
|
||||
"lifetime ending use?!\n"
|
||||
<< "Value: " << *Value << '\n';
|
||||
llvm::errs() << "Function: '" << Value->getFunction()->getName() << "'\n";
|
||||
if (Value.getOwnershipKind() == ValueOwnershipKind::Owned) {
|
||||
llvm::errs() << "Error! Found a leaked owned value that was never "
|
||||
"consumed.\n";
|
||||
} else {
|
||||
llvm::errs() << "Non trivial values, non address values, and non "
|
||||
"guaranteed function args must have at least one "
|
||||
"lifetime ending use?!\n";
|
||||
}
|
||||
llvm::errs() << "Value: " << *Value << '\n';
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user