audk/BaseTools/Source/C/VfrCompile
zenith432 5397bd425e BaseTools: resolve initialization order errors in VfrFormPkg.h
clang generates many warnings
warning: field 'XXX' is uninitialized when used here [-Wuninitialized]
for VfrFormPkg.h.

VfrFormPkg.h defines many classes derived from CIfrObj (along with other
base classes.)
Each of these derived classes defines a non-static member field that serves
as a duplicate pointer to an original pointer defined in the CIfrObj base
class, but cast to a different pointer type.
The derived class constructor passes the duplicate pointer to base class
constructors:
1) Once passes the address of the duplicate pointer to the CIfrObj
   constructor to have it initialized.
2) Then passes the duplicate pointer to one or more subsequent base class
   constructors to be used.
Both 1) and 2) constitute undefined behavior in C++.  C++ prescribes that
base classes are initialized before non-static members when initializing a
derived class.  So when base class constructors are executing, it is not
permitted to assume any non-static members of the derived class exist (even
to the stage of having their storage allocated.)

clang does not issue warnings for 1), but issues warnings -Wuninitialized
for 2).

This coding methodology is resolved as follows:
a) The CIfrObj object accessor method for retrieving the original pointer
   is revised to a template member function that returns the original
   pointer cast to a desired target type.
b) The call to CIfrObj constructor is no longer used to initialize the
   duplicate pointer in the derived class.
c) Any subsequent calls to a base class constructor that need to use the
   pointer, retrieve it from the CIfrObj base class using the template
   accessor method.
d) If the derived class makes no further use of the pointer, then the
   duplicate pointer defined in it is eliminated.
e) If the derived class needs the duplicate pointer for other use, the
   duplicate pointer remains in the derived class and is initialized in
   proper order from the original pointer in CIfrObj.
f) Existing source code that previously used the CIfrObj pointer accessor
   method is revised to use the template method.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zenith432 <zenith432@users.sourceforge.net>
Reviewed-by: Liming Gao <liming.gao@intel.com>
2018-01-02 20:37:38 +08:00
..
Pccts BaseTools: silence parentheses-equality warning 2018-01-02 20:37:32 +08:00
EfiVfr.h BaseTools/VfrCompile: Remove the MAX_PATH limitation 2017-08-04 14:32:42 +08:00
GNUmakefile BaseTools: Replace ARCH with HOST_ARCH in C Makefile to avoid conflict 2017-11-30 13:06:44 +08:00
Makefile Sync EDKII BaseTools to BaseTools project r2100. 2010-12-06 05:17:09 +00:00
VfrCompiler.cpp BaseTools/VfrCompile: Assign 'NULL' for closed file handle 2017-12-25 09:53:56 +08:00
VfrCompiler.h BaseTools/VfrCompile: Add checks for user/file inputs 2016-11-08 16:37:15 +08:00
VfrError.cpp BaseTools/VfrCompile: Resolve uninit class variables in constructor 2017-12-25 09:54:41 +08:00
VfrError.h BaseTool/VfrCompiler: Support Bit fields in EFI/Buffer VarStore 2017-09-21 16:17:40 +08:00
VfrFormPkg.cpp BaseTools: resolve initialization order errors in VfrFormPkg.h 2018-01-02 20:37:38 +08:00
VfrFormPkg.h BaseTools: resolve initialization order errors in VfrFormPkg.h 2018-01-02 20:37:38 +08:00
VfrSyntax.g BaseTools: resolve initialization order errors in VfrFormPkg.h 2018-01-02 20:37:38 +08:00
VfrUtilityLib.cpp BaseTools/VfrCompile: Resolve uninit class variables in constructor 2017-12-25 09:54:41 +08:00
VfrUtilityLib.h BaseTool/VfrCompiler: Support Bit fields in EFI/Buffer VarStore 2017-09-21 16:17:40 +08:00