Repository navigation
Weaver resolves aliases to the canonical declaration: source-spelled qualified names (e.g. high_resolution_clock) are lost #259
Description
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::nowwhen<chrono>resolves via libstdc++ (Linux, and Windows while the bundled clang used libstdc++ headers)std::chrono::steady_clock::nowvia libc++ (macOS)std::chrono::steady_clock::nowvia 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:
- 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 namedhigh_resolution_clock::now—high_resolution_clockis an alias, so the canonical decl genuinely issystem_clock::now/steady_clock::now. ClangAstParserstores that string verbatim (DeclDataParser.parseNamedDeclData,NamedDecl.QUALIFIED_PREFIX).- 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
- clang-dumper: for call/reference nodes, also emit the source-spelled qualified name (or qualifier) taken from the
MemberExpr/DeclRefExprnested-name-specifier. - ClavaWeaver: expose it on the Call join point (e.g. a source-spelled
qualifiedName/nameattribute alongsidedeclaration, 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
Settersfailure appeared when the dumper release moved tov18.1.8_*. - Alternative interim mitigation for CI: add a windows-specific
Settersresult file mirroring the macOS one. The alias-preserving call attribute is the proper fix and would let those files be collapsed into one.
Activity