lyh552506 / miniC-compiler

for gpt5.0 group
MIT License
4 stars 2 forks source link

[front]generating wrong ir when dealing with '!' operator #6

Open RicoAfoat opened 6 months ago

RicoAfoat commented 6 months ago

Reproduce:

int main(){
    int a=1;
    int b=!a;
    if(!a){
        b=2;
    }
    return 0;
}
define i32 @main(){
.1:
  %.5 = alloca i32
  %.2 = alloca i32
  store i32 1, i32* %.2
  %.6 = load i32, i32* %.2
  %.8 = icmp eq i32 %.6, 0
  store i1 %.8, i32* %.5
  %.12 = load i32, i32* %.2
  %.13 = icmp eq i32 %.12, 0
  br i1 %.13, label %.10, label %.11
.10:
  store i32 2, i32* %.5
  br label %.11 
.11:
  ret i32 0 
}

Solution:

  1. Assertion fails when meet this situation
  2. Generate zext