From 4c5e43da7792f75567b693105cc53e3f1992ad98 Mon Sep 17 00:00:00 2001 From: Pirama Arumuga Nainar Date: Wed, 8 Apr 2015 08:55:49 -0700 Subject: Update aosp/master llvm for rebase to r233350 Change-Id: I07d935f8793ee8ec6b7da003f6483046594bca49 --- unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp | 75 ++++++++++++++++++++++++ 1 file changed, 75 insertions(+) (limited to 'unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp') diff --git a/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp b/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp index 4521132..371e2af 100644 --- a/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp +++ b/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp @@ -8,8 +8,12 @@ //===----------------------------------------------------------------------===// #include "llvm/DebugInfo/DWARF/DWARFFormValue.h" +#include "llvm/ADT/SmallString.h" #include "llvm/Support/Dwarf.h" +#include "llvm/Support/Host.h" +#include "llvm/Support/LEB128.h" #include "gtest/gtest.h" +#include using namespace llvm; using namespace dwarf; @@ -46,4 +50,75 @@ TEST(DWARFFormValue, FormClass) { EXPECT_TRUE(isFormClass(DW_FORM_ref_sig8, DWARFFormValue::FC_Reference)); } +template +DWARFFormValue createDataXFormValue(uint16_t Form, RawTypeT Value) { + char Raw[sizeof(RawTypeT)]; + memcpy(Raw, &Value, sizeof(RawTypeT)); + uint32_t Offset = 0; + DWARFFormValue Result(Form); + DataExtractor Data(StringRef(Raw, sizeof(RawTypeT)), + sys::IsLittleEndianHost, sizeof(void*)); + Result.extractValue(Data, &Offset, nullptr); + return Result; +} + +DWARFFormValue createULEBFormValue(uint64_t Value) { + SmallString<10> RawData; + raw_svector_ostream OS(RawData); + encodeULEB128(Value, OS); + uint32_t Offset = 0; + DWARFFormValue Result(DW_FORM_udata); + DataExtractor Data(OS.str(), sys::IsLittleEndianHost, sizeof(void*)); + Result.extractValue(Data, &Offset, nullptr); + return Result; +} + +DWARFFormValue createSLEBFormValue(int64_t Value) { + SmallString<10> RawData; + raw_svector_ostream OS(RawData); + encodeSLEB128(Value, OS); + uint32_t Offset = 0; + DWARFFormValue Result(DW_FORM_sdata); + DataExtractor Data(OS.str(), sys::IsLittleEndianHost, sizeof(void*)); + Result.extractValue(Data, &Offset, nullptr); + return Result; +} + +TEST(DWARFFormValue, SignedConstantForms) { + // Check that we correctly sign extend fixed size forms. + auto Sign1 = createDataXFormValue(DW_FORM_data1, -123); + auto Sign2 = createDataXFormValue(DW_FORM_data2, -12345); + auto Sign4 = createDataXFormValue(DW_FORM_data4, -123456789); + auto Sign8 = createDataXFormValue(DW_FORM_data8, -1); + EXPECT_EQ(Sign1.getAsSignedConstant().getValue(), -123); + EXPECT_EQ(Sign2.getAsSignedConstant().getValue(), -12345); + EXPECT_EQ(Sign4.getAsSignedConstant().getValue(), -123456789); + EXPECT_EQ(Sign8.getAsSignedConstant().getValue(), -1); + + // Check that we can handle big positive values, but that we return + // an error just over the limit. + auto UMax = createULEBFormValue(LLONG_MAX); + auto TooBig = createULEBFormValue(uint64_t(LLONG_MAX) + 1); + EXPECT_EQ(UMax.getAsSignedConstant().getValue(), LLONG_MAX); + EXPECT_EQ(TooBig.getAsSignedConstant().hasValue(), false); + + // Sanity check some other forms. + auto Data1 = createDataXFormValue(DW_FORM_data1, 120); + auto Data2 = createDataXFormValue(DW_FORM_data2, 32000); + auto Data4 = createDataXFormValue(DW_FORM_data4, 2000000000); + auto Data8 = createDataXFormValue(DW_FORM_data8, 0x1234567812345678LL); + auto LEBMin = createSLEBFormValue(LLONG_MIN); + auto LEBMax = createSLEBFormValue(LLONG_MAX); + auto LEB1 = createSLEBFormValue(-42); + auto LEB2 = createSLEBFormValue(42); + EXPECT_EQ(Data1.getAsSignedConstant().getValue(), 120); + EXPECT_EQ(Data2.getAsSignedConstant().getValue(), 32000); + EXPECT_EQ(Data4.getAsSignedConstant().getValue(), 2000000000); + EXPECT_EQ(Data8.getAsSignedConstant().getValue(), 0x1234567812345678LL); + EXPECT_EQ(LEBMin.getAsSignedConstant().getValue(), LLONG_MIN); + EXPECT_EQ(LEBMax.getAsSignedConstant().getValue(), LLONG_MAX); + EXPECT_EQ(LEB1.getAsSignedConstant().getValue(), -42); + EXPECT_EQ(LEB2.getAsSignedConstant().getValue(), 42); +} + } // end anonymous namespace -- cgit v1.1