Bug when defers and $if were combined in a macro, which would cause miscompilation.

This commit is contained in:
Christoffer Lerno
2024-10-10 13:42:12 +02:00
parent 7a6544b17c
commit 967f14148f
4 changed files with 35 additions and 1 deletions

View File

@@ -1,3 +1,4 @@
// #target: macos-x64
int x @if(false) = 1;
int d @if(true) = 5;

View File

@@ -0,0 +1,32 @@
// #target: macos-x64
module test;
macro void @test(bool $skip = false)
{
$if $skip:
$else
int a;
int b;
defer
{
a = b;
}
$endif
}
fn int main() {
@test();
return 0;
}
/* #expect: test.ll
entry:
%a = alloca i32, align 4
%b = alloca i32, align 4
store i32 0, ptr %a, align 4
store i32 0, ptr %b, align 4
%0 = load i32, ptr %b, align 4
store i32 %0, ptr %a, align 4
ret i32 0
}