r359984 - Revert rL359962 : Use DiagRuntimeBehavior for -Wunsequenced to weed out false positives
Simon Pilgrim via cfe-commits
cfe-commits at lists.llvm.org
Sun May 5 10:10:05 PDT 2019
Author: rksimon
Date: Sun May 5 10:10:05 2019
New Revision: 359984
URL: http://llvm.org/viewvc/llvm-project?rev=359984&view=rev
Log:
Revert rL359962 : Use DiagRuntimeBehavior for -Wunsequenced to weed out false positives
where either the modification or the other access is unreachable.
........
Try to fix buildbots
Modified:
cfe/trunk/include/clang/Sema/ScopeInfo.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/warn-unsequenced.c
cfe/trunk/test/SemaCXX/warn-unsequenced.cpp
Modified: cfe/trunk/include/clang/Sema/ScopeInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/ScopeInfo.h?rev=359984&r1=359983&r2=359984&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/ScopeInfo.h (original)
+++ cfe/trunk/include/clang/Sema/ScopeInfo.h Sun May 5 10:10:05 2019
@@ -84,11 +84,11 @@ class PossiblyUnreachableDiag {
public:
PartialDiagnostic PD;
SourceLocation Loc;
- llvm::TinyPtrVector<const Stmt*> Stmts;
+ const Stmt *stmt;
PossiblyUnreachableDiag(const PartialDiagnostic &PD, SourceLocation Loc,
- ArrayRef<const Stmt *> Stmts)
- : PD(PD), Loc(Loc), Stmts(Stmts) {}
+ const Stmt *stmt)
+ : PD(PD), Loc(Loc), stmt(stmt) {}
};
/// Retains information about a function, method, or block that is
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=359984&r1=359983&r2=359984&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Sun May 5 10:10:05 2019
@@ -4252,10 +4252,6 @@ public:
/// If it is unreachable, the diagnostic will not be emitted.
bool DiagRuntimeBehavior(SourceLocation Loc, const Stmt *Statement,
const PartialDiagnostic &PD);
- /// Similar, but diagnostic is only produced if all the specified statements
- /// are reachable.
- bool DiagRuntimeBehavior(SourceLocation Loc, ArrayRef<const Stmt*> Stmts,
- const PartialDiagnostic &PD);
// Primary Expressions.
SourceRange getExprRange(Expr *E) const;
Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=359984&r1=359983&r2=359984&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Sun May 5 10:10:05 2019
@@ -2089,16 +2089,16 @@ AnalysisBasedWarnings::IssueWarnings(sem
// Register the expressions with the CFGBuilder.
for (const auto &D : fscope->PossiblyUnreachableDiags) {
- for (const Stmt *S : D.Stmts)
- AC.registerForcedBlockExpression(S);
+ if (D.stmt)
+ AC.registerForcedBlockExpression(D.stmt);
}
if (AC.getCFG()) {
analyzed = true;
for (const auto &D : fscope->PossiblyUnreachableDiags) {
- bool AllReachable = true;
- for (const Stmt *S : D.Stmts) {
- const CFGBlock *block = AC.getBlockForRegisteredExpression(S);
+ bool processed = false;
+ if (D.stmt) {
+ const CFGBlock *block = AC.getBlockForRegisteredExpression(D.stmt);
CFGReverseBlockReachabilityAnalysis *cra =
AC.getCFGReachablityAnalysis();
// FIXME: We should be able to assert that block is non-null, but
@@ -2106,17 +2106,15 @@ AnalysisBasedWarnings::IssueWarnings(sem
// edge cases; see test/Sema/vla-2.c.
if (block && cra) {
// Can this block be reached from the entrance?
- if (!cra->isReachable(&AC.getCFG()->getEntry(), block)) {
- AllReachable = false;
- break;
- }
+ if (cra->isReachable(&AC.getCFG()->getEntry(), block))
+ S.Diag(D.Loc, D.PD);
+ processed = true;
}
- // If we cannot map to a basic block, assume the statement is
- // reachable.
}
-
- if (AllReachable)
+ if (!processed) {
+ // Emit the warning anyway if we cannot map to a basic block.
S.Diag(D.Loc, D.PD);
+ }
}
}
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=359984&r1=359983&r2=359984&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Sun May 5 10:10:05 2019
@@ -12155,11 +12155,10 @@ class SequenceChecker : public Evaluated
if (OtherKind == UK_Use)
std::swap(Mod, ModOrUse);
- SemaRef.DiagRuntimeBehavior(
- Mod->getExprLoc(), {Mod, ModOrUse},
- SemaRef.PDiag(IsModMod ? diag::warn_unsequenced_mod_mod
- : diag::warn_unsequenced_mod_use)
- << O << SourceRange(ModOrUse->getExprLoc()));
+ SemaRef.Diag(Mod->getExprLoc(),
+ IsModMod ? diag::warn_unsequenced_mod_mod
+ : diag::warn_unsequenced_mod_use)
+ << O << SourceRange(ModOrUse->getExprLoc());
UI.Diagnosed = true;
}
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=359984&r1=359983&r2=359984&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sun May 5 10:10:05 2019
@@ -16079,7 +16079,7 @@ void Sema::MarkDeclarationsReferencedInE
/// behavior of a program, such as passing a non-POD value through an ellipsis.
/// Failure to do so will likely result in spurious diagnostics or failures
/// during overload resolution or within sizeof/alignof/typeof/typeid.
-bool Sema::DiagRuntimeBehavior(SourceLocation Loc, ArrayRef<const Stmt*> Stmts,
+bool Sema::DiagRuntimeBehavior(SourceLocation Loc, const Stmt *Statement,
const PartialDiagnostic &PD) {
switch (ExprEvalContexts.back().Context) {
case ExpressionEvaluationContext::Unevaluated:
@@ -16095,9 +16095,9 @@ bool Sema::DiagRuntimeBehavior(SourceLoc
case ExpressionEvaluationContext::PotentiallyEvaluated:
case ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed:
- if (!Stmts.empty() && getCurFunctionOrMethodDecl()) {
+ if (Statement && getCurFunctionOrMethodDecl()) {
FunctionScopes.back()->PossiblyUnreachableDiags.
- push_back(sema::PossiblyUnreachableDiag(PD, Loc, Stmts));
+ push_back(sema::PossiblyUnreachableDiag(PD, Loc, Statement));
return true;
}
@@ -16122,12 +16122,6 @@ bool Sema::DiagRuntimeBehavior(SourceLoc
return false;
}
-bool Sema::DiagRuntimeBehavior(SourceLocation Loc, const Stmt *Statement,
- const PartialDiagnostic &PD) {
- return DiagRuntimeBehavior(
- Loc, Statement ? llvm::makeArrayRef(Statement) : llvm::None, PD);
-}
-
bool Sema::CheckCallReturnType(QualType ReturnType, SourceLocation Loc,
CallExpr *CE, FunctionDecl *FD) {
if (ReturnType->isVoidType() || !ReturnType->isIncompleteType())
Modified: cfe/trunk/test/Sema/warn-unsequenced.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-unsequenced.c?rev=359984&r1=359983&r2=359984&view=diff
==============================================================================
--- cfe/trunk/test/Sema/warn-unsequenced.c (original)
+++ cfe/trunk/test/Sema/warn-unsequenced.c Sun May 5 10:10:05 2019
@@ -95,11 +95,4 @@ void test() {
_Alignof(++a) + ++a; // expected-warning {{extension}}
__builtin_constant_p(f(++a, 0)) ? f(f(++a, 0), f(++a, 0)) : 0;
-
- if (0) ++a + ++a; // ok, unreachable
-}
-
-void g(const char *p, int n) {
- // This resembles code produced by some macros in glibc's <string.h>.
- __builtin_constant_p(p) && __builtin_constant_p(++n) && (++n + ++n);
}
Modified: cfe/trunk/test/SemaCXX/warn-unsequenced.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-unsequenced.cpp?rev=359984&r1=359983&r2=359984&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-unsequenced.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-unsequenced.cpp Sun May 5 10:10:05 2019
@@ -486,8 +486,8 @@ int Foo<X>::Run() {
// cxx17-warning at -2 {{unsequenced modification and access to 'num'}}
foo(num++, num++);
- // cxx11-warning at -1 {{multiple unsequenced modifications to 'num'}}
- // cxx17-warning at -2 {{multiple unsequenced modifications to 'num'}}
+ // cxx11-warning at -1 2{{multiple unsequenced modifications to 'num'}}
+ // cxx17-warning at -2 2{{multiple unsequenced modifications to 'num'}}
return 1;
}
More information about the cfe-commits
mailing list