Skip to content

Commit

Permalink
Merged master:6ef07111a402 into amd-gfx:ed9982e88406
Browse files Browse the repository at this point in the history
Local branch amd-gfx ed9982e Merged master:ac06b1af402e into amd-gfx:6fabed927daf
Remote branch master 6ef0711 [scudo/standalone] Fix leak in ThreadedGlobalQuarantine test
  • Loading branch information
Sw authored and Sw committed Nov 14, 2020
2 parents ed9982e + 6ef0711 commit 21cc039
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ void RedundantBranchConditionCheck::check(const MatchFinder::MatchResult &Result

// For standalone condition variables and for "or" binary operations we simply
// remove the inner `if`.
const auto *BinOpCond = dyn_cast<BinaryOperator>(InnerIf->getCond());
const auto *BinOpCond =
dyn_cast<BinaryOperator>(InnerIf->getCond()->IgnoreParenImpCasts());

if (isa<DeclRefExpr>(InnerIf->getCond()->IgnoreParenImpCasts()) ||
(BinOpCond && BinOpCond->getOpcode() == BO_LOr)) {
SourceLocation IfBegin = InnerIf->getBeginLoc();
Expand Down Expand Up @@ -129,7 +131,8 @@ void RedundantBranchConditionCheck::check(const MatchFinder::MatchResult &Result
// For "and" binary operations we remove the "and" operation with the
// condition variable from the inner if.
} else {
const auto *CondOp = cast<BinaryOperator>(InnerIf->getCond());
const auto *CondOp =
cast<BinaryOperator>(InnerIf->getCond()->IgnoreParenImpCasts());
const auto *LeftDRE =
dyn_cast<DeclRefExpr>(CondOp->getLHS()->IgnoreParenImpCasts());
if (LeftDRE && LeftDRE->getDecl() == CondVar) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,34 @@ void positive_comma_after_condition() {
}
}

// ExprWithCleanups doesn't crash
int positive_expr_with_cleanups() {
class RetT {
public:
RetT(const int _code) : code_(_code) {}
bool Ok() const { return code_ == 0; }
static RetT Test(bool &_isSet) { return 0; }

private:
int code_;
};

bool isSet = false;
if (RetT::Test(isSet).Ok() && isSet) {
if (RetT::Test(isSet).Ok() && isSet) {
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: redundant condition 'isSet' [bugprone-redundant-branch-condition]
// CHECK-FIXES: if (RetT::Test(isSet).Ok() ) {
}
}
if (isSet) {
if ((RetT::Test(isSet).Ok() && isSet)) {
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: redundant condition 'isSet' [bugprone-redundant-branch-condition]
// CHECK-FIXES: if ((RetT::Test(isSet).Ok() )) {
}
}
return 0;
}

//===--- Special Negatives ------------------------------------------------===//

// Aliasing
Expand Down
26 changes: 18 additions & 8 deletions compiler-rt/lib/scudo/standalone/tests/quarantine_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,17 @@ TEST(ScudoQuarantineTest, GlobalQuarantine) {
Str.output();
}

void *populateQuarantine(void *Param) {
struct PopulateQuarantineThread {
pthread_t Thread;
QuarantineT *Quarantine;
CacheT Cache;
Cache.init();
QuarantineT *Quarantine = reinterpret_cast<QuarantineT *>(Param);
};

void *populateQuarantine(void *Param) {
PopulateQuarantineThread *P = static_cast<PopulateQuarantineThread *>(Param);
P->Cache.init();
for (scudo::uptr I = 0; I < 128UL; I++)
Quarantine->put(&Cache, Cb, FakePtr, LargeBlockSize);
P->Quarantine->put(&P->Cache, Cb, FakePtr, LargeBlockSize);
return 0;
}

Expand All @@ -233,13 +238,18 @@ TEST(ScudoQuarantineTest, ThreadedGlobalQuarantine) {
Quarantine.init(MaxQuarantineSize, MaxCacheSize);

const scudo::uptr NumberOfThreads = 32U;
pthread_t T[NumberOfThreads];
for (scudo::uptr I = 0; I < NumberOfThreads; I++)
pthread_create(&T[I], 0, populateQuarantine, &Quarantine);
PopulateQuarantineThread T[NumberOfThreads];
for (scudo::uptr I = 0; I < NumberOfThreads; I++) {
T[I].Quarantine = &Quarantine;
pthread_create(&T[I].Thread, 0, populateQuarantine, &T[I]);
}
for (scudo::uptr I = 0; I < NumberOfThreads; I++)
pthread_join(T[I], 0);
pthread_join(T[I].Thread, 0);

scudo::ScopedString Str(1024);
Quarantine.getStats(&Str);
Str.output();

for (scudo::uptr I = 0; I < NumberOfThreads; I++)
Quarantine.drainAndRecycle(&T[I].Cache, Cb);
}

0 comments on commit 21cc039

Please sign in to comment.