[all-commits] [llvm/llvm-project] 829bcb: [-Wunsafe-buffer-usage] Add unsafe buffer checking...

Ziqing Luo via All-commits all-commits at lists.llvm.org
Wed Feb 8 14:12:35 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 829bcb06ec43ab4b56b95ff040ec9d36feeaf06a
      https://github.com/llvm/llvm-project/commit/829bcb06ec43ab4b56b95ff040ec9d36feeaf06a
  Author: Ziqing Luo <ziqing at udel.edu>
  Date:   2023-02-08 (Wed, 08 Feb 2023)

  Changed paths:
    M clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
    M clang/include/clang/Basic/DiagnosticLexKinds.td
    M clang/include/clang/Lex/Preprocessor.h
    M clang/lib/Analysis/UnsafeBufferUsage.cpp
    M clang/lib/Lex/PPLexerChange.cpp
    M clang/lib/Lex/Pragma.cpp
    M clang/lib/Lex/Preprocessor.cpp
    M clang/lib/Sema/AnalysisBasedWarnings.cpp
    A clang/test/SemaCXX/warn-unsafe-buffer-usage-pragma-fixit.cpp
    A clang/test/SemaCXX/warn-unsafe-buffer-usage-pragma-misuse.cpp
    A clang/test/SemaCXX/warn-unsafe-buffer-usage-pragma.cpp
    A clang/test/SemaCXX/warn-unsafe-buffer-usage-pragma.h

  Log Message:
  -----------
  [-Wunsafe-buffer-usage] Add unsafe buffer checking opt-out pragmas

Add a pair of clang pragmas:
- `#pragma clang unsafe_buffer_usage begin` and
- `#pragma clang unsafe_buffer_usage end`,
which specify the start and end of an (unsafe buffer checking) opt-out
region, respectively.

Behaviors of opt-out regions conform to the following rules:

- No nested nor overlapped opt-out regions are allowed. One cannot
  start an opt-out region with `... unsafe_buffer_usage begin` but never
  close it with `... unsafe_buffer_usage end`. Mis-use of the pragmas
  will be warned.
- Warnings raised from unsafe buffer operations inside such an opt-out
  region will always be suppressed. This behavior CANNOT be changed by
  `clang diagnostic` pragmas or command-line flags.
- Warnings raised from unsafe operations outside of such opt-out
  regions may be reported on declarations inside opt-out
  regions. These warnings are NOT suppressed.
- An un-suppressed unsafe operation warning may be attached with
  notes. These notes are NOT suppressed as well regardless of whether
  they are in opt-out regions.

The implementation maintains a separate sequence of location pairs
representing opt-out regions in `Preprocessor`.  The `UnsafeBufferUsage`
analyzer reads the region sequence to check if an unsafe operation is
in an opt-out region. If it is, discard the warning raised from the
operation immediately.

This is a re-land after I reverting it at 9aa00c8a306561c4e3ddb09058e66bae322a0769.
The compilation error should be resolved.

Reviewed by: NoQ

Differential revision: https://reviews.llvm.org/D140179




More information about the All-commits mailing list