[all-commits] [llvm/llvm-project] f5ee10: [Clang] Optimize -Wunsafe-buffer-usage. (#125492)

Ivana Ivanovska via All-commits all-commits at lists.llvm.org
Thu Mar 20 03:59:12 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: f5ee10538b68835112323c241ca7db67ca78bf62
      https://github.com/llvm/llvm-project/commit/f5ee10538b68835112323c241ca7db67ca78bf62
  Author: Ivana Ivanovska <iivanovska at google.com>
  Date:   2025-03-20 (Thu, 20 Mar 2025)

  Changed paths:
    M clang/lib/Analysis/UnsafeBufferUsage.cpp

  Log Message:
  -----------
  [Clang] Optimize -Wunsafe-buffer-usage. (#125492)

The Clang disgnostic `-Wunsafe-buffer-usage` was adding up to +15%
compilation time when used. Profiling showed that most of the overhead
comes from the use of ASTMatchers.

This change replaces the ASTMatcher infrastructure with simple matching
functions and keeps the functionality unchanged. It reduces the overhead
added by `-Wunsafe-buffer-usage` by 87.8%, leaving a negligible
additional compilation time of 1.7% when the diagnostic is used.

**Old version without -Wunsafe-buffer-usage:**
```
$ hyperfine -i -w 1 --runs 5 '/tmp/old_clang -c -std=c++20 /tmp/preprocessed.cc -ferror-limit=20' 
Benchmark 1: /tmp/old_clang -c -std=c++20 /tmp/preprocessed.cc -ferror-limit=20
  Time (mean ± σ):     231.035 s ±  3.210 s    [User: 229.134 s, System: 1.704 s]
  Range (min … max):   228.751 s … 236.682 s    5 runs
```

**Old version with -Wunsafe-buffer-usage:**
```
$ hyperfine -i -w 1 --runs 10 '/tmp/old_clang -c -std=c++20 /tmp/preprocessed.cc -ferror-limit=20 -Wunsafe-buffer-usage'
Benchmark 1: /tmp/old_clang -c -std=c++20 /tmp/preprocessed.cc -ferror-limit=20 -Wunsafe-buffer-usage
  Time (mean ± σ):     263.840 s ±  0.854 s    [User: 262.043 s, System: 1.575 s]
  Range (min … max):   262.442 s … 265.142 s    10 runs
```

**New version with -Wunsafe-buffer-usage:**
```
$ hyperfine -i -w 1 --runs 10 '/tmp/new_clang -c -std=c++20 /tmp/preprocessed.cc -ferror-limit=20 -Wunsafe-buffer-usage'
Benchmark 1: /tmp/new_clang -c -std=c++20 /tmp/preprocessed.cc -ferror-limit=20 -Wunsafe-buffer-usage
  Time (mean ± σ):     235.169 s ±  1.408 s    [User: 233.406 s, System: 1.561 s]
  Range (min … max):   232.221 s … 236.792 s    10 runs
```



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list