diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2010-05-17 23:51:52 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2010-05-17 23:51:52 +0000 |
commit | 00e9cbb13d3e5deb8ee27288e0ed816266ec9e5b (patch) | |
tree | 837ad40147986c5f812aa4a1bf0da63bc02c55f3 | |
parent | a6b0907a71c66e6bf65e2477a6f9783d9fec4d47 (diff) |
Add a hack to silence warnings about failing to return from functions after
a temporary with a noreturn destructor has been created. Fixes PR6884 for now.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@104000 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/AnalysisBasedWarnings.cpp | 13 | ||||
-rw-r--r-- | test/SemaCXX/return-noreturn.cpp | 17 |
2 files changed, 30 insertions, 0 deletions
diff --git a/lib/Sema/AnalysisBasedWarnings.cpp b/lib/Sema/AnalysisBasedWarnings.cpp index 21dd40b32e..448d16116a 100644 --- a/lib/Sema/AnalysisBasedWarnings.cpp +++ b/lib/Sema/AnalysisBasedWarnings.cpp @@ -167,6 +167,19 @@ static ControlFlowKind CheckFallThrough(AnalysisContext &AC) { } } } + // FIXME: Remove this hack once temporaries and their destructors are + // modeled correctly by the CFG. + if (CXXExprWithTemporaries *E = dyn_cast<CXXExprWithTemporaries>(S)) { + for (unsigned I = 0, N = E->getNumTemporaries(); I != N; ++I) { + const FunctionDecl *FD = E->getTemporary(I)->getDestructor(); + if (FD->hasAttr<NoReturnAttr>() || + FD->getType()->getAs<FunctionType>()->getNoReturnAttr()) { + NoReturnEdge = true; + HasFakeEdge = true; + break; + } + } + } // FIXME: Add noreturn message sends. if (NoReturnEdge == false) HasPlainEdge = true; diff --git a/test/SemaCXX/return-noreturn.cpp b/test/SemaCXX/return-noreturn.cpp new file mode 100644 index 0000000000..9242d1240a --- /dev/null +++ b/test/SemaCXX/return-noreturn.cpp @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 %s -fsyntax-only -verify -Wmissing-noreturn -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)); + }; + + int f() { + abort_struct(); + } + + int f2() { + abort_struct s; + } // expected-warning{{control reaches end of non-void function}} +} |