From ebe6260137cff8f43e642d6b67a45960ca573bcb Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Tue, 25 Jan 2011 22:50:47 +0000 Subject: [PATCH] Fix regression in -Wreturn-type caused by not handling all CFGElement kinds. While writing the test case, it turned out that return-noreturn.cpp wasn't actually testing anything since it has the wrong -W flag. That uncovered another regression with the handling of destructors marked noreturn. WIP. llvm-svn: 124238 --- clang/lib/Sema/AnalysisBasedWarnings.cpp | 15 +++--------- clang/test/SemaCXX/return-noreturn-XFAIL.cpp | 18 +++++++++++++++ clang/test/SemaCXX/return-noreturn.cpp | 24 ++++++++------------ 3 files changed, 30 insertions(+), 27 deletions(-) create mode 100644 clang/test/SemaCXX/return-noreturn-XFAIL.cpp diff --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp b/clang/lib/Sema/AnalysisBasedWarnings.cpp index 4866c8fb3d01..2f02e158cbd7 100644 --- a/clang/lib/Sema/AnalysisBasedWarnings.cpp +++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp @@ -132,21 +132,12 @@ static ControlFlowKind CheckFallThrough(AnalysisContext &AC) { continue; } CFGElement CE = B[B.size()-1]; - if (CFGInitializer CI = CE.getAs()) { - // A base or member initializer. - HasPlainEdge = true; - continue; - } - if (CFGMemberDtor MD = CE.getAs()) { - // A member destructor. - HasPlainEdge = true; - continue; - } - if (CFGBaseDtor BD = CE.getAs()) { - // A base destructor. + + if (!isa(CE)) { HasPlainEdge = true; continue; } + CFGStmt CS = CE.getAs(); if (!CS.isValid()) continue; diff --git a/clang/test/SemaCXX/return-noreturn-XFAIL.cpp b/clang/test/SemaCXX/return-noreturn-XFAIL.cpp new file mode 100644 index 000000000000..ee76dcb270e9 --- /dev/null +++ b/clang/test/SemaCXX/return-noreturn-XFAIL.cpp @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 %s -fsyntax-only -verify -Wreturn-type -Wno-unreachable-code +// XFAIL: * + +// A destructor may be marked noreturn and should still influence the CFG. +namespace PR6884 { + struct abort_struct { + abort_struct() {} // Make this non-POD so the destructor is invoked. + ~abort_struct() __attribute__((noreturn)); + }; + + int f() { + abort_struct(); + } + + int f2() { + abort_struct s; + } +} diff --git a/clang/test/SemaCXX/return-noreturn.cpp b/clang/test/SemaCXX/return-noreturn.cpp index f7072b21771e..5045d1b4c3d3 100644 --- a/clang/test/SemaCXX/return-noreturn.cpp +++ b/clang/test/SemaCXX/return-noreturn.cpp @@ -1,17 +1,11 @@ -// RUN: %clang_cc1 %s -fsyntax-only -verify -Wmissing-noreturn -Wno-unreachable-code +// RUN: %clang_cc1 %s -fsyntax-only -verify -Wreturn-type -Wno-unreachable-code -// A destructor may be marked noreturn and should still influence the CFG. -namespace PR6884 { - struct abort_struct { - abort_struct() {} // Make this non-POD so the destructor is invoked. - ~abort_struct() __attribute__((noreturn)); - }; +// - Properly handle CFGs with destructors. +struct rdar8875247 { + ~rdar8875247 (); +}; +void rdar8875247_aux(); - int f() { - abort_struct(); - } - - int f2() { - abort_struct s; - } -} +int rdar8875247_test() { + rdar8875247 f; +} // expected-warning{{control reaches end of non-void function}} -- GitLab