Skip to content

Conversation

badumbatish
Copy link
Contributor

No description provided.

@badumbatish
Copy link
Contributor Author

LLVM generated from default clang

define dso_local void @_Z9BI_setjmpPPv(ptr noundef initializes((0, 8), (16, 24)) %env) local_unnamed_addr #0 !dbg !10 {
entry:
    #dbg_value(ptr %env, !16, !DIExpression(), !17)
  %0 = tail call ptr @llvm.frameaddress.p0(i32 0), !dbg !18
  store ptr %0, ptr %env, align 8, !dbg !18
  %1 = tail call ptr @llvm.stacksave.p0(), !dbg !18
  %2 = getelementptr inbounds nuw i8, ptr %env, i64 16, !dbg !18
  store ptr %1, ptr %2, align 8, !dbg !18
  %3 = tail call i32 @llvm.eh.sjlj.setjmp(ptr nonnull %env), !dbg !18
  ret void, !dbg !19
}

LLVM generated from clangir clang

define dso_local void @_Z9BI_setjmpPPv(ptr initializes((0, 16)) %0) local_unnamed_addr #0 !dbg !4 {
  %2 = tail call ptr @llvm.frameaddress.p0(i32 0), !dbg !8
  store ptr %2, ptr %0, align 8, !dbg !8
  %3 = tail call ptr @llvm.stacksave.p0(), !dbg !8
  %4 = getelementptr i8, ptr %0, i64 8, !dbg !8
  store ptr %3, ptr %4, align 8, !dbg !8
  %5 = tail call i32 @llvm.eh.sjlj.setjmp(ptr nonnull %0), !dbg !8
  ret void, !dbg !9
}

I'm not sure how the ptr stride op can generate the inbounds nuw flag just like in the default clang

@badumbatish
Copy link
Contributor Author

I can try for the setjmp in "setjmp.h" once i got my hands on a x86 linux, i'm not sure quite how to cross compile for x86_64 through llvm-lit and with x86_64's sysroot from a MacOS?!

@tommymcm
Copy link
Collaborator

Closes #1807

@xlauko xlauko changed the title Add builtin_setjmp codegen support [CIR] Add builtin_setjmp codegen support Aug 20, 2025
Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your first contribution and welcome to CIR! Some comments inline.

@bcardosolopes
Copy link
Member

I'm not sure how the ptr stride op can generate the inbounds nuw flag just like in the default clang

You should add assert(!cir::MissingFeatures::emitCheckedInBoundsGEP()); to the appropriate CIRGen place so we know how to come fix this later.

@badumbatish
Copy link
Contributor Author

the OG behavior defers BI_setjmp codegen to the predefined lib function codegen, the equivalent in CIR/ is

  // If this is a predefined lib function (e.g. malloc), emit the call
  // using exactly the normal call path.
  if (BI.isPredefinedLibFunction(BuiltinID))
    return emitLibraryCall(*this, FD, E, CGM.getRawFunctionPointer(FD));

the latest commit replicates this behavior. I replicate the structure but didn't put up the actual implementation for MSVCRT.

Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the latest round of updates!

@bcardosolopes bcardosolopes merged commit ff4c1fd into llvm:main Aug 25, 2025
8 of 9 checks passed
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

Successfully merging this pull request may close these issues.

5 participants