[cfe-commits] r148774 - in /cfe/trunk: lib/Sema/AnalysisBasedWarnings.cpp test/SemaCXX/array-bounds.cpp test/SemaCXX/warn-unreachable.cpp
David Blaikie
dblaikie at gmail.com
Mon Jan 23 20:56:14 PST 2012
Reverted in r148780 - again, apologies for the noise.
On Mon, Jan 23, 2012 at 8:36 PM, David Blaikie <dblaikie at gmail.com> wrote:
> Sorry about this (& a few future) commits - committed from the wrong
> git branch, evidently. I'll back them out ASAP.
>
> On Mon, Jan 23, 2012 at 8:29 PM, David Blaikie <dblaikie at gmail.com> wrote:
>> Author: dblaikie
>> Date: Mon Jan 23 22:29:18 2012
>> New Revision: 148774
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=148774&view=rev
>> Log:
>> Simple hack to do unreachable code analysis on template patterns.
>>
>> Modified:
>> cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
>> cfe/trunk/test/SemaCXX/array-bounds.cpp
>> cfe/trunk/test/SemaCXX/warn-unreachable.cpp
>>
>> Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=148774&r1=148773&r2=148774&view=diff
>> ==============================================================================
>> --- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
>> +++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Mon Jan 23 22:29:18 2012
>> @@ -782,8 +782,7 @@
>> return;
>>
>> // For code in dependent contexts, we'll do this at instantiation time.
>> - if (cast<DeclContext>(D)->isDependentContext())
>> - return;
>> + bool Dependent = cast<DeclContext>(D)->isDependentContext();
>>
>> if (Diags.hasErrorOccurred() || Diags.hasFatalErrorOccurred()) {
>> // Flush out any possibly unreachable diagnostics.
>> @@ -826,7 +825,7 @@
>> // Construct the analysis context with the specified CFG build options.
>>
>> // Emit delayed diagnostics.
>> - if (!fscope->PossiblyUnreachableDiags.empty()) {
>> + if (!fscope->PossiblyUnreachableDiags.empty() && !Dependent) {
>> bool analyzed = false;
>>
>> // Register the expressions with the CFGBuilder.
>> @@ -874,7 +873,7 @@
>>
>>
>> // Warning: check missing 'return'
>> - if (P.enableCheckFallThrough) {
>> + if (P.enableCheckFallThrough && !Dependent) {
>> const CheckFallThroughDiagnostics &CD =
>> (isa<BlockDecl>(D) ? CheckFallThroughDiagnostics::MakeForBlock()
>> : CheckFallThroughDiagnostics::MakeForFunction(D));
>> @@ -895,7 +894,7 @@
>> }
>>
>> // Check for thread safety violations
>> - if (P.enableThreadSafetyAnalysis) {
>> + if (P.enableThreadSafetyAnalysis && !Dependent) {
>> SourceLocation FL = AC.getDecl()->getLocation();
>> thread_safety::ThreadSafetyReporter Reporter(S, FL);
>> thread_safety::runThreadSafetyAnalysis(AC, Reporter);
>>
>> Modified: cfe/trunk/test/SemaCXX/array-bounds.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/array-bounds.cpp?rev=148774&r1=148773&r2=148774&view=diff
>> ==============================================================================
>> --- cfe/trunk/test/SemaCXX/array-bounds.cpp (original)
>> +++ cfe/trunk/test/SemaCXX/array-bounds.cpp Mon Jan 23 22:29:18 2012
>> @@ -73,17 +73,21 @@
>> (*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 <int I> struct S {
>> - char arr[I]; // expected-note 2 {{declared here}}
>> + char arr[I]; // expected-note 4 {{declared here}}
>> };
>> template <int I> void f() {
>> S<3> s;
>> - 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)}}
>> + 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)}}
>> }
>>
>> void test_templates() {
>> f<5>(); // expected-note {{in instantiation}}
>> + f<3>(); // expected-note {{in instantiation}}
>> }
>>
>> #define SIZE 10
>>
>> Modified: cfe/trunk/test/SemaCXX/warn-unreachable.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-unreachable.cpp?rev=148774&r1=148773&r2=148774&view=diff
>> ==============================================================================
>> --- cfe/trunk/test/SemaCXX/warn-unreachable.cpp (original)
>> +++ cfe/trunk/test/SemaCXX/warn-unreachable.cpp Mon Jan 23 22:29:18 2012
>> @@ -98,6 +98,24 @@
>> test_unreachable_templates<TestUnreachableB>();
>> }
>>
>> +// Do warn about non-dependent unreachable code in templates
>> +// Warn even if the template is never instantiated
>> +
>> +template<typename T> 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<typename T> void test_non_dependent_unreachable_templates2() {
>> + TestUnreachableA::foo();
>> + isUnreachable(); // expected-warning {{will never be executed}}
>> +}
>> +
>> +template void test_non_dependent_unreachable_templates2<int>();
>> +template void test_non_dependent_unreachable_templates2<long>();
>> +
>> // Do warn about explict template specializations, as they represent
>> // actual concrete functions that somebody wrote.
>>
>> @@ -106,4 +124,3 @@
>> halt();
>> dead(); // expected-warning {{will never be executed}}
>> }
>> -
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list