aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Frontend/InitPreprocessor.cpp
diff options
context:
space:
mode:
authorJakub Kuderski <kubak@google.com>2021-11-03 20:47:57 -0400
committerJakub Kuderski <kubak@google.com>2021-11-03 20:52:21 -0400
commit3348b841d36e6a189e1bcb30de41b7a8ec8c6991 (patch)
tree296b6c7e367ba83455d56da99c7652e881dd8334 /clang/lib/Frontend/InitPreprocessor.cpp
parent0986433401067c72816450e64d73a79f16cc3c5e (diff)
downloadllvm-3348b841d36e6a189e1bcb30de41b7a8ec8c6991.zip
llvm-3348b841d36e6a189e1bcb30de41b7a8ec8c6991.tar.gz
llvm-3348b841d36e6a189e1bcb30de41b7a8ec8c6991.tar.bz2
Make enum iteration with seq safe by default
By default `llvm::seq` would happily iterate over enums, which may be unsafe if the enum values are not continuous. This patch disable enum iteration with `llvm::seq` and `llvm::seq_inclusive` and adds two new functions: `enum_seq` and `enum_seq_inclusive`. To make sure enum iteration is safe, we require users to declare their enum types as iterable by specializing `enum_iteration_traits<SomeEnum>`. Because it's not always possible to add these traits next to enum definition (e.g., for enums defined in external libraries), we provide an escape hatch to allow iteration on per-callsite basis by passing `force_iteration_on_noniterable_enum`. The main benefit of this approach is that these global declarations via traits can appear just next to enum definitions, making easy to spot when enums are miss-labeled, e.g., after introducing new enum values, whereas `force_iteration_on_noniterable_enum` should stand out and be easy to grep for. This emerged from a discussion with gchatelet@ about reusing llvm's `Sequence.h` in lieu of https://github.com/GPUOpen-Drivers/llpc/blob/dev/lgc/interface/lgc/EnumIterator.h. Reviewed By: dblaikie, gchatelet, aaron.ballman Differential Revision: https://reviews.llvm.org/D107378
Diffstat (limited to 'clang/lib/Frontend/InitPreprocessor.cpp')
0 files changed, 0 insertions, 0 deletions