[cfe-commits] r142538 - in /cfe/trunk: lib/Sema/AnalysisBasedWarnings.cpp test/Sema/uninit-variables.c

Douglas Gregor dgregor at apple.com
Wed Oct 19 13:50:56 PDT 2011


Approved.

In the future, please ask the code owner (in this case, me) first and the code owner will forward to Bill.

	- Doug

On Oct 19, 2011, at 12:02 PM, Matt Beaumont-Gay wrote:

> Hi Bill,
> 
> Can you merge this into the 3.0 branch? It fixes a minor diagnostic
> regression introduced in r141881.
> 
> Thanks,
> Matt
> 
> On Wed, Oct 19, 2011 at 11:53, Matt Beaumont-Gay <matthewbg at google.com> wrote:
>> Author: matthewbg
>> Date: Wed Oct 19 13:53:03 2011
>> New Revision: 142538
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=142538&view=rev
>> Log:
>> Only warn at self-initialization if some later use is always uninitialized.
>> 
>> Modified:
>>    cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
>>    cfe/trunk/test/Sema/uninit-variables.c
>> 
>> Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=142538&r1=142537&r2=142538&view=diff
>> ==============================================================================
>> --- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
>> +++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Wed Oct 19 13:53:03 2011
>> @@ -586,9 +586,10 @@
>>       // Specially handle the case where we have uses of an uninitialized
>>       // variable, but the root cause is an idiomatic self-init.  We want
>>       // to report the diagnostic at the self-init since that is the root cause.
>> -      if (!vec->empty() && hasSelfInit)
>> +      if (!vec->empty() && hasSelfInit && hasAlwaysUninitializedUse(vec))
>>         DiagnoseUninitializedUse(S, vd, vd->getInit()->IgnoreParenCasts(),
>> -                                 true, /* alwaysReportSelfInit */ true);
>> +                                 /* isAlwaysUninit */ true,
>> +                                 /* alwaysReportSelfInit */ true);
>>       else {
>>         // Sort the uses by their SourceLocations.  While not strictly
>>         // guaranteed to produce them in line/column order, this will provide
>> @@ -610,6 +611,16 @@
>>     }
>>     delete uses;
>>   }
>> +
>> +private:
>> +  static bool hasAlwaysUninitializedUse(const UsesVec* vec) {
>> +  for (UsesVec::const_iterator i = vec->begin(), e = vec->end(); i != e; ++i) {
>> +    if (i->second) {
>> +      return true;
>> +    }
>> +  }
>> +  return false;
>> +}
>>  };
>>  }
>> 
>> 
>> Modified: cfe/trunk/test/Sema/uninit-variables.c
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/uninit-variables.c?rev=142538&r1=142537&r2=142538&view=diff
>> ==============================================================================
>> --- cfe/trunk/test/Sema/uninit-variables.c (original)
>> +++ cfe/trunk/test/Sema/uninit-variables.c Wed Oct 19 13:53:03 2011
>> @@ -44,6 +44,15 @@
>>   return x; // expected-warning{{variable 'x' may be uninitialized when used here}}
>>  }
>> 
>> +int test7b(int y) {
>> +  int x = x; // expected-note{{variable 'x' is declared here}}
>> +  if (y)
>> +    x = 1;
>> +  // Warn with "may be uninitialized" here (not "is uninitialized"), since the
>> +  // self-initialization is intended to suppress a -Wuninitialized warning.
>> +  return x; // expected-warning{{variable 'x' may be uninitialized when used here}}
>> +}
>> +
>>  int test8(int y) {
>>   int x;
>>   if (y)
>> @@ -415,4 +424,3 @@
>>   for (; i < 10000; ++i) // expected-warning {{variable 'i' is uninitialized when used here}}
>>     P[i] = 0.0f;
>>  }
>> -
>> 
>> 
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>> 
> 
> _______________________________________________
> 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