Skip to content

Commit

Permalink
WithHelperKey breaks on clang with asserts on (#26500)
Browse files Browse the repository at this point in the history
`WithHelperKey` breaks on clang with asserts

`WithHelperKey` is a template class that has an inline field that it
uses to produce a memory address that is used as a data key. This PR is
not concerned with the underlying causes for this unconventional design.
Rather, this change aims to fix a clang crash that happens whenever
nearly daily when building brave with a clang binary that has asserts on.
In particular, it looks like some combination of the key address and the
use `std::addressof` cause clang to assert and crash.

This change works around this crash by returning the address of the
inline variable using `&`. For a repro of the crash, see:

  https://godbolt.org/z/M6oq6b3sz

An issue has been created for this issue as well

  llvm/llvm-project#111188
  • Loading branch information
cdesouza-chromium authored Nov 12, 2024
1 parent 2f34c66 commit babe3bb
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion components/brave_rewards/core/rewards_engine_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class RewardsEngineHelper : public base::SupportsUserData::Data {
template <typename T>
class WithHelperKey {
public:
static const void* GetHelperKey() { return std::addressof(kHelperKey); }
static const void* GetHelperKey() { return &kHelperKey; }

private:
static inline const int kHelperKey = 0;
Expand Down

0 comments on commit babe3bb

Please sign in to comment.