Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Core Grammars:
- fix(rust) recognize `\\` and `\"` char-literal escapes so highlighting doesn't leak, issue #4351 [Sarath Francis][]
- fix(cmake) only highlight standalone numbers, not digits that begin an identifier (e.g. `3rdparty`), issue #4170 [MarkXian][]
- fix(cpp) require a word boundary before numeric literals so digits inside identifiers aren't highlighted as numbers, issue #4231 [Mark Xian][]
- fix(c) only match real `atomic_*` type names, not C11 atomic functions, issue #3837 [MarkXian][]
- enh(python) add missing builtins: `aiter` and `anext` (Python 3.10), `frozendict` and `sentinel` (Python 3.15) [Hugo van Kemenade][]

Documentation:
Expand Down
44 changes: 43 additions & 1 deletion src/languages/c.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,53 @@ export default function(hljs) {
+ ')';


// C11 <stdatomic.h> atomic type names. This is an explicit whitelist so that
// C11 atomic *functions* (atomic_init, atomic_store, atomic_load,
// atomic_fetch_add, ...) are not mistakenly highlighted as types. See #3837.
const ATOMIC_TYPES = regex.concat(/\batomic_/, regex.either(
'bool',
'char',
'schar',
'uchar',
'short',
'ushort',
'int',
'uint',
'long',
'ulong',
'llong',
'ullong',
'char16_t',
'char32_t',
'wchar_t',
'int_least8_t',
'uint_least8_t',
'int_least16_t',
'uint_least16_t',
'int_least32_t',
'uint_least32_t',
'int_least64_t',
'uint_least64_t',
'int_fast8_t',
'uint_fast8_t',
'int_fast16_t',
'uint_fast16_t',
'int_fast32_t',
'uint_fast32_t',
'int_fast64_t',
'uint_fast64_t',
'intptr_t',
'uintptr_t',
'size_t',
'ptrdiff_t',
'intmax_t',
'uintmax_t'
), /\b/);
const TYPES = {
className: 'type',
variants: [
{ begin: '\\b[a-z\\d_]*_t\\b' },
{ match: /\batomic_[a-z]{3,6}\b/ }
{ match: ATOMIC_TYPES }
]

};
Expand Down
7 changes: 7 additions & 0 deletions test/markup/c/atomic-types.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<span class="hljs-type">atomic_int</span> x;
<span class="hljs-type">atomic_bool</span> flag;
<span class="hljs-type">atomic_uint</span> counter;
atomic_store(&amp;x, <span class="hljs-number">1</span>);
atomic_load(&amp;x);
atomic_init(&amp;x, <span class="hljs-number">0</span>);
atomic_fetch_add(&amp;x, <span class="hljs-number">2</span>);
7 changes: 7 additions & 0 deletions test/markup/c/atomic-types.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
atomic_int x;
atomic_bool flag;
atomic_uint counter;
atomic_store(&x, 1);
atomic_load(&x);
atomic_init(&x, 0);
atomic_fetch_add(&x, 2);