diff --git a/clang/lib/Analysis/LifetimeSafety.cpp b/clang/lib/Analysis/LifetimeSafety.cpp index 0dd5716d93fb6..d016c6f12e82e 100644 --- a/clang/lib/Analysis/LifetimeSafety.cpp +++ b/clang/lib/Analysis/LifetimeSafety.cpp @@ -910,10 +910,13 @@ template static llvm::ImmutableSet join(llvm::ImmutableSet A, llvm::ImmutableSet B, typename llvm::ImmutableSet::Factory &F) { + if (A == B) + return A; if (A.getHeight() < B.getHeight()) std::swap(A, B); for (const T &E : B) - A = F.add(A, E); + if (!A.contains(E)) + A = F.add(A, E); return A; } @@ -947,10 +950,11 @@ join(llvm::ImmutableMap A, llvm::ImmutableMap B, for (const auto &Entry : B) { const K &Key = Entry.first; const V &ValB = Entry.second; - if (const V *ValA = A.lookup(Key)) - A = F.add(A, Key, JoinValues(*ValA, ValB)); - else + const V *ValA = A.lookup(Key); + if (!ValA) A = F.add(A, Key, ValB); + else if (*ValA != ValB) + A = F.add(A, Key, JoinValues(*ValA, ValB)); } return A; } diff --git a/clang/test/Analysis/LifetimeSafety/benchmark.py b/clang/test/Analysis/LifetimeSafety/benchmark.py index 4421fe9a81e21..2373f9984eecd 100644 --- a/clang/test/Analysis/LifetimeSafety/benchmark.py +++ b/clang/test/Analysis/LifetimeSafety/benchmark.py @@ -252,7 +252,7 @@ def generate_markdown_report(results: dict) -> str: report.append(" ".join(row)) report.append("\n**Complexity Analysis:**\n") - report.append("| Analysis Phase | Complexity O(nk) |") + report.append("| Analysis Phase | Complexity O(nk) | ") report.append("|:------------------|:--------------------------|") analysis_phases = { @@ -302,7 +302,7 @@ def run_single_test( source_file, ] - result = subprocess.run(clang_command, capture_output=True, text=True) + result = subprocess.run(clang_command, capture_output=True, text=True, timeout=60) if result.returncode != 0: print(f"Compilation failed for N={n}!", file=sys.stderr) @@ -334,24 +334,25 @@ def run_single_test( os.makedirs(args.output_dir, exist_ok=True) print(f"Benchmark files will be saved in: {os.path.abspath(args.output_dir)}\n") + # Maximize 'n' values while keeping execution time under 10s. test_configurations = [ { "name": "cycle", "title": "Pointer Cycle in Loop", "generator_func": generate_cpp_cycle_test, - "n_values": [10, 25, 50, 75, 100, 150], + "n_values": [25, 50, 75, 100], }, { "name": "merge", "title": "CFG Merges", "generator_func": generate_cpp_merge_test, - "n_values": [10, 50, 100, 200, 400, 800], + "n_values": [400, 1000, 2000, 5000], }, { "name": "nested_loops", "title": "Deeply Nested Loops", "generator_func": generate_cpp_nested_loop_test, - "n_values": [10, 50, 100, 200, 400, 800], + "n_values": [50, 100, 150, 200], }, ]