tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit b651a44293e7522ecfcd18d15141b8e9ed4beb4c
parent f8479b2158358ad6ebd1c3eaeab2a3f6864401a9
Author: Chris Peterson <cpeterson@mozilla.com>
Date:   Tue,  9 Dec 2025 00:01:29 +0000

Bug 2002864 - Replace MOZ_CONSTINIT with C++20 constinit in GlobalVariableInitializationChecker.cpp. r=firefox-static-analysis-reviewers,marco

Differential Revision: https://phabricator.services.mozilla.com/D274502

Diffstat:
Mbuild/clang-plugin/GlobalVariableInitializationChecker.cpp | 4++--
Mbuild/clang-plugin/tests/TestGlobalVariableInitialization.cpp | 11+++++------
2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/build/clang-plugin/GlobalVariableInitializationChecker.cpp b/build/clang-plugin/GlobalVariableInitializationChecker.cpp @@ -32,7 +32,7 @@ void GlobalVariableInitializationChecker::check( if (const VarDecl *VD = Result.Nodes.getNodeAs<VarDecl>("flagged-constinit_global")) { if (VD->hasConstantInitialization()) { - diag(VD->getBeginLoc(), "Global variable flagged as MOZ_RUNINIT but actually has constinit initialisation. Consider flagging it as constexpr or MOZ_CONSTINIT instead.", + diag(VD->getBeginLoc(), "Global variable flagged as MOZ_RUNINIT but actually has constinit initialisation. Consider flagging it as constexpr or constinit instead.", DiagnosticIDs::Error); } else { @@ -58,7 +58,7 @@ void GlobalVariableInitializationChecker::check( if (getFilename(SM, Loc).ends_with(".cc")) { return; } - diag(VD->getBeginLoc(), "Global variable has runtime initialisation, try to remove it, make it constexpr or MOZ_CONSTINIT if possible, or as a last resort flag it as MOZ_RUNINIT.", + diag(VD->getBeginLoc(), "Global variable has runtime initialisation, try to remove it, make it constexpr or constinit if possible, or as a last resort flag it as MOZ_RUNINIT.", DiagnosticIDs::Error); } } diff --git a/build/clang-plugin/tests/TestGlobalVariableInitialization.cpp b/build/clang-plugin/tests/TestGlobalVariableInitialization.cpp @@ -1,5 +1,4 @@ #define MOZ_RUNINIT __attribute__((annotate("moz_global_var"))) -#define MOZ_CONSTINIT [[clang::require_constant_initialization]] #define MOZ_GLOBAL_CLASS __attribute__((annotate("moz_global_class"))) // POD Type @@ -22,7 +21,7 @@ struct Global { Global(); }; -Global g2; // expected-error {{Global variable has runtime initialisation, try to remove it, make it constexpr or MOZ_CONSTINIT if possible, or as a last resort flag it as MOZ_RUNINIT.}} +Global g2; // expected-error {{Global variable has runtime initialisation, try to remove it, make it constexpr or constinit if possible, or as a last resort flag it as MOZ_RUNINIT.}} // Global with extern constructor *but* marked MOZ_GLOBAL_CLASS struct MOZ_GLOBAL_CLASS GlobalCls { @@ -43,7 +42,7 @@ struct InvalidRuninitGlobal { constexpr InvalidRuninitGlobal() {} }; -MOZ_RUNINIT InvalidRuninitGlobal g5; // expected-error {{Global variable flagged as MOZ_RUNINIT but actually has constinit initialisation. Consider flagging it as constexpr or MOZ_CONSTINIT instead.}} +MOZ_RUNINIT InvalidRuninitGlobal g5; // expected-error {{Global variable flagged as MOZ_RUNINIT but actually has constinit initialisation. Consider flagging it as constexpr or constinit instead.}} constexpr InvalidRuninitGlobal g5a; struct InvalidRuninitGlobal2 { @@ -54,14 +53,14 @@ MOZ_RUNINIT InvalidRuninitGlobal2 g5b; // expected-error {{Global variable flagg InvalidRuninitGlobal2 g5c; // Static variable with extern constructor -Global g6; // expected-error {{Global variable has runtime initialisation, try to remove it, make it constexpr or MOZ_CONSTINIT if possible, or as a last resort flag it as MOZ_RUNINIT.}} +Global g6; // expected-error {{Global variable has runtime initialisation, try to remove it, make it constexpr or constinit if possible, or as a last resort flag it as MOZ_RUNINIT.}} // Static variable with extern constructor within a function void foo() { static Global g7; } // Global variable with extern constructor in a namespace -namespace bar {Global g8;} // expected-error {{Global variable has runtime initialisation, try to remove it, make it constexpr or MOZ_CONSTINIT if possible, or as a last resort flag it as MOZ_RUNINIT.}} +namespace bar {Global g8;} // expected-error {{Global variable has runtime initialisation, try to remove it, make it constexpr or constinit if possible, or as a last resort flag it as MOZ_RUNINIT.}} // Static variable with extern constructor in a class class foobar {static Global g9;}; -Global foobar::g9; // expected-error {{Global variable has runtime initialisation, try to remove it, make it constexpr or MOZ_CONSTINIT if possible, or as a last resort flag it as MOZ_RUNINIT.}} +Global foobar::g9; // expected-error {{Global variable has runtime initialisation, try to remove it, make it constexpr or constinit if possible, or as a last resort flag it as MOZ_RUNINIT.}}