Skip to content

Weaver resolves aliases to the canonical declaration: source-spelled qualified names (e.g. high_resolution_clock) are lost #259

Description

@lm-sousa

Note

opencode-go/omen-alpha responding of behalf of @lm-sousa

Summary

Clava's $call.declaration.qualifiedName reports the canonical declaration's qualified name, so when user code references a function through a standard-library alias, the alias is lost and the reported name depends on which STL Clava was compiled against. Concretely:

auto a = std::chrono::high_resolution_clock::now();

reports:

  • std::chrono::system_clock::now when <chrono> resolves via libstdc++ (Linux, and Windows while the bundled clang used libstdc++ headers)
  • std::chrono::steady_clock::now via libc++ (macOS)
  • std::chrono::steady_clock::now via MSVC STL (Windows with the current clang 18 dumper build)

There is no way for a Clava script to recover the name as written in the source (std::chrono::high_resolution_clock::now), even though that information exists in the AST (MemberExpr's nested-name-specifier spells the alias).

Why this matters

This is not just cosmetic — it makes goldens and platform behavior diverge. The legacy integration test Setters currently needs platform-specific result files purely because of this (ClavaWeaver/resources/clava/test/weaver/cpp/results/Setters.js.txt expects system_clock, Setters.js.macos.txt expects steady_clock, and there is no windows file — the windows MSVC resolution is why Setters fails on the windows-latest CI jobs of the current stacked branches, e.g. PR #258's base).

If the weaver exposed the source-spelled qualified name, a single golden (high_resolution_clock::now) would be valid on every platform.

Root cause

The pipeline loses the alias before the weaver ever sees it:

  1. The clang-dumper emits the declaration's qualified prefix using clang's canonical semantics (Decl::getQualifiedNameAsString()), which walks through typedefs/using-aliases. In the clang AST there is no declaration named high_resolution_clock::nowhigh_resolution_clock is an alias, so the canonical decl genuinely is system_clock::now/steady_clock::now.
  2. ClangAstParser stores that string verbatim (DeclDataParser.parseNamedDeclData, NamedDecl.QUALIFIED_PREFIX).
  3. The weaver concatenates it (ANamedDecl.getQualifiedNameImpl() / NamedDecl.getFullyQualifiedName()).

Alias information only exists at the reference site: a MemberExpr's qualifier spelling. The declaration itself is shared by all references and cannot report three different names — so the fix belongs at the call/reference level, not on the decl attribute (which must stay canonical for setQualifiedName/setQualifiedPrefix renaming to work).

Proposed fix

  1. clang-dumper: for call/reference nodes, also emit the source-spelled qualified name (or qualifier) taken from the MemberExpr/DeclRefExpr nested-name-specifier.
  2. ClavaWeaver: expose it on the Call join point (e.g. a source-spelled qualifiedName/name attribute alongside declaration, which keeps pointing at the canonical decl).

Notes

  • Behavior is consistent across clang 16 and 18 dumper builds; the clang 16 → 18 bump only changed which canonical decl the windows STL's alias chain resolves to, which is why the windows Setters failure appeared when the dumper release moved to v18.1.8_*.
  • Alternative interim mitigation for CI: add a windows-specific Setters result file mirroring the macOS one. The alias-preserving call attribute is the proper fix and would let those files be collapsed into one.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions