Skip to content

Phase 3: -Wreorder を潰して -Werror=reorder を有効化 - #54

Merged
thawk105 merged 1 commit into
masterfrom
werror-reorder
May 13, 2026
Merged

Phase 3: -Wreorder を潰して -Werror=reorder を有効化#54
thawk105 merged 1 commit into
masterfrom
werror-reorder

Conversation

@thawk105

Copy link
Copy Markdown
Owner

#43 Phase 3 のサブタスク。-Wreorder (20 件ユニーク) を潰し、ccbench_add_protocol()-Werror=reorder を追加する。

修正概要

すべて TxExecutor (10 protocols) と TxNode (oze) のコンストラクタで member initializer list の順序がクラス内のメンバ宣言順と一致していなかったケース。C++ の初期化は宣言順で行われるので、initializer list の順は無視される。「見た目の順に初期化されている」と読み手が思い込むのを防ぐため、宣言順に並べ替え。

各箇所でメンバ初期化式に副作用が無いことを確認 (純粋なリファレンス bind / コピー / TxScanCallback(this) のような前提のない式) してから順序のみを変更。挙動の変化は無し。

修正ファイル

箇所 クラス
cc/cicada/include/transaction.hh:65 TxExecutor
cc/d2pl/include/transaction.hh:60 TxExecutor
cc/ermia/include/transaction.hh:57 TxExecutor
cc/mocc/include/transaction.hh:62-63 TxExecutor (callback_ が先頭宣言)
cc/mvto/include/transaction.hh:58 TxExecutor
cc/oze/include/oze.hh:40-49 TxNode (2 コンストラクタ)
cc/oze/include/transaction.hh:75 TxExecutor
cc/si/include/transaction.hh:57 TxExecutor
cc/silo/include/transaction.hh:69 TxExecutor
cc/ss2pl/include/transaction.hh:46 TxExecutor
cc/tictoc/include/transaction.hh:58 TxExecutor

真のバグ

無し。順序変更で挙動が変わるパターン (Foo(int x) : a_(x++), b_(x) のような副作用持ち) は混じっていなかった。

CMake

 target_compile_options(${target} PRIVATE
   -Werror=maybe-uninitialized
   -Werror=unused-but-set-variable
-  -Werror=unused-label)
+  -Werror=unused-label
+  -Werror=reorder)

Test plan

  • GCC 13 Release / -DENABLE_SANITIZER=OFF: 34/34
  • GCC 11 Debug + ASan: 34/34
  • CI 緑

Related

#43 Phase 3 のサブタスク。-Wreorder の 20 件 (ユニーク) を潰し、
ccbench_add_protocol() に -Werror=reorder を追加する。

すべて TxExecutor (10 protocols) と TxNode (oze) のコンストラクタで
member initializer list の順序がクラス内のメンバ宣言順と一致していな
かったケース。C++ の初期化は宣言順で行われるため、initializer list の
順は無視され、見た目の順に初期化されると思い込むと UB の温床になる。
今回各箇所を「メンバが副作用を持たない (リファレンス bind / 単純なコ
ピー / TxScanCallback(this) のような前提のない式)」ことを確認した上
で initializer の順序のみを宣言順に並べ替えた。意味的な動作変更はな
し、ただし宣言順を変えないと潰せない箇所は無かった。

修正ファイル (12)
=================

  cc/cicada/include/transaction.hh:65    TxExecutor
  cc/d2pl/include/transaction.hh:60      TxExecutor
  cc/ermia/include/transaction.hh:57     TxExecutor
  cc/mocc/include/transaction.hh:62-63   TxExecutor (callback_ が先頭宣言)
  cc/mvto/include/transaction.hh:58      TxExecutor
  cc/oze/include/oze.hh:40-49            TxNode (2 個のコンストラクタ)
  cc/oze/include/transaction.hh:75       TxExecutor
  cc/si/include/transaction.hh:57        TxExecutor
  cc/silo/include/transaction.hh:69      TxExecutor
  cc/ss2pl/include/transaction.hh:46     TxExecutor
  cc/tictoc/include/transaction.hh:58    TxExecutor

各 protocol で order が違うのは、それぞれの TxExecutor クラスでメン
バ宣言順が違うため。基本的に `thid_ -> result_ -> backoff_ -> quit_
-> callback_` のような形に揃っているが、cicada は `result_` の後に
`quit_, callback_, backoff_, thid_` の宣言順、mocc は `callback_`
が一番上にあるなど protocol ごとに微妙に違う。

真のバグ
========

無し。順序を変えても挙動が変わるパターン (Foo(int x) : a_(x++), b_(x))
は無かった。すべて純粋な「混乱しやすい順序の整理」。

CMake
=====

  -Werror=maybe-uninitialized
  -Werror=unused-but-set-variable
  -Werror=unused-label
+ -Werror=reorder

Test plan
=========

- GCC 13 + Release / -ENABLE_SANITIZER=OFF: 34/34
- GCC 11 + Debug + ASan:                    34/34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant