Commit fff469c8 authored by Lukasz Anforowicz's avatar Lukasz Anforowicz Committed by Commit Bot

Emit constexpr-initialized fields as candidates for exclusion.

After this CL, the rewriter will detect fields that are initialized
with non-nullptr value in constexpr constructors.  Such fields will
be emitted as candidates for exclusion via --exclude-fields cmdline
parameter.

This CL should help ensure that the build is successful, once we
stop excluding |const char* fields| from the rewrite.  In particular,
performance_manager::PriorityAndReason::reason_ field needs to be
excluded in practice.  Additionally, this CL should help to automate
excluding of the various base::FeatureParam fields/scenarios (they
are currently covered via manual-fields-to-ignore.txt).

Bug: 1069567
Change-Id: I122a329577f77d8172e26f189b5155af742a33c2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2495719
Auto-Submit: Łukasz Anforowicz <lukasza@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#820840}
parent 005ae158
......@@ -1050,6 +1050,18 @@ int main(int argc, const char* argv[]) {
match_finder.addMatcher(overlapping_field_decl_matcher,
&overlapping_field_decl_writer);
// Matches fields initialized with a non-nullptr value in a constexpr
// constructor. See also the testcase in tests/gen-constexpr-ctor-test.cc.
auto constexpr_ctor_initialized_field_matcher = cxxConstructorDecl(allOf(
isConstexpr(),
forEachConstructorInitializer(allOf(
forField(field_decl_matcher), withInitializer(unless(ignoringImplicit(
cxxNullPtrLiteralExpr())))))));
FilteredExprWriter constexpr_ctor_initialized_field_writer(
&output_helper, "constexpr-ctor-initializer");
match_finder.addMatcher(constexpr_ctor_initialized_field_matcher,
&constexpr_ctor_initialized_field_writer);
// See the doc comment for the isInMacroLocation matcher
// and the testcases in tests/gen-macro-test.cc.
auto macro_field_decl_matcher =
......
==== BEGIN EDITS ====
include-user-header:::/usr/local/google/home/lukasza/src/chromium4/src/tools/clang/rewrite_raw_ptr_fields/tests/gen-constexpr-ctor-actual.cc:::-1:::-1:::base/memory/checked_ptr.h
r:::/usr/local/google/home/lukasza/src/chromium4/src/tools/clang/rewrite_raw_ptr_fields/tests/gen-constexpr-ctor-actual.cc:::1045:::5:::CheckedPtr<int>
r:::/usr/local/google/home/lukasza/src/chromium4/src/tools/clang/rewrite_raw_ptr_fields/tests/gen-constexpr-ctor-actual.cc:::1153:::5:::CheckedPtr<int>
r:::/usr/local/google/home/lukasza/src/chromium4/src/tools/clang/rewrite_raw_ptr_fields/tests/gen-constexpr-ctor-actual.cc:::1271:::5:::CheckedPtr<int>
==== END EDITS ====
==== BEGIN FIELD FILTERS ====
Foo::ptr2_ # constexpr-ctor-initializer
Foo::ptr_ # constexpr-ctor-initializer
==== END FIELD FILTERS ====
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This file (and other gen-*-test.cc files) tests generation of output for
// --field-filter-file and therefore the expectations file
// (gen-char-expected.txt) needs to be compared against the raw output of the
// rewriter (rather than against the actual edits result). This makes the test
// incompatible with other tests, which require passing --apply-edits switch to
// test_tool.py and so to disable the test it is named *-test.cc rather than
// *-original.cc.
//
// To run the test use tools/clang/rewrite_raw_ptr_fields/tests/run_all_tests.py
class Foo {
public:
constexpr explicit Foo(int* ptr) : ptr_(ptr), ptr2_(ptr), null_(nullptr) {}
private:
// CheckedPtr(T*) constructor is non-constexpr and therefore CheckedPtr fields
// cannot be initialized in constexpr constructors - such fields should be
// emitted as candidates for the --field-filter-file.
int* ptr_;
// Testing that all initializers and fields are covered (i.e. not just the
// first one).
int* ptr2_;
// CheckedPtr(nullptr_t) is constexpr and therefore the field below doesn't
// need to be skipped.
int* null_;
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment