This is an archive of the discontinued LLVM Phabricator instance.

Warn on self-initializations
Needs ReviewPublic

Authored by rtrieu on Sep 17 2018, 7:42 PM.
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
Summary

Improve some diagnostics around self-initialization. The uninitialized checker does not warn on self-initialization, but does warn later if the variable is used. GCC also has a -Winit-self which will enable a -Wuninitialized warning for self-initialized. -Winit-self is active in -Wall

There's also the matter of the variable being const. GCC -Wuninitialized will warn on a const self-initialized with or without -Winit-self.

This patch will make it so that const self-initialization is always warned on under -Wuninitialized. Since Clang does not use warning flags to control other warnings, -Winit-self will be a new warning group for non-const self-initialized. -Winit-self will also be in -Wall via -Wmost.

// GCC - warn with -Wuninitialized and -Winit-self
// Clang - no warning
// Clang with patch - warn with -Winit-self
void f1() {
  int x = x;
}

// GCC - warn with -Wuninitialized
// Clang - no warning
// Clang with patch - warn with -Wuninitialized
void f2() {
  const int x = x;
}

Diff Detail

Event Timeline

rtrieu created this revision.Sep 17 2018, 7:42 PM