Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang] Invalid 32bit pointer (-fms-extensions __ptr32 __uptr) on non-Windows platforms #62538

Closed
d-mozulyov opened this issue May 3, 2023 · 4 comments
Labels
ABI Application Binary Interface backend:X86

Comments

@d-mozulyov
Copy link

Problem

32-bit pointer does not work correctly on non-Windows platforms. See the Godbolt listing.

screen_small

Sample

int param_std(int* foo) {
    int temp = *foo;
    *foo = 1;
    return temp;
}

int param_ptr32(int* __ptr32 __uptr bar) {
    int temp = *bar;
    *bar = 2;
    return temp;
}

int emulate_ptr32(unsigned baz) {
    unsigned long long baz64 = baz;
    int* bazptr = (int*)baz64;
    int temp = *bazptr;
    *bazptr = 3;
    return temp;
}

struct Qux {
    int* __ptr32 __uptr value;
};

int struct_ptr32(Qux& qux) {
    int temp = *qux.value;
    *qux.value = 4;
    return temp;
}

Conclusions

The param_ptr32 disassembler must be equal to emulate_ptr32, like struct_ptr32, and different from param_std. Based on the Godbolt listing, the MSVC and Clang for Windows target (x86_64-windows-gnu) compilers do just that. But on non-Windows platforms, Clang may not do the important conversion from a 32-bit pointer to a 64-bit one. I have localized this behavior in two cases. First, if the pointer appears as a function argument (param_ptr32). Second, if it is a member of a small structure that is passed as an argument (change Qux& qux to Qux qux).

@EugeneZelenko
Copy link
Contributor

@d-mozulyov: Please elaborate.

@d-mozulyov
Copy link
Author

d-mozulyov commented Jul 22, 2023

@EugeneZelenko

It looks like a 32 bit pointer works on POSIX x64. The difference is in the ABI - on POSIX x64 the 32-bit pointer-argument is already unpacked.

https://godbolt.org/z/WvosqdW96

image

@d-mozulyov
Copy link
Author

@EugeneZelenko

But on ARM 64 still not working: #62536

@EugeneZelenko EugeneZelenko added backend:X86 ABI Application Binary Interface and removed new issue labels Jul 22, 2023
@llvmbot
Copy link
Member

llvmbot commented Jul 22, 2023

@llvm/issue-subscribers-backend-x86

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ABI Application Binary Interface backend:X86
Projects
None yet
Development

No branches or pull requests

3 participants