mc-imperial / dredd

Framework for evaluating C/C++ compiler testing tools
Apache License 2.0
11 stars 3 forks source link

Dredd incorrectly apply mutation to lvalue inside a function that expect lvalue #259

Closed JonathanFoo0523 closed 1 month ago

JonathanFoo0523 commented 1 month ago

Applying dredd to the following file

#include <tuple>
struct foo {
  int b : 2;
};

int main() {
  const foo d = foo();
  std::tie(d.b);
}

results in

#include <tuple>
struct foo {
  int b : 2;
};

void c() {
  const foo d = foo();
  if (!__dredd_enabled_mutation(2)) { std::tie(__dredd_replace_expr_int_zero(d.b, 0)); }
}

which, when compile, results in error related to

no matching function for call to 'tie': not viable: expects an lvalue for 1st argument
afd commented 1 month ago

@JonathanFoo0523 is it possible to find a reproducer that doesn't use std::tie, but instead calls some made up function, foo or whatever, that has the appropriate signature to trigger this issue?

I wonder if it will turn out to be template-specific.

afd commented 1 month ago

Here is a simpler reproducer:

template<typename T> void bloop(T& x) { }

struct foo {
  int b : 2;
};

int main() {
  const foo d = foo();
  bloop(d.b);
}
JonathanFoo0523 commented 1 month ago

The AST:

FunctionDecl 0x558b47a670d0 <line:7:1, line:10:1> line:7:5 main 'int ()'
  `-CompoundStmt 0x558b47a85f00 <col:12, line:10:1>
    |-DeclStmt 0x558b47a85a48 <line:8:3, col:22>
    | `-VarDecl 0x558b47a671f0 <col:3, col:21> col:13 used d 'const foo':'const foo' cinit
    |   `-ImplicitCastExpr 0x558b47a85a30 <col:17, col:21> 'const foo':'const foo' <NoOp>
    |     `-CXXTemporaryObjectExpr 0x558b47a678d8 <col:17, col:21> 'foo':'foo' 'void () noexcept' zeroing
    `-ExprWithCleanups 0x558b47a85ee8 <line:9:3, col:12> 'void'
      `-CallExpr 0x558b47a85e90 <col:3, col:12> 'void'
        |-ImplicitCastExpr 0x558b47a85e78 <col:3> 'void (*)(const short &)' <FunctionToPointerDecay>
        | `-DeclRefExpr 0x558b47a85df0 <col:3> 'void (const short &)' lvalue Function 0x558b47a85ce8 'bloop' 'void (const short &)' (FunctionTemplate 0x558b47a66ce0 'bloop')
        `-MaterializeTemporaryExpr 0x558b47a85ed0 <col:9, col:11> 'const short':'const short' lvalue
          `-ImplicitCastExpr 0x558b47a85eb8 <col:9, col:11> 'short' <LValueToRValue>
            `-MemberExpr 0x558b47a85ac8 <col:9, col:11> 'const short' lvalue bitfield .b 0x558b47a67010
              `-DeclRefExpr 0x558b47a85aa8 <col:9> 'const foo':'const foo' lvalue Var 0x558b47a671f0 'd' 'const foo':'const foo'