Skip to content

Preserve values of structural template arguments #247

Description

@lm-sousa

Problem

clang-dumper currently serializes TemplateArgument::StructuralValue using only the value's type. Clava stores that type in TemplateArgumentStructuralValue, but loses the evaluated APValue.

For example:

template <double D>
struct FloatArg {
    int values[D > 1.0 ? 2 : 1];
};

FloatArg<1.25> first;
FloatArg<0.5> second;

The source-facing TemplateSpecializationType keeps each written expression. The canonical ClassTemplateSpecializationDecl arguments, however, both reach Clava as StructuralValue(type = double) with no value. This loses the information that identifies each specialization.

The specialization declarations are still useful because Clang puts substituted members on them. In this example, the two values fields have types int[2] and int[1].

Suggested direction

  • Keep written argument expressions on TemplateSpecializationType.
  • Serialize the useful evaluated value for StructuralValue as typed data, not as an ID with no resolvable Clava node.
  • Cover the APValue kinds that structural template arguments need. Do not dump every cached ConstantExpr APValue.
  • Keep implicit specialization declarations for analysis, but do not emit them as separately written source.
  • Update clang-dumper and Clava together because the line protocol has no record version.
  • Add focused floating-point and class-valued template argument tests.

Related discussion: #241 (comment)

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