Skip to content

Group the node-reuse diagnostics so they can be silenced. - #1881

Draft
vgvassilev wants to merge 1 commit into
masterfrom
clad-plugin-node-reuse-group
Draft

Group the node-reuse diagnostics so they can be silenced.#1881
vgvassilev wants to merge 1 commit into
masterfrom
clad-plugin-node-reuse-group

Conversation

@vgvassilev

Copy link
Copy Markdown
Owner

The AST-integrity checks added with the no-shared-node work emit a warning a user cannot turn off, and in a release build their findSharedNode/findPrimalSharedNode walks run on every generated derivative even when nobody wants the diagnostic -- pure overhead for a check that only ever fires on a clad bug.

Route both diagnostics into the "clad-plugin-node-reuse" group (a subgroup of clad's "clad-plugin" group) through the getCustomDiagID group overload, so -Wno-clad-plugin-node-reuse -- or the wider -Wno-clad-plugin / -Wno-plugin -- silences them. A release build then consults isIgnored and skips the walks entirely when the group is off, so the checks cost nothing once silenced; a debug build always runs them so the asserts still catch a regression.

The group overload is a recent clang addition, so a compile-time trait detects it and older clang keeps the ungrouped two-argument form.

The AST-integrity checks added with the no-shared-node work emit a
warning a user cannot turn off, and in a release build their
findSharedNode/findPrimalSharedNode walks run on every generated
derivative even when nobody wants the diagnostic -- pure overhead for
a check that only ever fires on a clad bug.

Route both diagnostics into the "clad-plugin-node-reuse" group (a
subgroup of clad's "clad-plugin" group) through the getCustomDiagID
group overload, so -Wno-clad-plugin-node-reuse -- or the wider
-Wno-clad-plugin / -Wno-plugin -- silences them. A release build then
consults isIgnored and skips the walks entirely when the group is off,
so the checks cost nothing once silenced; a debug build always runs
them so the asserts still catch a regression.

The group overload is a recent clang addition, so a compile-time trait
detects it and older clang keeps the ungrouped two-argument form.
@vgvassilev

Copy link
Copy Markdown
Owner Author

Land when/if llvm/llvm-project#208538 lands.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

// other warning. Detect the three-argument getCustomDiagID(Level, format,
// group) overload; older clang has only the two-argument form and the
// diagnostics stay ungrouped.
constexpr llvm::StringLiteral CladNodeReuseGroup = "clad-plugin-node-reuse";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "llvm::StringLiteral" is directly included [misc-include-cleaner]

lib/Differentiator/DerivativeBuilder.cpp:51:

- #include <memory>
+ #include <llvm/ADT/StringRef.h>
+ #include <memory>

template <typename T>
struct HasPluginDiagGroups<
T, std::void_t<decltype(std::declval<T&>().getCustomDiagID(
clang::DiagnosticsEngine::Warning, std::declval<const char (&)[2]>(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not declare C-style arrays, use std::array<> instead [cppcoreguidelines-avoid-c-arrays]

           clang::DiagnosticsEngine::Warning, std::declval<const char (&)[2]>(),
                                                                 ^

// group overload.
template <unsigned N>
unsigned getIntegrityDiagID(clang::DiagnosticsEngine& Diags,
const char (&Message)[N]) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not declare C-style arrays, use std::array<> instead [cppcoreguidelines-avoid-c-arrays]

                            const char (&Message)[N]) {
                                  ^

// (or -Wno-clad-plugin, or -Wno-plugin) silences them.
unsigned SharedDiagID = getIntegrityDiagID(
Diags,
"clad internally reused a '%0' AST node while differentiating %1; "

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: argument comment missing for literal argument 'Message' [bugprone-argument-comment]

Suggested change
"clad internally reused a '%0' AST node while differentiating %1; "
/*Message=*/"clad internally reused a '%0' AST node while differentiating %1; "

"https://github.com/vgvassilev/clad");
unsigned PrimalDiagID = getIntegrityDiagID(
Diags,
"clad reused a '%0' AST node from the original function while "

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: argument comment missing for literal argument 'Message' [bugprone-argument-comment]

Suggested change
"clad reused a '%0' AST node from the original function while "
/*Message=*/"clad reused a '%0' AST node from the original function while "

@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.94737% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
lib/Differentiator/DerivativeBuilder.cpp 78.94% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant