From: David Blaikie Date: Tue, 24 Jan 2012 04:51:48 +0000 (+0000) Subject: Revert various template unreachability code I committed accidentally. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=23661d3e348c5f44ae89b6848bbc331829bb46f2;p=clang Revert various template unreachability code I committed accidentally. r148774, r148775, r148776, r148777 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148780 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/CFG.cpp b/lib/Analysis/CFG.cpp index c7040fc6d4..7b84710b59 100644 --- a/lib/Analysis/CFG.cpp +++ b/lib/Analysis/CFG.cpp @@ -721,7 +721,7 @@ void CFGBuilder::addAutomaticObjDtors(LocalScope::const_iterator B, } const CXXDestructorDecl *Dtor = Ty->getAsCXXRecordDecl()->getDestructor(); - if (Dtor && cast(Dtor->getType())->getNoReturnAttr()) + if (cast(Dtor->getType())->getNoReturnAttr()) Block = createNoReturnBlock(); else autoCreateBlock(); @@ -750,12 +750,13 @@ void CFGBuilder::addImplicitDtorsForDestructor(const CXXDestructorDecl *DD) { // Before virtual bases destroy direct base objects. for (CXXRecordDecl::base_class_const_iterator BI = RD->bases_begin(), BE = RD->bases_end(); BI != BE; ++BI) { - if (!BI->isVirtual()) - if (const CXXRecordDecl *CD = BI->getType()->getAsCXXRecordDecl()) - if (!CD->hasTrivialDestructor()) { - autoCreateBlock(); - appendBaseDtor(Block, BI); - } + if (!BI->isVirtual()) { + const CXXRecordDecl *CD = BI->getType()->getAsCXXRecordDecl(); + if (!CD->hasTrivialDestructor()) { + autoCreateBlock(); + appendBaseDtor(Block, BI); + } + } } // First destroy member objects. @@ -864,7 +865,7 @@ LocalScope* CFGBuilder::addLocalScopeForVarDecl(VarDecl *VD, // Check if type is a C++ class with non-trivial destructor. if (const CXXRecordDecl *CD = QT->getAsCXXRecordDecl()) - if (CD->hasDefinition() && !CD->hasTrivialDestructor()) { + if (!CD->hasTrivialDestructor()) { // Add the variable to scope Scope = createOrReuseLocalScope(Scope); Scope->addVar(VD); diff --git a/lib/Sema/AnalysisBasedWarnings.cpp b/lib/Sema/AnalysisBasedWarnings.cpp index 5f1d8cc7b0..e2d1e8c331 100644 --- a/lib/Sema/AnalysisBasedWarnings.cpp +++ b/lib/Sema/AnalysisBasedWarnings.cpp @@ -782,7 +782,8 @@ AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P, return; // For code in dependent contexts, we'll do this at instantiation time. - bool Dependent = cast(D)->isDependentContext(); + if (cast(D)->isDependentContext()) + return; if (Diags.hasErrorOccurred() || Diags.hasFatalErrorOccurred()) { // Flush out any possibly unreachable diagnostics. @@ -825,7 +826,7 @@ AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P, // Construct the analysis context with the specified CFG build options. // Emit delayed diagnostics. - if (!fscope->PossiblyUnreachableDiags.empty() && !Dependent) { + if (!fscope->PossiblyUnreachableDiags.empty()) { bool analyzed = false; // Register the expressions with the CFGBuilder. @@ -873,7 +874,7 @@ AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P, // Warning: check missing 'return' - if (P.enableCheckFallThrough && !Dependent) { + if (P.enableCheckFallThrough) { const CheckFallThroughDiagnostics &CD = (isa(D) ? CheckFallThroughDiagnostics::MakeForBlock() : CheckFallThroughDiagnostics::MakeForFunction(D)); @@ -894,7 +895,7 @@ AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P, } // Check for thread safety violations - if (P.enableThreadSafetyAnalysis && !Dependent) { + if (P.enableThreadSafetyAnalysis) { SourceLocation FL = AC.getDecl()->getLocation(); thread_safety::ThreadSafetyReporter Reporter(S, FL); thread_safety::runThreadSafetyAnalysis(AC, Reporter); diff --git a/test/SemaCXX/array-bounds.cpp b/test/SemaCXX/array-bounds.cpp index 8d0b1e4e30..c1b3701172 100644 --- a/test/SemaCXX/array-bounds.cpp +++ b/test/SemaCXX/array-bounds.cpp @@ -73,21 +73,17 @@ void test() { (*array_ptr)[3] = 1; // expected-warning {{array index 3 is past the end of the array (which contains 2 elements)}} } -// FIXME: we should see the next note only 3 times and the following warning once, not twice -// since it is independent of the template parameter 'I'. template struct S { - char arr[I]; // expected-note 4 {{declared here}} + char arr[I]; // expected-note 2 {{declared here}} }; template void f() { S<3> s; - s.arr[4] = 0; // expected-warning 2 {{array index 4 is past the end of the array (which contains 3 elements)}} - s.arr[I] = 0; // expected-warning {{array index 5 is past the end of the array (which contains 3 elements)}} \ - expected-warning {{array index 3 is past the end of the array (which contains 3 elements)}} + s.arr[4] = 0; // expected-warning {{array index 4 is past the end of the array (which contains 3 elements)}} + s.arr[I] = 0; // expected-warning {{array index 5 is past the end of the array (which contains 3 elements)}} } void test_templates() { f<5>(); // expected-note {{in instantiation}} - f<3>(); // expected-note {{in instantiation}} } #define SIZE 10 diff --git a/test/SemaCXX/warn-unreachable.cpp b/test/SemaCXX/warn-unreachable.cpp index 59b6bf9f30..f36300af4d 100644 --- a/test/SemaCXX/warn-unreachable.cpp +++ b/test/SemaCXX/warn-unreachable.cpp @@ -98,24 +98,6 @@ void test_unreachable_templates_harness() { test_unreachable_templates(); } -// Do warn about non-dependent unreachable code in templates -// Warn even if the template is never instantiated - -template void test_non_dependent_unreachable_templates() { - TestUnreachableA::foo(); - isUnreachable(); // expected-warning {{will never be executed}} -} - -// Warn only once even if the template is instantiated multiple times - -template void test_non_dependent_unreachable_templates2() { - TestUnreachableA::foo(); - isUnreachable(); // expected-warning {{will never be executed}} -} - -template void test_non_dependent_unreachable_templates2(); -template void test_non_dependent_unreachable_templates2(); - // Do warn about explict template specializations, as they represent // actual concrete functions that somebody wrote. @@ -125,19 +107,3 @@ template <> void funcToSpecialize() { dead(); // expected-warning {{will never be executed}} } -// Ensure we don't regress a fix involving undefined bases to template -// destructors when computing the CFG for unreachable code analysis -template struct imp; -template -struct aligned_storage : imp { - ~aligned_storage() { } -}; - -// is this valid? -template -class outer { - class inner; - void func() { - inner t; - } -};