[llvm] r327498 - Explicitly initialize dwarf::FormParams in DIEInteger::SizeOf

Pavel Labath via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 14 04:14:43 PDT 2018


Author: labath
Date: Wed Mar 14 04:14:43 2018
New Revision: 327498

URL: http://llvm.org/viewvc/llvm-project?rev=327498&view=rev
Log:
Explicitly initialize dwarf::FormParams in DIEInteger::SizeOf

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.

Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp?rev=327498&r1=327497&r2=327498&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp Wed Mar 14 04:14:43 2018
@@ -425,7 +425,7 @@ void DIEInteger::EmitValue(const AsmPrin
 /// 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()};




More information about the llvm-commits mailing list