This is an archive of the discontinued LLVM Phabricator instance.

[scudo] Make Options a reference for functions.
ClosedPublic

Authored by cferris on Jul 26 2023, 2:32 PM.

Details

Summary

Modify all places that use the Options structure to be a const
reference. The underlying structure is a u32 so making it a
reference doesn't really do anything. However, if the structure
changes in the future it already works and avoids future coders
wondering why a structure is being passed by value. This also
makes it clear that the Options should not be modified in those functions.

Diff Detail

Event Timeline

cferris created this revision.Jul 26 2023, 2:32 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 26 2023, 2:32 PM
Herald added subscribers: yaneury, Enna1. · View Herald Transcript
cferris requested review of this revision.Jul 26 2023, 2:32 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 26 2023, 2:32 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
This revision is now accepted and ready to land.Jul 26 2023, 2:37 PM
cferris updated this revision to Diff 544523.Jul 26 2023, 2:40 PM

Remove the const Options &Options = Options.load();

That's too aggressive and there is already a copy.

cferris updated this revision to Diff 544524.Jul 26 2023, 2:42 PM

Actually do a clang-format.

Just did a quick look on the type Options, it's a wrapper of AtomicOptions which contains a single atomic_32 data member. The change may make it require 64 bits space. If we want to assume that Options will be extended then passing by reference shows more value here. (Or maybe I misunderstand something here) I agree that making it passing by reference may be reasonable in terms of software architecture. No strong opinion here, will leave you to do the final decision.

cferris edited the summary of this revision. (Show Details)Jul 26 2023, 4:51 PM

Yeah, I was thinking about this and it doesn't do much. However, I do think the const is useful just to make sure the compiler catches any places where we try to modify the value. And even though making it a reference doesn't really do anything, it also prevents people from coming along and asking why a structure is being passed on the stack.

So I think it's reasonable to leave this as is, but I changed the description to be clearer about this.

This revision was automatically updated to reflect the committed changes.