Skip to content

[BUG] Miscompilation "double jump" #95

@fwc

Description

@fwc

The following program miscompiles.

#include <nautilus/core.hpp>
#include <nautilus/Engine.hpp>
#include <cassert>

using namespace nautilus;

#define max(a,b) \
    ({ __typeof__ (a) _a = (a); \
       __typeof__ (b) _b = (b); \
       _a > _b ? _a : _b; })

void test(val<int*> x) {
    *x = (val<int>) max(
        (val<int>) (*x)
        ,
        (val<int>) 100
    );
}

int main() {
  engine::Options options;
  options.setOption("engine.Compilation", true);
  options.setOption("dump.all", true);
  auto engine = engine::NautilusEngine(options);
  auto function = engine.registerFunction(test);
  int x = 0;
  function(&x);
  std::cout << x << std::endl;
  assert(x == 100);
}

With d434082, I get the following after_ssa.trace:

B0($1:ptr)
	LOAD	$5	$1	:i32
	CONST	$6	100	:i32
	GT	$7	$5	$6	:bool
	CMP	$8	$7	B1($1,$5)	B2($1,$5)	:void
B1($2:ptr,$5:i32)
	JMP	$0	B3($2,$5)	:void
B2($2:ptr,$5:i32)
	JMP	$0	B3($2,$5)	:void
B3($2:ptr,$5:i32) ControlFlowMerge
	STORE	$12	$2	$5	:void
	RETURN	$0	:void

So afaics the final value of x is always its initial value and never 100.

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