This is an archive of the discontinued LLVM Phabricator instance.

NFC. opt_storage refactored toward thread local options

Authored by yrouban on Oct 19 2018, 2:49 AM.



This patch refactors the template class cl::opt_storage<DataType, false, true> to make it possible to override the access to the stored DataType. This is needed for the patch

  • D53424 Enable thread specific cl::opt values for multi-threaded support

Having DataType extended by cl::opt_storage it is impossible to control reads and writes of the base DataType using instances of cl::opt_storage because the dot-operator cannot be overridden.

cl::opt<std::string> MyOption;
if (MyOption.empty())

In this snippet empty() is applied directly to the base type of MyOption (which is DataType) without use of any operator.

This patch makes cl::opt_storage<DataType, false, true> wrap DataType as a field as it is done in cl::opt_storage<DataType, false, false>.
In addition to the getValue() methods to access to the field there are added operators *, -> and data type conversion for convenience.
Two templates are added for most frequently used methods for DataType=std::string: empty() and StringRef().
All places in the LLVM code are fixed accordingly. There are several fixes in project clang (D53428).
All changes except in CommandLine.h are straightforward. Similar changes should be done in all dependent projects if needed.

Diff Detail