Skip to content

Default-initialized arguments inserted by DefaultArguments pass are not cloned #5473

@kfcripps

Description

@kfcripps
extern void __e(in bit<1> x = 1w1);

control C() {
    apply {
        __e();
        __e();
    }
}

control proto();
package top(proto p);

top(C()) main;

The tmp-0002-DefaultArguments_1_DoDefaultArguments.p4 output of p4test --dump tmp --top4 DefaultArguments tmp.p4 -v contains:

...
control C() {
    apply /*
    <BlockStatement>(1942) */
    {
        /*
      <MethodCallStatement>(1945)
        <MethodCallExpression>(1946)
          <PathExpression>(738)
            __e
          <Vector<Type>>(44), size=0
          <Vector<Argument>>(1951), size=1
            <Argument>(1954)
              <Constant>(721) 1
                <Type_Bits>(462) */
        __e(/*
            <Argument>(1954)
              <Constant>(721) 1
                <Type_Bits>(462) */
x = 1w1);
        /*
      <MethodCallStatement>(1955)
        <MethodCallExpression>(1956)
          <PathExpression>(744)
            __e
          <Vector<Type>>(50), size=0
          <Vector<Argument>>(1961), size=1
            <Argument>(1964)
              <Constant>(721) 1
                <Type_Bits>(462) */
        __e(/*
            <Argument>(1964)
              <Constant>(721) 1
                <Type_Bits>(462) */
x = 1w1);
    }
}
...

Note that the 1w1 constant inserted for the x argument to both __e() calls has a node id of 721. This can cause unexpected problems in later passes that expect each of these method calls' argument's expressions to be visited. Since each __e() method call's argument expression points to the same IR::Node, only the expression of the x argument belonging to the first __e() method call will be visited.

I believe the DefaultArguments pass should clone the 1w1 constant instead of each __e() call's argument pointing to the same IR::Constant expression.

Metadata

Metadata

Assignees

No one assigned

    Labels

    coreTopics concerning the core segments of the compiler (frontend, midend, parser)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions