Author Topic: Compiling using Clang/LLVM  (Read 4200 times)

nalf

  • Posts: 26
  • Turrets: +1/-0
Compiling using Clang/LLVM
« on: August 22, 2012, 10:20:34 am »
  Hi,

I wonder, has anybody successfully tried to compile Tremulous server using Clang/LLVM? And if so, what modifications were necessary, and was there any noticeable speed improvement?

/dev/humancontroller

  • Posts: 1033
  • Turrets: +1002/-383
Re: Compiling using Clang/LLVM
« Reply #1 on: August 22, 2012, 07:33:05 pm »
essentials:
Code: [Select]
Index: src/qcommon/vm.c
===================================================================
--- src/qcommon/vm.c (revision 2264)
+++ src/qcommon/vm.c (working copy)
@@ -338,7 +338,7 @@
 ============
 */
 intptr_t QDECL VM_DllSyscall( intptr_t arg, ... ) {
-#if !id386
+#if !id386 || defined __clang__
   // rcg010206 - see commentary above
   intptr_t args[16];
   int i;
@@ -766,7 +766,7 @@
                             args[4],  args[5],  args[6], args[7],
                             args[8],  args[9]);
  } else {
-#if id386 || idsparc // i386/sparc calling convention doesn't need conversion
+#if ( id386 || idsparc ) && !defined __clang__ // calling convention doesn't need conversion in some cases
 #ifndef NO_VM_COMPILED
  if ( vm->compiled )
  r = VM_CallCompiled( vm, (int*)&callnum );
Index: src/qcommon/vm_x86.c
===================================================================
--- src/qcommon/vm_x86.c (revision 2264)
+++ src/qcommon/vm_x86.c (working copy)
@@ -92,7 +92,7 @@
 static void (*const asmCallPtr)(void) = AsmCall;
 
 
-static int callMask = 0;
+int callMask = 0;
 
 static int instruction, pass;
 static int lastConst = 0;

fixes for warnings:
Code: [Select]
Index: src/renderer/tr_bsp.c
===================================================================
--- src/renderer/tr_bsp.c (revision 2264)
+++ src/renderer/tr_bsp.c (working copy)
@@ -264,6 +264,8 @@
 //===============================================================================
 
 
+#define LL(x) x=LittleLong(x)
+
 /*
 ===============
 ShaderForShaderNum
@@ -273,7 +275,7 @@
  shader_t *shader;
  dshader_t *dsh;
 
- shaderNum = LittleLong( shaderNum );
+ LL( shaderNum );
  if ( shaderNum < 0 || shaderNum >= s_worldData.numShaders ) {
  ri.Error( ERR_DROP, "ShaderForShaderNum: bad num %i", shaderNum );
  }
Index: src/renderer/tr_scene.c
===================================================================
--- src/renderer/tr_scene.c (revision 2264)
+++ src/renderer/tr_scene.c (working copy)
@@ -220,7 +220,7 @@
  }
  return;
  }
- if ( ent->reType < 0 || ent->reType >= RT_MAX_REF_ENTITY_TYPE ) {
+ if ( (int)ent->reType < 0 || ent->reType >= RT_MAX_REF_ENTITY_TYPE ) {
  ri.Error( ERR_DROP, "RE_AddRefEntityToScene: bad reType %i", ent->reType );
  }
 
Index: src/qcommon/md5.c
===================================================================
--- src/qcommon/md5.c (revision 2264)
+++ src/qcommon/md5.c (working copy)
@@ -253,7 +253,7 @@
     
     if (digest!=NULL)
      memcpy(digest, ctx->buf, 16);
-    memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
+    memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */
 }
 
 
Index: src/qcommon/unzip.c
===================================================================
--- src/qcommon/unzip.c (revision 2264)
+++ src/qcommon/unzip.c (working copy)
@@ -1250,7 +1250,7 @@
         return UNZ_PARAMERROR;
 
 
-    if ((pfile_in_zip_read_info->read_buffer == NULL))
+    if (pfile_in_zip_read_info->read_buffer == NULL)
         return UNZ_END_OF_LIST_OF_FILE;
     if (len==0)
         return 0;
Index: src/qcommon/common.c
===================================================================
--- src/qcommon/common.c (revision 2264)
+++ src/qcommon/common.c (working copy)
@@ -2314,7 +2314,7 @@
 =================
 */
 static void Com_Crash_f( void ) {
- * ( int * ) 0 = 0x12345678;
+ * ( volatile int * ) 0 = 0x12345678;
 }
 
 /*
Index: src/cgame/cg_buildable.c
===================================================================
--- src/cgame/cg_buildable.c (revision 2264)
+++ src/cgame/cg_buildable.c (working copy)
@@ -122,7 +122,7 @@
     else
       frac = 1.0f;
   }
-  else if( time < 0 )
+  else
   {
     msec = cg.time + time;
     if( msec >= 0 && msec < CREEP_SCALEDOWN_TIME )
Index: src/cgame/cg_view.c
===================================================================
--- src/cgame/cg_view.c (revision 2264)
+++ src/cgame/cg_view.c (working copy)
@@ -932,9 +932,7 @@
       {
         f = ( cg.time - cg.zoomTime ) / (float)ZOOM_TIME;
 
-        if ( f > 1.0f )
-          fov_y = fov_y;
-        else
+        if ( f <= 1.0f )
           fov_y = zoomFov + f * ( fov_y - zoomFov );
 
         // BUTTON_ATTACK2 is held so zoom next time
Index: src/cgame/cg_servercmds.c
===================================================================
--- src/cgame/cg_servercmds.c (revision 2264)
+++ src/cgame/cg_servercmds.c (working copy)
@@ -1069,7 +1069,7 @@
     return;
 
   vChan = atoi( CG_Argv( 2 ) );
-  if( vChan < 0 || vChan >= VOICE_CHAN_NUM_CHANS )
+  if( (int)vChan < 0 || vChan >= VOICE_CHAN_NUM_CHANS )
     return;
 
   if( cg_teamChatsOnly.integer && vChan != VOICE_CHAN_TEAM )
works flawlessly with, for example, r2264 on FreeBSD.

ULTRA Random ViruS

  • Posts: 924
  • Turrets: +4/-101
    • ZdrytchX's reference website
Re: Compiling using Clang/LLVM
« Reply #2 on: August 23, 2012, 11:29:41 am »
/dev/hc: Why did you have to know everything?  >:(

vcxzet

  • Posts: 467
  • Turrets: +21/-13
Re: Compiling using Clang/LLVM
« Reply #3 on: August 23, 2012, 11:54:46 pm »
probably a little slower than gcc 4.7.x