Skip to content

Commit 48c97a3

Browse files
author
git apple-llvm automerger
committed
Merge commit '58b71bb621fe' from apple/stable/20200714 into swift/main
2 parents e3f2a56 + 58b71bb commit 48c97a3

File tree

4 files changed

+76
-12
lines changed

4 files changed

+76
-12
lines changed

llvm/cmake/modules/AddLLVM.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,6 +2104,13 @@ function(setup_dependency_debugging name)
21042104
set_target_properties(${name} PROPERTIES RULE_LAUNCH_COMPILE ${sandbox_command})
21052105
endfunction()
21062106

2107+
# If the sources at the given `path` are under version control, set `out_var`
2108+
# to the the path of a file which will be modified when the VCS revision
2109+
# changes, attempting to create that file if it does not exist; if no such
2110+
# file exists and one cannot be created, instead set `out_var` to the
2111+
# empty string.
2112+
#
2113+
# If the sources are not under version control, do not define `out_var`.
21072114
function(find_first_existing_vc_file path out_var)
21082115
if(NOT EXISTS "${path}")
21092116
return()
@@ -2125,6 +2132,7 @@ function(find_first_existing_vc_file path out_var)
21252132
RESULT_VARIABLE touch_head_result
21262133
ERROR_QUIET)
21272134
if (NOT touch_head_result EQUAL 0)
2135+
set(${out_var} "" PARENT_SCOPE)
21282136
return()
21292137
endif()
21302138
endif()

llvm/include/llvm/Support/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ if(LLVM_APPEND_VC_REV)
1111
# A fake version file and is not expected to exist. It is being used to
1212
# force regeneration of VCSRevision.h for source directory with no write
1313
# permission available.
14-
if (NOT llvm_vc)
14+
if (llvm_vc STREQUAL "")
1515
set(fake_version_inc "${CMAKE_CURRENT_BINARY_DIR}/__FakeVCSRevision.h")
1616
endif()
1717
endif()

llvm/lib/DebugInfo/DWARF/DWARFDebugArangeSet.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,19 +132,20 @@ Error DWARFDebugArangeSet::extract(DWARFDataExtractor data,
132132

133133
uint64_t end_offset = Offset + full_length;
134134
while (*offset_ptr < end_offset) {
135+
uint64_t EntryOffset = *offset_ptr;
135136
arangeDescriptor.Address = data.getUnsigned(offset_ptr, HeaderData.AddrSize);
136137
arangeDescriptor.Length = data.getUnsigned(offset_ptr, HeaderData.AddrSize);
137138

138-
if (arangeDescriptor.Length == 0) {
139-
// Each set of tuples is terminated by a 0 for the address and 0
140-
// for the length.
141-
if (arangeDescriptor.Address == 0 && *offset_ptr == end_offset)
139+
// Each set of tuples is terminated by a 0 for the address and 0
140+
// for the length.
141+
if (arangeDescriptor.Length == 0 && arangeDescriptor.Address == 0) {
142+
if (*offset_ptr == end_offset)
142143
return ErrorSuccess();
143144
return createStringError(
144145
errc::invalid_argument,
145146
"address range table at offset 0x%" PRIx64
146-
" has an invalid tuple (length = 0) at offset 0x%" PRIx64,
147-
Offset, *offset_ptr - tuple_size);
147+
" has a premature terminator entry at offset 0x%" PRIx64,
148+
Offset, EntryOffset);
148149
}
149150

150151
ArangeDescriptors.push_back(arangeDescriptor);

llvm/unittests/DebugInfo/DWARF/DWARFDebugArangeSetTest.cpp

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h"
10+
#include "llvm/Testing/Support/Error.h"
1011
#include "gtest/gtest.h"
1112

1213
using namespace llvm;
@@ -166,24 +167,78 @@ TEST(DWARFDebugArangeSet, UnevenLength) {
166167
"of the tuple size");
167168
}
168169

169-
TEST(DWARFDebugArangeSet, ZeroLengthEntry) {
170+
TEST(DWARFDebugArangeSet, ZeroAddressEntry) {
170171
static const char DebugArangesSecRaw[] =
171-
"\x24\x00\x00\x00" // Length
172+
"\x1c\x00\x00\x00" // Length
172173
"\x02\x00" // Version
173174
"\x00\x00\x00\x00" // Debug Info Offset
174175
"\x04" // Address Size
175176
"\x00" // Segment Selector Size
176177
"\x00\x00\x00\x00" // Padding
177178
"\x00\x00\x00\x00" // Entry1: Address
178179
"\x01\x00\x00\x00" // Length
180+
"\x00\x00\x00\x00" // Termination tuple
181+
"\x00\x00\x00\x00";
182+
DWARFDataExtractor Extractor(
183+
StringRef(DebugArangesSecRaw, sizeof(DebugArangesSecRaw) - 1),
184+
/*IsLittleEndian=*/true,
185+
/*AddressSize=*/4);
186+
DWARFDebugArangeSet Set;
187+
uint64_t Offset = 0;
188+
ASSERT_THAT_ERROR(Set.extract(Extractor, &Offset),
189+
Succeeded());
190+
auto Range = Set.descriptors();
191+
auto Iter = Range.begin();
192+
ASSERT_EQ(std::distance(Iter, Range.end()), 1u);
193+
EXPECT_EQ(Iter->Address, 0u);
194+
EXPECT_EQ(Iter->Length, 1u);
195+
}
196+
197+
TEST(DWARFDebugArangeSet, ZeroLengthEntry) {
198+
static const char DebugArangesSecRaw[] =
199+
"\x1c\x00\x00\x00" // Length
200+
"\x02\x00" // Version
201+
"\x00\x00\x00\x00" // Debug Info Offset
202+
"\x04" // Address Size
203+
"\x00" // Segment Selector Size
204+
"\x00\x00\x00\x00" // Padding
205+
"\x01\x00\x00\x00" // Entry1: Address
206+
"\x00\x00\x00\x00" // Length
207+
"\x00\x00\x00\x00" // Termination tuple
208+
"\x00\x00\x00\x00";
209+
DWARFDataExtractor Extractor(
210+
StringRef(DebugArangesSecRaw, sizeof(DebugArangesSecRaw) - 1),
211+
/*IsLittleEndian=*/true,
212+
/*AddressSize=*/4);
213+
DWARFDebugArangeSet Set;
214+
uint64_t Offset = 0;
215+
ASSERT_THAT_ERROR(Set.extract(Extractor, &Offset),
216+
Succeeded());
217+
auto Range = Set.descriptors();
218+
auto Iter = Range.begin();
219+
ASSERT_EQ(std::distance(Iter, Range.end()), 1u);
220+
EXPECT_EQ(Iter->Address, 1u);
221+
EXPECT_EQ(Iter->Length, 0u);
222+
}
223+
224+
TEST(DWARFDebugArangesSet, PrematureTerminator) {
225+
static const char DebugArangesSecRaw[] =
226+
"\x24\x00\x00\x00" // Length
227+
"\x02\x00" // Version
228+
"\x00\x00\x00\x00" // Debug Info Offset
229+
"\x04" // Address Size
230+
"\x00" // Segment Selector Size
231+
"\x00\x00\x00\x00" // Padding
232+
"\x00\x00\x00\x00" // Entry1: Premature
233+
"\x00\x00\x00\x00" // terminator
179234
"\x01\x00\x00\x00" // Entry2: Address
180-
"\x00\x00\x00\x00" // Length (invalid)
235+
"\x01\x00\x00\x00" // Length
181236
"\x00\x00\x00\x00" // Termination tuple
182237
"\x00\x00\x00\x00";
183238
ExpectExtractError(
184239
DebugArangesSecRaw,
185-
"address range table at offset 0x0 has an invalid tuple (length = 0) "
186-
"at offset 0x18");
240+
"address range table at offset 0x0 has a premature "
241+
"terminator entry at offset 0x10");
187242
}
188243

189244
} // end anonymous namespace

0 commit comments

Comments
 (0)