[cfe-commits] r158611 - in /cfe/trunk: lib/Analysis/UninitializedValues.cpp test/Sema/uninit-variables.c

Ted Kremenek kremenek at apple.com
Mon Jun 18 10:29:45 PDT 2012


Awesome!

On Jun 16, 2012, at 4:34 PM, Richard Smith <richard-llvm at metafoo.co.uk> wrote:

> Author: rsmith
> Date: Sat Jun 16 18:34:14 2012
> New Revision: 158611
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=158611&view=rev
> Log:
> -Wuninitialized bugfix: when entering the scope of a variable with no
> initializer, it is uninitialized, even if we may be coming from somewhere where
> it was initialized.
> 
> Modified:
>    cfe/trunk/lib/Analysis/UninitializedValues.cpp
>    cfe/trunk/test/Sema/uninit-variables.c
> 
> Modified: cfe/trunk/lib/Analysis/UninitializedValues.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/UninitializedValues.cpp?rev=158611&r1=158610&r2=158611&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Analysis/UninitializedValues.cpp (original)
> +++ cfe/trunk/lib/Analysis/UninitializedValues.cpp Sat Jun 16 18:34:14 2012
> @@ -625,6 +625,18 @@
>           // the use of the uninitialized value (which visiting the
>           // initializer).
>           vals[vd] = Initialized;
> +        } else {
> +          // No initializer: the variable is now uninitialized. This matters
> +          // for cases like:
> +          //   while (...) {
> +          //     int n;
> +          //     use(n);
> +          //     n = 0;
> +          //   }
> +          // FIXME: Mark the variable as uninitialized whenever its scope is
> +          // left, since its scope could be re-entered by a jump over the
> +          // declaration.
> +          vals[vd] = Uninitialized;
>         }
>       }
>     }
> 
> Modified: cfe/trunk/test/Sema/uninit-variables.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/uninit-variables.c?rev=158611&r1=158610&r2=158611&view=diff
> ==============================================================================
> --- cfe/trunk/test/Sema/uninit-variables.c (original)
> +++ cfe/trunk/test/Sema/uninit-variables.c Sat Jun 16 18:34:14 2012
> @@ -437,3 +437,28 @@
>   int c;  // expected-note {{initialize the variable 'c' to silence this warning}}
>   ASSIGN(int, c, d);  // expected-warning {{variable 'c' is uninitialized when used here}}
> }
> +
> +void uninit_in_loop() {
> +  int produce(void);
> +  void consume(int);
> +  for (int n = 0; n < 100; ++n) {
> +    int k; // expected-note {{initialize}}
> +    consume(k); // expected-warning {{variable 'k' is uninitialized}}
> +    k = produce();
> +  }
> +}
> +
> +void uninit_in_loop_goto() {
> +  int produce(void);
> +  void consume(int);
> +  for (int n = 0; n < 100; ++n) {
> +    goto skip_decl;
> +    int k; // expected-note {{initialize}}
> +skip_decl:
> +    // FIXME: This should produce the 'is uninitialized' diagnostic, but we
> +    // don't have enough information in the CFG to easily tell that the
> +    // variable's scope has been left and re-entered.
> +    consume(k); // expected-warning {{variable 'k' may be uninitialized}}
> +    k = produce();
> +  }
> +}
> 
> 
> _______________________________________________
> 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