Skip to content

Conversation

@andmadri
Copy link

@andmadri andmadri commented Dec 8, 2025

When processing thunk functions and elementtypes with
inheritance, there were logic errors in the direct base checking
that could lead to incorrect function types being retained.

The issue occurred in the following case:

  1. Initial comparison: CurrentThisStructTy (ios_base) == NewThisTy (ios_base)
  • Both types are the same, so NewIsDirectBase is incorrectly set to true
  • ThunkFn type: void (%class._ZSt8ios_base*)
  • ThunkFnTy: (%class._ZSt8ios_base*)
  • Since types match, no update occurs
  1. Second comparison: CurrentThisStructTy != NewThisTy
  • ThunkFn then gets updated to void (%class._ZSt9basic_iosIcSt11char_traitsIcEE*)
  • This is correct behavior
  1. Third comparison: Same types again (ios_base == ios_base)
  • NewIsDirectBase is again set to true, which will then affect updating the ThunkFn
  • Current ThunkFn: void (%class._ZSt9basic_iosIcSt11char_traitsIcEE*)
    but the one we want to update to is void (%class._ZSt8ios_base*)
  • Because NewIsDirectBase is true, the update is skipped eventhough
    ThunkFn != ThunkFnTy. This leaves ThunkFn with the wrong type

@andmadri andmadri requested a review from yuri91 December 8, 2025 16:27
Copy link
Member

@yuri91 yuri91 left a comment

Choose a reason for hiding this comment

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

You found the right spot. But the fix needs some more work

// between the function signature and the elementtype attribute
llvm::Type* CurrentThisTy = nullptr;
if (auto* PtrTy = dyn_cast<llvm::PointerType>(ActualParamType)) {
CurrentThisTy = PtrTy->getPointerElementType();
Copy link
Member

Choose a reason for hiding this comment

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

getPointerElementType() is a deprecated function. We should not use it, and actually the main reason for the elementtype attribute is to avoid having to resort to getPointerElementType().
See if there is any other way to get the element type fom Clang here.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, I see I had issues with opaque pointers and added a check to prevent opaque pointers to try and call this function in my new chnages but just read your comment now so the version I pushed still has the getPointerElementType() in there. I'll try to find a way not to use it

@andmadri andmadri force-pushed the clang_fix_elemettype branch from ff91653 to 4240a25 Compare December 9, 2025 08:59
When processing thunk functions and elementtypes with
inheritance, there were logic errors in the direct base checking
that could lead to incorrect function types being retained.

The issue occurred in the following case:
1. Initial comparison: CurrentThisStructTy (ios_base) == NewThisTy (ios_base)
 - Both types are the same, so NewIsDirectBase is incorrectly set to true
 - ThunkFn type: void (%class._ZSt8ios_base*)
 - ThunkFnTy: (%class._ZSt8ios_base*)
 - Since types match, no update occurs

2. Second comparison: CurrentThisStructTy != NewThisTy
 - ThunkFn then gets updated to void (%class._ZSt9basic_iosIcSt11char_traitsIcEE*)
 - This is correct behavior

3. Third comparison: Same types again (ios_base == ios_base)
 - NewIsDirectBase is again set to true, which will then affect updating the ThunkFn
 - Current ThunkFn: void (%class._ZSt9basic_iosIcSt11char_traitsIcEE*)
   but the one we want to update to is void (%class._ZSt8ios_base*)
 - Because NewIsDirectBase is true, the update is skipped eventhough
   ThunkFn != ThunkFnTy. This leaves ThunkFn with the wrong type
@andmadri andmadri force-pushed the clang_fix_elemettype branch from 69b9718 to 55fb6ba Compare December 10, 2025 13:28
@andmadri andmadri requested a review from yuri91 December 10, 2025 14:36
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.

3 participants