-
Notifications
You must be signed in to change notification settings - Fork 142
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
XXX_ptr
vs XXX_t
#407
Comments
I agree that there is an inconsistency in the fact that some In some way using |
GCC complains at some points that Edit: I now think that |
By now, I seriously doubt that Edit: This is done by looking at GCC's output. I have not found another way. |
Before embarking on that I would try to investigate if there any real implications of the warning (performance, wrong code generation) or if it's just a false positive that we can suppress safely with compiler flags. |
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102810 If I understand this correctly: void fun(int a[]); // Nemas problemas
void fun(int * a); // Nemas problemas
void fun(int a[3]); // ? haven't encountered a problem with these
void fun(const int * a); // Nemas problemas
void fun(const int a[]); // Nemas problemas
void fun(const int a[3]); // Muchos problemos As for the last function, it assumes that the input is an array of 3 ints, and will therefore read 3 int (for optimization reasons I guess). That is why we see problems with With this in mind, I think the most reasonable thing is to take GMP's approach and simply introduce stuff like |
This is still mysterious to me. arf_t (for example) is defined as an array of arf_struct of length 1, so it should always be safe to read exactly sizeof(arf_struct) bytes. Same with the various context objects. |
Don't know if I've encountered problems with arf in this aspect (the thing I mentioned has to do with different definitions of a function in header vs function file). However, problems occur for at least mag where it reads 16 bytes instead of 8. This is expected since |
I'm still not seeing the problem. Yes, it reads 16 bytes. Why "instead of 8"? Why would it only be allowed to read 8 bytes? |
I'm not sure, but can it be because of this? #include <stdio.h>
int
main()
{
long int a[3] = {0, 1, 2};
printf("&a = %p\n", &a);
printf("a + 0 = %p\n", a + 0);
printf("a + 1 = %p\n", a + 1);
printf("a + 2 = %p\n", a + 2);
} Output:
And so the it reads the following bytes after the pointer? So if a |
Any thoughts into this? As mentioned, I can prepare a PR which shouldn't take too long with some |
I still don't understand what the issue is either. GMP have had _ptr and _srcptr types for a very long time, long before this was an issue with recent GCC (and probably for other reasons). I think I'd like to understand the issue properly before just doing a radical overhaul of everything in Flint on the assumption that it fixes the problem. If things are declared properly, there should be no overreading. I currently don't understand why that is happening. |
@albinahlback I don't understand what your example is supposed to show. You are not reading anything. You are merely printing the pointer values and these seem to be printed correctly to me. |
Yeah, my example is incorrect. I read somewhere that something similar is fixed in the current state of GCC, so let's wait until GCC 12 is released until we draw any conclusions. Should be released in about a month. |
The compiler warning of |
In some functions, for example
arf_mul_si
, there is use ofarf_ptr
instead ofarf_t
as well asarf_srcptr
instead ofconst arf_t
. I thinkarf_ptr
andarf_srcptr
"only should be used as a pointers". What I mean by that is that they either represent an array or a (temporary) pointer, where the pointer might change value. In the named function, it is clear that the pointers only point to onearf_struct
, in which case I thinkarf_t
should be used.Do you agree? In the case that you do not agree, I think that
arf_t
should be omitted from the definitions, and that onlyarf_[src]ptr
should be used in order to be consistent.The text was updated successfully, but these errors were encountered: