diff --git a/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp index 137356acbdbacd..abb8e8be9b2f85 100644 --- a/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp @@ -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(InnerIf->getCond()); + const auto *BinOpCond = + dyn_cast(InnerIf->getCond()->IgnoreParenImpCasts()); + if (isa(InnerIf->getCond()->IgnoreParenImpCasts()) || (BinOpCond && BinOpCond->getOpcode() == BO_LOr)) { SourceLocation IfBegin = InnerIf->getBeginLoc(); @@ -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(InnerIf->getCond()); + const auto *CondOp = + cast(InnerIf->getCond()->IgnoreParenImpCasts()); const auto *LeftDRE = dyn_cast(CondOp->getLHS()->IgnoreParenImpCasts()); if (LeftDRE && LeftDRE->getDecl() == CondVar) { diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp index 2bfd49a82955c8..dd001e836477a8 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp @@ -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 diff --git a/compiler-rt/lib/scudo/standalone/tests/quarantine_test.cpp b/compiler-rt/lib/scudo/standalone/tests/quarantine_test.cpp index 0422c2ff3736b0..91de56a78c97b6 100644 --- a/compiler-rt/lib/scudo/standalone/tests/quarantine_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/quarantine_test.cpp @@ -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(Param); +}; + +void *populateQuarantine(void *Param) { + PopulateQuarantineThread *P = static_cast(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; } @@ -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); }