From a729f654b0a058d3c30e785a08822ad23d1aca96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Bastian?= Date: Fri, 5 Jul 2019 15:29:47 +0200 Subject: [PATCH] csmith check: fix break in pyramid detection --- csmith/check_generated_eh_frame.py | 35 +++++++++++++++++++----------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/csmith/check_generated_eh_frame.py b/csmith/check_generated_eh_frame.py index aea3913..52ce672 100755 --- a/csmith/check_generated_eh_frame.py +++ b/csmith/check_generated_eh_frame.py @@ -59,6 +59,24 @@ def detect_clang_flat_to_pyramid(rows): [k'; k[ """ + def is_flatness_row(row, prev_cfa, prev_loc): + for reg in row: + if reg not in ["LOC", "CFA", "ra"] and row[reg] != "u": + return prev_cfa, prev_loc, True + cfa = row["CFA"] + if cfa[:4] != "rsp+": + return prev_cfa, prev_loc, True + cfa_offset = int(cfa[4:]) + if cfa_offset != prev_cfa + 8: + return prev_cfa, prev_loc, True + prev_cfa += 8 + loc = row["LOC"] + if loc > prev_loc + 2: + return prev_cfa, prev_loc, True + prev_loc = loc + + return prev_cfa, prev_loc, False + def try_starting_at(start_row): if len(rows) < start_row + 1: # Ensure we have at least the start row return rows, False @@ -69,22 +87,13 @@ def detect_clang_flat_to_pyramid(rows): first_cfa = int(rows[start_row]["CFA"][4:]) prev_cfa = first_cfa prev_loc = rows[start_row]["LOC"] + for row in rows[start_row + 1 :]: - for reg in row: - if reg not in ["LOC", "CFA", "ra"] and row[reg] != "u": - break - cfa = row["CFA"] - if cfa[:4] != "rsp+": + prev_cfa, prev_loc, flatness = is_flatness_row(row, prev_cfa, prev_loc) + if flatness: break - cfa_offset = int(cfa[4:]) - if cfa_offset != prev_cfa + 8: - break - prev_cfa += 8 - loc = row["LOC"] - if loc > prev_loc + 2: - break - prev_loc = loc flatness_row_id += 1 + flatness_row_id += 1 if flatness_row_id - start_row <= 1 or flatness_row_id >= len(rows): return rows, False # nothing to change