Create named structs instead of anonymous
This commit is contained in:
parent
b185e2ecc6
commit
de95db7cc1
2
Makefile
2
Makefile
@ -10,7 +10,7 @@ clean:
|
||||
rm -f $(BIN) $(SRC:.reid=.o) $(SRC:.reid=.asm) $(SRC:.reid=.ll)
|
||||
|
||||
$(BIN): $(SRC:.reid=.o)
|
||||
$(LD) -O0 -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/crt1.o -lc $(LDFLAGS) $< -o$@
|
||||
$(LD) -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/crt1.o -lc $(LDFLAGS) $< -o$@
|
||||
|
||||
.SUFFIXES: .o .reid
|
||||
.reid.o:
|
||||
|
8
otus.c
Normal file
8
otus.c
Normal file
@ -0,0 +1,8 @@
|
||||
struct DivT {
|
||||
int quot;
|
||||
int rem;
|
||||
};
|
||||
|
||||
extern struct DivT div(int num, int denom);
|
||||
|
||||
int main() { return div(10, 5).quot; }
|
33
otus.ll
Normal file
33
otus.ll
Normal file
@ -0,0 +1,33 @@
|
||||
; ModuleID = 'otus.c'
|
||||
source_filename = "otus.c"
|
||||
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
|
||||
target triple = "x86_64-pc-linux-gnu"
|
||||
|
||||
%struct.DivT = type { i32, i32 }
|
||||
|
||||
; Function Attrs: noinline nounwind optnone sspstrong uwtable
|
||||
define dso_local i32 @main() #0 {
|
||||
%1 = alloca i32, align 4
|
||||
%2 = alloca %struct.DivT, align 4
|
||||
store i32 0, ptr %1, align 4
|
||||
%3 = call i64 @div(i32 noundef 10, i32 noundef 5)
|
||||
store i64 %3, ptr %2, align 4
|
||||
%4 = getelementptr inbounds %struct.DivT, ptr %2, i32 0, i32 0
|
||||
%5 = load i32, ptr %4, align 4
|
||||
ret i32 %5
|
||||
}
|
||||
|
||||
declare i64 @div(i32 noundef, i32 noundef) #1
|
||||
|
||||
attributes #0 = { noinline nounwind optnone sspstrong uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
|
||||
attributes #1 = { "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
|
||||
|
||||
!llvm.module.flags = !{!0, !1, !2, !3, !4}
|
||||
!llvm.ident = !{!5}
|
||||
|
||||
!0 = !{i32 1, !"wchar_size", i32 4}
|
||||
!1 = !{i32 8, !"PIC Level", i32 2}
|
||||
!2 = !{i32 7, !"PIE Level", i32 2}
|
||||
!3 = !{i32 7, !"uwtable", i32 2}
|
||||
!4 = !{i32 7, !"frame-pointer", i32 2}
|
||||
!5 = !{!"clang version 19.1.7"}
|
@ -563,8 +563,12 @@ impl TypeHolder {
|
||||
for ty in &named_struct.1 {
|
||||
elem_types.push(ty.as_llvm(context.context_ref, types));
|
||||
}
|
||||
let struct_ty = LLVMStructTypeInContext(
|
||||
let struct_ty = LLVMStructCreateNamed(
|
||||
context.context_ref,
|
||||
into_cstring(named_struct.0.clone()).as_ptr(),
|
||||
);
|
||||
LLVMStructSetBody(
|
||||
struct_ty,
|
||||
elem_types.as_mut_ptr(),
|
||||
elem_types.len() as u32,
|
||||
0,
|
||||
|
Loading…
Reference in New Issue
Block a user