[PATCH] D83211: [clang][cli] Factor out call to EXTRACTOR in generateCC1CommandLine (NFC)
Jan Svoboda via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 26 05:15:30 PST 2020
jansvoboda11 updated this revision to Diff 307838.
jansvoboda11 added a comment.
Remove lifetime comment
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D83211/new/
https://reviews.llvm.org/D83211
Files:
clang/lib/Frontend/CompilerInvocation.cpp
llvm/unittests/Option/CMakeLists.txt
Index: llvm/unittests/Option/CMakeLists.txt
===================================================================
--- llvm/unittests/Option/CMakeLists.txt
+++ llvm/unittests/Option/CMakeLists.txt
@@ -6,6 +6,7 @@
set(LLVM_TARGET_DEFINITIONS Opts.td)
tablegen(LLVM Opts.inc -gen-opt-parser-defs)
+
add_public_tablegen_target(OptsTestTableGen)
add_llvm_unittest(OptionTests
Index: clang/lib/Frontend/CompilerInvocation.cpp
===================================================================
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -4015,13 +4015,17 @@
void CompilerInvocation::generateCC1CommandLine(
SmallVectorImpl<const char *> &Args, StringAllocator SA) const {
+ // Capture the extracted value as a lambda argument to avoid potential issues
+ // with lifetime extension of the reference.
#define OPTION_WITH_MARSHALLING( \
PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE, \
NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX) \
- if (((FLAGS) & options::CC1Option) && \
- (ALWAYS_EMIT || EXTRACTOR(this->KEYPATH) != (DEFAULT_VALUE))) { \
- DENORMALIZER(Args, SPELLING, SA, TABLE_INDEX, EXTRACTOR(this->KEYPATH)); \
+ if ((FLAGS)&options::CC1Option) { \
+ [&](const auto &Extracted) { \
+ if (ALWAYS_EMIT || Extracted != (DEFAULT_VALUE)) \
+ DENORMALIZER(Args, SPELLING, SA, TABLE_INDEX, Extracted); \
+ }(EXTRACTOR(this->KEYPATH)); \
}
#define OPTION_WITH_MARSHALLING_BOOLEAN( \
@@ -4029,10 +4033,10 @@
HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE, \
NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX, NEG_ID, \
NEG_SPELLING) \
- if (((FLAGS)&options::CC1Option) && \
- (ALWAYS_EMIT || EXTRACTOR(this->KEYPATH) != DEFAULT_VALUE)) { \
- DENORMALIZER(Args, SPELLING, NEG_SPELLING, SA, TABLE_INDEX, \
- EXTRACTOR(this->KEYPATH)); \
+ if ((FLAGS)&options::CC1Option) { \
+ bool Extracted = EXTRACTOR(this->KEYPATH); \
+ if (ALWAYS_EMIT || Extracted != (DEFAULT_VALUE)) \
+ DENORMALIZER(Args, SPELLING, NEG_SPELLING, SA, TABLE_INDEX, Extracted); \
}
#include "clang/Driver/Options.inc"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83211.307838.patch
Type: text/x-patch
Size: 2904 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201126/e9602cf2/attachment.bin>
More information about the cfe-commits
mailing list