https://bugs.llvm.org/show_bug.cgi?id=46159
Linux Kernel code using is try as a variable name (as its 'C' code they can), they interpreted as the 'try' keyword by clang-format causing odd formatting (see below)
We have no specific 'C' code handling, as this code could easily be in a '.h' file so need to handle this not based on extension alone.
This revision adds a FormatTokenLexer rule to identify either try blocks "try {" or function try block "try :" and if not, rename the "try" token to be an identifier
static size_t get_kcore_size(int *nphdr, size_t *phdrs_len, size_t *notes_len,
size_t *data_offset)
{
size_t try, size;
struct kcore_list *m;
*nphdr = 1; /* PT_NOTE */
size = 0;
list_for_each_entry(m, &kclist_head, list) {
try = kc_vaddr_to_offset((size_t)m->addr + m->size);
if (try1 > size)
size = try1;
*nphdr = *nphdr + 1;
}
}
clang-format-10 formats it as:
static size_t get_kcore_size(int *nphdr, size_t *phdrs_len, size_t *notes_len,
size_t *data_offset) {
size_t try
, size;
struct kcore_list *m;
*nphdr = 1; /* PT_NOTE */
size = 0;
list_for_each_entry(m, &kclist_head, list) {
try
= kc_vaddr_to_offset((size_t)m->addr + m->size);
if (try > size)
size = try
;
*nphdr = *nphdr + 1;
}
}
Please rename to something that includes colon or is more general. Just using Brace is misleading.