Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brilc key error #322

Open
oflatt opened this issue May 7, 2024 · 2 comments
Open

Brilc key error #322

oflatt opened this issue May 7, 2024 · 2 comments

Comments

@oflatt
Copy link
Contributor

oflatt commented May 7, 2024

Here's a bril file that causes brilc to report the following error:

File "/Users/oflatt/eggcc/./bril-llvm/brilc", line 161, in __init__
    types[i['dest']] = types[i['args'][0]]
KeyError: 'v68__1'

Perhaps the bril code is invalid in some way? Or there's a brilc bug

Bril code:

@orig_main(v0: int, v1: int) {
  print v0;
}
@main {
  v0_: int = const 10;
  v1_: int = const 1;
  v2_: int = const 1000;
  v3_: int = id v0_;
  v4_: int = id v1_;
  v5_: int = id v2_;
.v6_:
  v7_: bool = lt v3_ v5_;
  br v7_ .v8_ .v9_;
.v8_:
  v10_: int = const 10;
  v11_: int = id v3_;
  v12_: int = id v4_;
  v13_: int = id v10_;
  v14_: int = id v5_;
.v15_:
  v16_: bool = lt v13_ v14_;
  br v16_ .v17_ .v18_;
.v17_:
  v19_: int = const 0;
  v20_: int = id v13_;
  v21_: int = id v11_;
  v22_: int = id v19_;
.v23_:
  v24_: bool = lt v21_ v20_;
  br v24_ .v25_ .v26_;
.v25_:
  v27_: int = sub v20_ v21_;
  v28_: int = id v20_;
  v29_: int = id v27_;
  v30_: int = id v21_;
  v31_: bool = id v24_;
  v32_: int = id v22_;
.v33_:
  v34_: bool = eq v22_ v29_;
  br v34_ .v35_ .v36_;
.v35_:
  v37_: bool = const false;
  v38_: int = id v20_;
  v39_: bool = id v37_;
  v40_: int = id v21_;
  v41_: int = id v22_;
.v42_:
  v43_: bool = not v34_;
  v20_: int = id v38_;
  v21_: int = id v40_;
  v22_: int = id v22_;
  br v43_ .v23_ .v44_;
.v44_:
  print v20_;
  v45_: bool = const true;
  v46_: int = add v12_ v13_;
  v47_: int = id v11_;
  v48_: int = id v12_;
  v49_: bool = id v45_;
  v50_: int = id v46_;
  v51_: int = id v14_;
.v52_:
  v11_: int = id v11_;
  v12_: int = id v12_;
  v13_: int = id v50_;
  v14_: int = id v14_;
  br v16_ .v15_ .v53_;
.v53_:
  v54_: bool = const true;
  v55_: int = add v11_ v12_;
  v56_: bool = id v54_;
  v57_: int = id v55_;
  v58_: int = id v12_;
  v59_: int = id v14_;
.v60_:
  v3_: int = id v57_;
  v4_: int = id v58_;
  v5_: int = id v59_;
  br v7_ .v6_ .v61_;
.v36_:
  br v24_ .v62_ .v63_;
.v62_:
  v64_: bool = const true;
  v65_: int = id v29_;
  v66_: bool = id v64_;
  v67_: int = id v21_;
  v68_: int = id v22_;
.v69_:
  v70_: bool = const true;
  v38_: int = id v65_;
  v39_: bool = id v70_;
  v40_: int = id v67_;
  v41_: int = id v22_;
  jmp .v42_;
.v63_:
  v71_: bool = const true;
  v65_: int = id v20_;
  v66_: bool = id v71_;
  v67_: int = id v29_;
  v68_: int = id v22_;
  jmp .v69_;
.v26_:
  v72_: int = sub v21_ v20_;
  v28_: int = id v20_;
  v29_: int = id v72_;
  v30_: int = id v21_;
  v31_: bool = id v24_;
  v32_: int = id v22_;
  jmp .v33_;
.v18_:
  v73_: bool = const false;
  v47_: int = id v11_;
  v48_: int = id v12_;
  v49_: bool = id v73_;
  v50_: int = id v13_;
  v51_: int = id v14_;
  jmp .v52_;
.v9_:
  v74_: bool = const false;
  v56_: bool = id v74_;
  v57_: int = id v3_;
  v58_: int = id v4_;
  v59_: int = id v5_;
  jmp .v60_;
.v61_:
}

@sampsyo
Copy link
Owner

sampsyo commented May 17, 2024

Mysterious! This program seems fine (in the sense that it passes brilck). It's not shocking that there are bugs in the bril-llvm translation… I think the next step here, FWIW, would be to try reducing the test case to see if we can distill the problem.

@sampsyo
Copy link
Owner

sampsyo commented May 17, 2024

I reduced it a bit with this interestingness test:

#!/bin/sh
set -e
bril2json < $1 | brilck
bril2json < $1 | <path>/bril-llvm/brilc 2>&1 | grep KeyError

And got here:

@f {
  b: bool = const true;
  x: int = const 0;
  br b .B .C;
  y: int = const 0;
.B:
  x: int = const 0;
  jmp .e;
  print y;
.C:
  print x;
.e:
}

The key clearly seems to be the multiple assignments to x, but the rest of the CFG is kinda load-bearing as well. Maybe this helps narrow the bug down somewhat!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants