Skip to content

Commit

Permalink
Enable clang-tidy's modernize-use-default-member-init check (#7662)
Browse files Browse the repository at this point in the history
* Upgrade clang-format and clang-tidy to use v16

(Skipping over 15 entirely in favor of the newest stable version)

* Update presubmit.yml

* Update .clang-tidy

* Update .clang-tidy

* fixes

* Update run-clang-tidy.sh

* Update .clang-tidy

* Update .clang-tidy

* fixes

* Update .clang-tidy

* Update PyHalide.cpp

* Update run-clang-tidy.sh

* Update CodeGen_Vulkan_Dev.cpp

* Update .clang-tidy

* fix

* format
  • Loading branch information
steven-johnson committed Jun 26, 2023
1 parent c28a00f commit c7ca15f
Show file tree
Hide file tree
Showing 27 changed files with 117 additions and 161 deletions.
9 changes: 4 additions & 5 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ Checks: >
-modernize-unary-static-assert,
-modernize-use-auto,
modernize-use-bool-literals,
# TODO: revisit this
-modernize-use-default-member-init,
modernize-use-default-member-init,
modernize-use-emplace,
modernize-use-equals-default,
modernize-use-equals-delete,
Expand Down Expand Up @@ -194,7 +193,7 @@ Checks: >
WarningsAsErrors: '*'
HeaderFilterRegex: '.*'
FormatStyle: 'file'
#CheckOptions:
# - key: modernize-use-default-member-init.UseAssignment
# value: 1
CheckOptions:
- key: modernize-use-default-member-init.UseAssignment
value: 1
...
4 changes: 1 addition & 3 deletions src/CodeGen_C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,7 @@ class TypeInfoGatherer : public IRGraphVisitor {
} // namespace

CodeGen_C::CodeGen_C(ostream &s, const Target &t, OutputKind output_kind, const std::string &guard)
: IRPrinter(s), id("$$ BAD ID $$"), target(t), output_kind(output_kind),
extern_c_open(false), inside_atomic_mutex_node(false), emit_atomic_stores(false),
using_vector_typedefs(false) {
: IRPrinter(s), id("$$ BAD ID $$"), target(t), output_kind(output_kind) {

if (output_kind == CPlusPlusFunctionInfoHeader) {
// If it's a header, emit an include guard.
Expand Down
8 changes: 4 additions & 4 deletions src/CodeGen_C.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class CodeGen_C : public IRPrinter {
bool have_user_context;

/** Track current calling convention scope. */
bool extern_c_open;
bool extern_c_open = false;

/** True if at least one gpu-based for loop is used. */
bool uses_gpu_for_loops;
Expand Down Expand Up @@ -277,13 +277,13 @@ class CodeGen_C : public IRPrinter {

/** Are we inside an atomic node that uses mutex locks?
This is used for detecting deadlocks from nested atomics. */
bool inside_atomic_mutex_node;
bool inside_atomic_mutex_node = false;

/** Emit atomic store instructions? */
bool emit_atomic_stores;
bool emit_atomic_stores = false;

/** true if add_vector_typedefs() has been called. */
bool using_vector_typedefs;
bool using_vector_typedefs = false;

/** Some architectures have private memory for the call stack; this
* means a thread cannot hand pointers to stack memory to another
Expand Down
4 changes: 2 additions & 2 deletions src/CodeGen_GPU_Dev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ class IsBufferConstant : public IRVisitor {
}

public:
bool result;
bool result = true;
const std::string &buffer;

IsBufferConstant(const std::string &b)
: result(true), buffer(b) {
: buffer(b) {
}
};
} // namespace
Expand Down
25 changes: 3 additions & 22 deletions src/CodeGen_LLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,22 +168,9 @@ llvm::GlobalValue::LinkageTypes llvm_linkage(LinkageType t) {
} // namespace

CodeGen_LLVM::CodeGen_LLVM(const Target &t)
: function(nullptr), context(nullptr),
builder(nullptr),
value(nullptr),
very_likely_branch(nullptr),
default_fp_math_md(nullptr),
strict_fp_math_md(nullptr),
: builder(nullptr),

target(t),
void_t(nullptr), i1_t(nullptr), i8_t(nullptr),
i16_t(nullptr), i32_t(nullptr), i64_t(nullptr),
f16_t(nullptr), f32_t(nullptr), f64_t(nullptr),
halide_buffer_t_type(nullptr),
metadata_t_type(nullptr),
argument_t_type(nullptr),
scalar_value_t_type(nullptr),
device_interface_t_type(nullptr),
pseudostack_slot_t_type(nullptr),

wild_u1x_(Variable::make(UInt(1, 0), "*")),
wild_i8x_(Variable::make(Int(8, 0), "*")),
Expand All @@ -209,14 +196,8 @@ CodeGen_LLVM::CodeGen_LLVM(const Target &t)
wild_f32_(Variable::make(Float(32), "*")),
wild_f64_(Variable::make(Float(64), "*")),

inside_atomic_mutex_node(false),
emit_atomic_stores(false),
use_llvm_vp_intrinsics(false),

destructor_block(nullptr),
strict_float(t.has_feature(Target::StrictFloat)),
llvm_large_code_model(t.has_feature(Target::LLVMLargeCodeModel)),
effective_vscale(0) {
llvm_large_code_model(t.has_feature(Target::LLVMLargeCodeModel)) {
initialize_llvm();
}

Expand Down
42 changes: 21 additions & 21 deletions src/CodeGen_LLVM.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ class CodeGen_LLVM : public IRVisitor {
virtual Type upgrade_type_for_argument_passing(const Type &) const;

std::unique_ptr<llvm::Module> module;
llvm::Function *function;
llvm::LLVMContext *context;
llvm::Function *function = nullptr;
llvm::LLVMContext *context = nullptr;
std::unique_ptr<llvm::IRBuilder<llvm::ConstantFolder, llvm::IRBuilderDefaultInserter>> builder;
llvm::Value *value;
llvm::MDNode *very_likely_branch;
llvm::MDNode *default_fp_math_md;
llvm::MDNode *strict_fp_math_md;
llvm::Value *value = nullptr;
llvm::MDNode *very_likely_branch = nullptr;
llvm::MDNode *default_fp_math_md = nullptr;
llvm::MDNode *strict_fp_math_md = nullptr;
std::vector<LoweredArgument> current_function_args;

/** The target we're generating code for */
Expand Down Expand Up @@ -207,16 +207,16 @@ class CodeGen_LLVM : public IRVisitor {

/** Some useful llvm types */
// @{
llvm::Type *void_t, *i1_t, *i8_t, *i16_t, *i32_t, *i64_t, *f16_t, *f32_t, *f64_t;
llvm::StructType *halide_buffer_t_type,
*type_t_type,
*dimension_t_type,
*metadata_t_type,
*argument_t_type,
*scalar_value_t_type,
*device_interface_t_type,
*pseudostack_slot_t_type,
*semaphore_t_type;
llvm::Type *void_t = nullptr, *i1_t = nullptr, *i8_t = nullptr, *i16_t = nullptr, *i32_t = nullptr, *i64_t = nullptr, *f16_t = nullptr, *f32_t = nullptr, *f64_t = nullptr;
llvm::StructType *halide_buffer_t_type = nullptr,
*type_t_type,
*dimension_t_type,
*metadata_t_type = nullptr,
*argument_t_type = nullptr,
*scalar_value_t_type = nullptr,
*device_interface_t_type = nullptr,
*pseudostack_slot_t_type = nullptr,
*semaphore_t_type;

// @}

Expand Down Expand Up @@ -529,10 +529,10 @@ class CodeGen_LLVM : public IRVisitor {

/** Are we inside an atomic node that uses mutex locks?
This is used for detecting deadlocks from nested atomics & illegal vectorization. */
bool inside_atomic_mutex_node;
bool inside_atomic_mutex_node = false;

/** Emit atomic store instructions? */
bool emit_atomic_stores;
bool emit_atomic_stores = false;

/** Can we call this operation with float16 type?
This is used to avoid "emulated" equivalent code-gen in case target has FP16 feature **/
Expand Down Expand Up @@ -640,7 +640,7 @@ class CodeGen_LLVM : public IRVisitor {

/** Controls use of vector predicated intrinsics for vector operations.
* Will be set by certain backends (e.g. RISC V) to control codegen. */
bool use_llvm_vp_intrinsics;
bool use_llvm_vp_intrinsics = false;
// @}

/** Generate a basic dense vector load, with an optional predicate and
Expand All @@ -666,7 +666,7 @@ class CodeGen_LLVM : public IRVisitor {
/** A basic block to branch to on error that triggers all
* destructors. As destructors are registered, code gets added
* to this block. */
llvm::BasicBlock *destructor_block;
llvm::BasicBlock *destructor_block = nullptr;

/** Turn off all unsafe math flags in scopes while this is set. */
bool strict_float;
Expand All @@ -677,7 +677,7 @@ class CodeGen_LLVM : public IRVisitor {
/** Cache the result of target_vscale from architecture specific implementation
* as this is used on every Halide to LLVM type conversion.
*/
int effective_vscale;
int effective_vscale = 0;

/** Assign a unique ID to each producer-consumer and for-loop node. The IDs
* are printed as comments in assembly and used to link visualizations with
Expand Down
4 changes: 2 additions & 2 deletions src/Deinterleave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class StoreCollector : public IRMutator {
StoreCollector(const std::string &name, int stride, int ms,
std::vector<Stmt> &lets, std::vector<Stmt> &ss)
: store_name(name), store_stride(stride), max_stores(ms),
let_stmts(lets), stores(ss), collecting(true) {
let_stmts(lets), stores(ss) {
}

private:
Expand Down Expand Up @@ -57,7 +57,7 @@ class StoreCollector : public IRMutator {
return op;
}

bool collecting;
bool collecting = true;
// These are lets that we've encountered since the last collected
// store. If we collect another store, these "potential" lets
// become lets used by the collected stores.
Expand Down
4 changes: 2 additions & 2 deletions src/ExprUsesVar.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ class ExprUsesVars : public IRGraphVisitor {

public:
ExprUsesVars(const Scope<T> &v, const Scope<Expr> *s = nullptr)
: vars(v), result(false) {
: vars(v) {
scope.set_containing_scope(s);
}
bool result;
bool result = false;
};

/** Test if a statement or expression references or defines any of the
Expand Down
5 changes: 2 additions & 3 deletions src/Func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2811,10 +2811,9 @@ Func::operator Stage() const {
namespace {
class CountImplicitVars : public Internal::IRGraphVisitor {
public:
int count;
int count = 0;

CountImplicitVars(const vector<Expr> &exprs)
: count(0) {
CountImplicitVars(const vector<Expr> &exprs) {
for (const auto &e : exprs) {
e.accept(this);
}
Expand Down
19 changes: 8 additions & 11 deletions src/FuseGPUThreadLoops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ class NormalizeDimensionality : public IRMutator {
const ExtractBlockSize &block_size;
const DeviceAPI device_api;

int depth;
int max_depth;
int depth = 0;
int max_depth = 0;

Stmt wrap(Stmt s) {
if (depth != 0) {
Expand Down Expand Up @@ -181,7 +181,7 @@ class NormalizeDimensionality : public IRMutator {

public:
NormalizeDimensionality(const ExtractBlockSize &e, DeviceAPI device_api)
: block_size(e), device_api(device_api), depth(0), max_depth(0) {
: block_size(e), device_api(device_api) {
}
};

Expand Down Expand Up @@ -293,9 +293,9 @@ class ExtractSharedAndHeapAllocations : public IRMutator {
private:
map<string, SharedAllocation *> shared;

bool in_threads;
bool in_threads = false;

int barrier_stage;
int barrier_stage = 0;

const DeviceAPI device_api;

Expand Down Expand Up @@ -1022,9 +1022,7 @@ class ExtractSharedAndHeapAllocations : public IRMutator {
}

ExtractSharedAndHeapAllocations(DeviceAPI d)
: in_threads(false),
barrier_stage(0),
device_api(d),
: device_api(d),
thread_id_var_name(unique_name('t')),
num_threads_var_name(unique_name('t')),
may_merge_allocs_of_different_type(device_api != DeviceAPI::OpenGLCompute &&
Expand Down Expand Up @@ -1203,7 +1201,7 @@ class ExtractRegisterAllocations : public IRMutator {
};

class InjectThreadBarriers : public IRMutator {
bool in_threads, injected_barrier;
bool in_threads = false, injected_barrier;

using IRMutator::visit;

Expand Down Expand Up @@ -1351,8 +1349,7 @@ class InjectThreadBarriers : public IRMutator {

public:
InjectThreadBarriers(ExtractSharedAndHeapAllocations &sha, ExtractRegisterAllocations &ra)
: in_threads(false),
block_allocs(sha),
: block_allocs(sha),
register_allocs(ra) {
}
};
Expand Down
7 changes: 3 additions & 4 deletions src/Introspection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ typedef uint64_t llvm_offset_t;

class DebugSections {

bool calibrated;
bool calibrated = false;

struct FieldFormat {
uint64_t name = 0, form = 0;
Expand Down Expand Up @@ -190,10 +190,9 @@ class DebugSections {
vector<TypeInfo> types;

public:
bool working;
bool working = false;

DebugSections(const std::string &binary)
: calibrated(false), working(false) {
DebugSections(const std::string &binary) {
std::string binary_path = binary;
#ifdef __APPLE__
size_t last_slash = binary_path.rfind('/');
Expand Down
4 changes: 2 additions & 2 deletions src/Parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ struct ParameterContents {
const int dimensions;
const std::string name;
Buffer<> buffer;
uint64_t data;
uint64_t data = 0;
int host_alignment;
std::vector<BufferConstraint> buffer_constraints;
Expr scalar_default, scalar_min, scalar_max, scalar_estimate;
const bool is_buffer;
MemoryType memory_type = MemoryType::Auto;

ParameterContents(Type t, bool b, int d, const std::string &n)
: type(t), dimensions(d), name(n), buffer(Buffer<>()), data(0),
: type(t), dimensions(d), name(n), buffer(Buffer<>()),
host_alignment(t.bytes()), buffer_constraints(std::max(0, dimensions)), is_buffer(b) {
// stride_constraint[0] defaults to 1. This is important for
// dense vectorization. You can unset it by setting it to a
Expand Down
4 changes: 2 additions & 2 deletions src/PartitionLoops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ class ExprUsesInvalidBuffers : public IRVisitor {

public:
ExprUsesInvalidBuffers(const Scope<> &buffers)
: invalid_buffers(buffers), invalid(false) {
: invalid_buffers(buffers) {
}
bool invalid;
bool invalid = false;
};

/** Check if any references to buffers in an expression is invalid. */
Expand Down
4 changes: 2 additions & 2 deletions src/PrintLoopNest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ namespace {
class PrintLoopNest : public IRVisitor {
public:
PrintLoopNest(std::ostream &output, const map<string, Function> &e)
: out(output), env(e), indent(0) {
: out(output), env(e) {
}

private:
std::ostream &out;
const map<string, Function> &env;
int indent;
int indent = 0;

Scope<Expr> constants;

Expand Down
Loading

0 comments on commit c7ca15f

Please sign in to comment.