[MDEV-6802] Build fails with clang on amd64 Created: 2014-09-27  Updated: 2014-11-23  Resolved: 2014-09-30

Status: Closed
Project: MariaDB Server
Component/s: Storage Engine - Connect
Affects Version/s: 10.0.14
Fix Version/s: 10.0.15

Type: Bug Priority: Minor
Reporter: Bernard Spil Assignee: Olivier Bertrand
Resolution: Fixed Votes: 0
Labels: connect-engine
Environment:

FreeBSD bobthebuilder 10.0-RELEASE-p7 FreeBSD 10.0-RELEASE-p7 #0: Tue Jul 8 06:37:44 UTC 2014 root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC


Attachments: File patch-storage_connect_array.cpp     File patch-storage_connect_filamap.cpp     File patch-storage_connect_filamap.h    
Issue Links:
Duplicate
is duplicated by MDEV-7154 Errors building CONNECT from 10.1 on ... Closed

 Description   

When building MariaDB 10.0.14 using clang 3.3 on FreeBSD amd64, there's a compile error in storage/connect/filamap.h

107: virtual int GetNextPos(void)

{return (int)Fpos + Nrec;}

error: cast from pointer to smaller type 'int' loses information

int is a 32-bit type this will not fit a memory address of a 64-bit platform. This should probably be handled using a uintptr_t type which should be available on all platforms.



 Comments   
Comment by Bernard Spil [ 2014-09-27 ]

Patches that enable build on FreeBSD 10.0 clang 3.3

Comment by Bernard Spil [ 2014-09-27 ]

And a patch for
storage/connect/array.cpp:132:26: �error: cast from pointer to smaller type 'int' loses information�

Comment by Olivier Bertrand [ 2014-09-29 ]

This function was wrongly defined but fortunately never used. However, it was fixed (just in case...) as:

virtual int   GetNextPos(void) {return GetPos() + 1;}

Comment by Bernard Spil [ 2014-09-29 ]

Great!
I attached a patch for connect_array as well which is unrelated to the filamap compile issue I encountered. Would you want me to open another bug for this or can you check this as well?

Comment by Olivier Bertrand [ 2014-09-29 ]

Sorry, I closed this before reading your last comments. About your patches:

in filamap.h:
Your patches on InitDelete are incorrect. These are virtual functions that must have the same signature as the base class one.

in filamap.cpp:
If there is a problem when the function is still defined as InitDelete(PGLOBAL g, int fpos, int spos) I suggest the following patches:

   Fpos = Memory + (uintptr_t)fpos;
   Mempos = Memory + (uintptr_t)spos;

and the same casting in MPXFAM::InitDelete. This is not necessary with the MS or GCC compilers. Let me know whether it is with clang.

In array.cpp:
This patch is also incorrect and would make the program fail or even crash!
Indeed, the parmp->Value variable is a void pointer but to avoid having to allocate an integer and make it point on it I choosed to directly put the integer value in it. This is tricky and not really correct but was done to save memory allocation.
It works with MS and GCC that flag the casting (int)parmp->Value as a warning. With clang, the problem is to extract an integer from a pointer. Perhaps (int)(uintptr_t)parmp->Value would work? Let me know whether you have a solution for this. If not, I shall have to redesign the whole thing (perhaps using another stucture with a union in it)

Comment by Olivier Bertrand [ 2014-09-29 ]

Reopened until you tell me whether my last suggestions work with clang

Comment by Bernard Spil [ 2014-09-29 ]

Thanks for your guidance Olivier Please find revised patches attached, Mariadb-10.0.14 builds on FreeBSD 10.0 with these patches.

Comment by Olivier Bertrand [ 2014-09-30 ]

I applied the new patches successfully on Windows. However, on Linux the GCC compiling failed saying that uintptr_t was undeclared.
Therefore I added:

#include <stdint.h>         // for uintprt_h

into the Unix declare section.
Is this ok with clang on FreeBSD?

Comment by Bernard Spil [ 2014-09-30 ]

Hi Olivier,
This is OK without adding an include for stdint.h anywhere in the storage/connect/ code
Built, packaged and deployed the server without a problem using the attached patches (sorry for the DOS CRLF)

Comment by Olivier Bertrand [ 2014-09-30 ]

This should fix all compiler issues. However, to do it in a cleaner way, I did not exactly apply the above patches:

In the InitDelete functions I changed the cast from uintptr_t to ptrdiff_t, which seems more appropriate and does not require including stdint.h.

About the array making, I have added an union in the PARM structure:

typedef struct _parm {
  union {
    void *Value;
    int   Intval;
    }; // end union
  short Type, Domain;
  PPARM Next;
  } PARM;

This makes possible to suppress all the funny casting that were done when creating the structure (in TXTFAM::AddListValue) and retrieving the integer value from it (in MakeValueArray)

Generated at Thu Feb 08 07:14:41 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.