snu-sf-class / swpp202401

Principles and Practices of Software Development Main Repository
14 stars 4 forks source link

[Project] Skeleton compiler fails #73

Open sbkim28 opened 1 month ago

sbkim28 commented 1 month ago

안녕하십니까, skeleton compiler가 다음의 ll 파일을 컴파일할 때 문제가 생기는 것 같아서 이를 제보하고자 합니다.

다음은 제가 임의로 제작한 ll 파일입니다.

@BitsSetTable256 = external global [256 x i32], align 16

define dso_local i32 @main() #0 {
entry:
  store i32 0, ptr @BitsSetTable256, align 16
  br label %for.end

for.body:                                          ; preds = %for.body
  %div = sdiv i32 0, 2
  %idxprom = sext i32 %div to i64
  call void @write(i64 noundef %idxprom)
  br label %for.body

for.end:                                           ; preds = %entry
  %call = call i64 (...) @read()
  %conv = trunc i64 %call to i32
  %idxprom3 = sext i32 %conv to i64
  %arrayidx4 = getelementptr inbounds [256 x i32], ptr @BitsSetTable256, i64 0, i64 %idxprom3
  %1 = load i32, ptr %arrayidx4, align 4
  %conv5 = sext i32 %1 to i64
  call void @write(i64 noundef %conv5)
  ret i32 0
}

해당 ll 파일을 skeleton compiler을 이용해서 compile을 하면 Segmentation fault가 발생합니다. 그런데, for.body block을 제거하면 컴파일이 정상적으로 됩니다.

해당 ll파일은 c 파일로부터는 직접적으로 만들어지지 않지만, 최적화 과정 중에 unreachable한 자기 자신으로 돌아가는 block이 생성되었을 때 문제가 됩니다. 이 문제를 확인해주셨으면 합니다.

감사합니다.

strikef commented 1 month ago

Unreachable block 내에서 register allocation을 시도하려다 문제가 생기는 것으로 보입니다. 버그가 맞으며, 수정 예정입니다.

strikef commented 1 month ago

5/14일자 백엔드 패치에서 수정되었습니다.