OSDN Git Service

Explicitly initialize dwarf::FormParams in DIEInteger::SizeOf
authorPavel Labath <labath@google.com>
Wed, 14 Mar 2018 11:14:43 +0000 (11:14 +0000)
committerPavel Labath <labath@google.com>
Wed, 14 Mar 2018 11:14:43 +0000 (11:14 +0000)
This could end up inititialized if someone called the function with a
null AsmPrinter. Right now this only happens in DIEHash unit tests,
presumably because it was hard to create an AsmPrinter in the context of
unit tests. This only worked before r327486 because those tests did not
use any dwarf forms whose size actually depended on the dwarf version
(otherwise, they would have crashed due to null dereference).

I fix the uninitialized error, by explicitly initializing FormParams to
an invalid value, which will cause getFixedFormByteSize to return None
if called with a form with version-dependent size. A more principled
solution might be to fix the DIEHash tests to always pass in a valid
AsmPrinter.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@327498 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/AsmPrinter/DIE.cpp

index d935c05..8326215 100644 (file)
@@ -425,7 +425,7 @@ void DIEInteger::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
 /// SizeOf - Determine size of integer value in bytes.
 ///
 unsigned DIEInteger::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
-  dwarf::FormParams Params;
+  dwarf::FormParams Params({0, 0, dwarf::DWARF32});
   if (AP)
     Params = {AP->getDwarfVersion(), uint8_t(AP->getPointerSize()),
               AP->OutStreamer->getContext().getDwarfFormat()};