Skip to content

Commit

Permalink
[DWARFYAML] Fix unintialized value Is64BitAddrSize. NFC.
Browse files Browse the repository at this point in the history
This patch fixes the undefined behavior that reported by ubsan.

http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/44524/
  • Loading branch information
higuoxing committed Aug 4, 2020
1 parent 0de547e commit 12605bf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion llvm/include/llvm/ObjectYAML/DWARFEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ std::function<Error(raw_ostream &, const Data &)>
getDWARFEmitterByName(StringRef SecName);
Expected<StringMap<std::unique_ptr<MemoryBuffer>>>
emitDebugSections(StringRef YAMLString,
bool IsLittleEndian = sys::IsLittleEndianHost);
bool IsLittleEndian = sys::IsLittleEndianHost,
bool Is64BitAddrSize = true);
} // end namespace DWARFYAML
} // end namespace llvm

Expand Down
5 changes: 4 additions & 1 deletion llvm/lib/ObjectYAML/DWARFEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,8 @@ emitDebugSectionImpl(const DWARFYAML::Data &DI, StringRef Sec,
}

Expected<StringMap<std::unique_ptr<MemoryBuffer>>>
DWARFYAML::emitDebugSections(StringRef YAMLString, bool IsLittleEndian) {
DWARFYAML::emitDebugSections(StringRef YAMLString, bool IsLittleEndian,
bool Is64BitAddrSize) {
auto CollectDiagnostic = [](const SMDiagnostic &Diag, void *DiagContext) {
*static_cast<SMDiagnostic *>(DiagContext) = Diag;
};
Expand All @@ -956,6 +957,8 @@ DWARFYAML::emitDebugSections(StringRef YAMLString, bool IsLittleEndian) {

DWARFYAML::Data DI;
DI.IsLittleEndian = IsLittleEndian;
DI.Is64BitAddrSize = Is64BitAddrSize;

YIn >> DI;
if (YIn.error())
return createStringError(YIn.error(), GeneratedDiag.getMessage());
Expand Down
3 changes: 2 additions & 1 deletion llvm/unittests/DebugInfo/DWARF/DWARFDieTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ TEST(DWARFDie, getLocations) {
)";
Expected<StringMap<std::unique_ptr<MemoryBuffer>>> Sections =
DWARFYAML::emitDebugSections(StringRef(yamldata),
/*IsLittleEndian=*/true);
/*IsLittleEndian=*/true,
/*Is64BitAddrSize=*/false);
ASSERT_THAT_EXPECTED(Sections, Succeeded());
std::unique_ptr<DWARFContext> Ctx =
DWARFContext::create(*Sections, 4, /*isLittleEndian=*/true);
Expand Down

0 comments on commit 12605bf

Please sign in to comment.