[all-commits] [llvm/llvm-project] 09bf7e: [Testing] Allow custom markers in llvm::Annotation...

Harlen Batagelo via All-commits all-commits at lists.llvm.org
Mon Jun 1 11:27:03 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 09bf7ef7d7848e4c78d3790a51dc28d9f157e777
      https://github.com/llvm/llvm-project/commit/09bf7ef7d7848e4c78d3790a51dc28d9f157e777
  Author: Harlen Batagelo <hbatagelo at gmail.com>
  Date:   2026-06-01 (Mon, 01 Jun 2026)

  Changed paths:
    M llvm/include/llvm/Testing/Annotations/Annotations.h
    M llvm/lib/Testing/Annotations/Annotations.cpp
    M llvm/unittests/Testing/Annotations/AnnotationsTest.cpp

  Log Message:
  -----------
  [Testing] Allow custom markers in llvm::Annotations (#195570)

The current annotation markers can conflict with several language
constructs. Notably, `[[ ]]` and `^` collide with C++ attributes (e.g.,
`[[nodiscard]]`), the C++26 reflection operator (`^^int`), and
Objective-C blocks (`void (^foo)(void)`). Similarly, `$` can conflict
with identifiers that also use `$` with `-fdollars-in-identifiers`, as
well as with C++26 code that uses `$` as raw-string delimiters or as a
preprocessing token
([P2558R2](https://www.open-std.org/JTC1/SC22/WG21/docs/papers/2023/p2558r2.html)).

Because the markers are currently hardcoded in `llvm::Annotations`,
existing workarounds have to rely on digraphs or macro substitution via
implicit `#define`s. These approaches reduce readability and make tests
cumbersome to write. This PR alleviates these issues by adding support
for custom markers. It adds an overloaded `Annotations` constructor that
accepts a new `Annotations::Markers` struct. For example, to use `~` for
point, `@` for name, and `{{`/`}}` for range:

```cpp
Annotations Example(R"cpp(
  @name(payload){{[[nodiscard]] int foo(int x);}}~
)cpp", {"~", "@", "{{", "}}"});
```

Alternatively, we can use setters to customize the markers individually:
```cpp
Annotations Example(R"cpp(
  @name(payload){{[[nodiscard]] int foo(int x);}}~
)cpp", Annotations::Markers().setPoint("~")
                             .setName("@@")
                             .setRangeBegin("{{")
                             .setRangeEnd("}}"));
```

Using longer markers:
```cpp
Annotations Example(R"cpp(
  $$name(payload)[[[[[nodiscard]] int foo(int x);]]]^^
)cpp", {"^^", "$$", "[[[", "]]]"});
```

Using multi-byte characters:
```cpp
Annotations Example(R"cpp(
  🏷️name(payload)πŸ‘‰[[nodiscard]] int foo(int x);πŸ‘ˆπŸŽ―
)cpp", {"🎯", "🏷️", "πŸ‘‰", "πŸ‘ˆ"});
```

The existing single-argument constructor delegates to the new overload,
preserving backward compatibility.

PS: The original code has a FIXME comment mentioning alternative
approaches, such as escaping and changing the default syntax. While
valid, escaping would increase visual noise, and changing the default
syntax would break existing tests. The approach proposed here provides
the flexibility to choose a syntax that is clean for a specific context
and is backward compatible. See https://reviews.llvm.org/D59814 for
earlier discussion about these alternative design choices.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list