Skip to content

Commit 72e14fb

Browse files
committed
[NFC][hwasan] Reduce nesting in function
1 parent fbacf70 commit 72e14fb

File tree

1 file changed

+55
-55
lines changed

1 file changed

+55
-55
lines changed

compiler-rt/lib/hwasan/hwasan_report.cpp

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -218,63 +218,63 @@ static void PrintStackAllocations(const StackAllocationsRingBuffer *sa,
218218
uptr pc_mask = (1ULL << kRecordFPShift) - 1;
219219
uptr pc = record & pc_mask;
220220
FrameInfo frame;
221-
if (Symbolizer::GetOrInit()->SymbolizeFrame(pc, &frame)) {
222-
for (LocalInfo &local : frame.locals) {
223-
if (!local.has_frame_offset || !local.has_size || !local.has_tag_offset)
224-
continue;
225-
if (!(local.name && internal_strlen(local.name)) &&
226-
!(local.function_name && internal_strlen(local.function_name)) &&
227-
!(local.decl_file && internal_strlen(local.decl_file)))
228-
continue;
229-
tag_t obj_tag = base_tag ^ local.tag_offset;
230-
if (obj_tag != addr_tag)
231-
continue;
232-
// Guess top bits of local variable from the faulting address, because
233-
// we only store bits 4-19 of FP (bits 0-3 are guaranteed to be zero).
234-
uptr local_beg = (fp + local.frame_offset) |
235-
(untagged_addr & ~(uptr(kRecordFPModulus) - 1));
236-
uptr local_end = local_beg + local.size;
237-
238-
if (!found_local) {
239-
Printf("\nPotentially referenced stack objects:\n");
240-
found_local = true;
241-
}
242-
243-
uptr offset;
244-
const char *whence;
245-
const char *cause;
246-
if (local_beg <= untagged_addr && untagged_addr < local_end) {
247-
offset = untagged_addr - local_beg;
248-
whence = "inside";
249-
cause = "use-after-scope";
250-
} else if (untagged_addr >= local_end) {
251-
offset = untagged_addr - local_end;
252-
whence = "after";
253-
cause = "stack-buffer-overflow";
254-
} else {
255-
offset = local_beg - untagged_addr;
256-
whence = "before";
257-
cause = "stack-buffer-overflow";
258-
}
259-
Decorator d;
260-
Printf("%s", d.Error());
261-
Printf("Cause: %s\n", cause);
262-
Printf("%s", d.Default());
263-
Printf("%s", d.Location());
264-
StackTracePrinter::GetOrInit()->RenderSourceLocation(
265-
&location, local.decl_file, local.decl_line, /* column= */ 0,
266-
common_flags()->symbolize_vs_style,
267-
common_flags()->strip_path_prefix);
268-
Printf(
269-
"%p is located %zd bytes %s a %zd-byte local variable %s [%p,%p) "
270-
"in %s %s\n",
271-
untagged_addr, offset, whence, local_end - local_beg, local.name,
272-
local_beg, local_end, local.function_name, location.data());
273-
location.clear();
274-
Printf("%s\n", d.Default());
221+
if (!Symbolizer::GetOrInit()->SymbolizeFrame(pc, &frame))
222+
continue;
223+
for (LocalInfo &local : frame.locals) {
224+
if (!local.has_frame_offset || !local.has_size || !local.has_tag_offset)
225+
continue;
226+
if (!(local.name && internal_strlen(local.name)) &&
227+
!(local.function_name && internal_strlen(local.function_name)) &&
228+
!(local.decl_file && internal_strlen(local.decl_file)))
229+
continue;
230+
tag_t obj_tag = base_tag ^ local.tag_offset;
231+
if (obj_tag != addr_tag)
232+
continue;
233+
// Guess top bits of local variable from the faulting address, because
234+
// we only store bits 4-19 of FP (bits 0-3 are guaranteed to be zero).
235+
uptr local_beg = (fp + local.frame_offset) |
236+
(untagged_addr & ~(uptr(kRecordFPModulus) - 1));
237+
uptr local_end = local_beg + local.size;
238+
239+
if (!found_local) {
240+
Printf("\nPotentially referenced stack objects:\n");
241+
found_local = true;
242+
}
243+
244+
uptr offset;
245+
const char *whence;
246+
const char *cause;
247+
if (local_beg <= untagged_addr && untagged_addr < local_end) {
248+
offset = untagged_addr - local_beg;
249+
whence = "inside";
250+
cause = "use-after-scope";
251+
} else if (untagged_addr >= local_end) {
252+
offset = untagged_addr - local_end;
253+
whence = "after";
254+
cause = "stack-buffer-overflow";
255+
} else {
256+
offset = local_beg - untagged_addr;
257+
whence = "before";
258+
cause = "stack-buffer-overflow";
275259
}
276-
frame.Clear();
260+
Decorator d;
261+
Printf("%s", d.Error());
262+
Printf("Cause: %s\n", cause);
263+
Printf("%s", d.Default());
264+
Printf("%s", d.Location());
265+
StackTracePrinter::GetOrInit()->RenderSourceLocation(
266+
&location, local.decl_file, local.decl_line, /* column= */ 0,
267+
common_flags()->symbolize_vs_style,
268+
common_flags()->strip_path_prefix);
269+
Printf(
270+
"%p is located %zd bytes %s a %zd-byte local variable %s [%p,%p) "
271+
"in %s %s\n",
272+
untagged_addr, offset, whence, local_end - local_beg, local.name,
273+
local_beg, local_end, local.function_name, location.data());
274+
location.clear();
275+
Printf("%s\n", d.Default());
277276
}
277+
frame.Clear();
278278
}
279279

280280
if (found_local)

0 commit comments

Comments
 (0)