[clang] [Format] Fix isStartOfName to recognize attributes (PR #76804)

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 4 01:49:47 PST 2024


================
@@ -1698,8 +1698,6 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) {
           /*BasedOnStyle=*/"google",
       },
   };
-  GoogleStyle.AttributeMacros.push_back("GUARDED_BY");
----------------
ilya-biryukov wrote:

They are attribute macros indeed, the problem is that we actually need more. The ones used with fields are at least:
- ABSL_PT_GUARDED_BY
- ABSL_ACQUIRED_AFTER
- ABSL_ACQUIRED_BEFORE
- ABSL_GUARDED_BY_FIXME

We could also consider including the annotations for functions, but the patch only broke formatting for variables, so it's not strictly necessary to unblock the release.

If we want to also include the ones that are used with functions (they are not strictly necessary because `clang-format` does a decent job there without config), we would need to add at least these:
- ABSL_EXCLUSIVE_LOCKS_REQUIRED
- ABSL_LOCKS_EXCLUDED
- ABSL_LOCK_RETURNED
- ABSL_EXCLUSIVE_LOCK_FUNCTION
- ABSL_EXCLUSIVE_TRYLOCK_FUNCTION
- ABSL_SHARED_TRYLOCK_FUNCTION
- ABSL_ASSERT_EXCLUSIVE_LOCK
- ABSL_ASSERT_SHARED_LOCK
- ABSL_NO_THREAD_SAFETY_ANALYSIS


I am not sure how to best approach it and would appreciate some guidance here. Should we have all these attribute macros inside `AttributeMacros` or should we aim for clang-format formatting them reasonably without configuration?

https://github.com/llvm/llvm-project/pull/76804


More information about the cfe-commits mailing list