diff --git a/src/Makefile b/src/Makefile index 9b8a92f55..752579fdb 100644 --- a/src/Makefile +++ b/src/Makefile @@ -131,9 +131,19 @@ endif include Makefile.d/util.mk ifdef PREFIX +ifdef USECLANG +CC:=$(PREFIX)-clang +CXX:=$(PREFIX)-clang++ +else CC:=$(PREFIX)-gcc CXX:=$(PREFIX)-g++ endif +endif + +ifdef USECLANG +CC=clang +CXX=clang++ +endif OBJDUMP_OPTS?=--wide --source --line-numbers @@ -236,7 +246,7 @@ endif # build with profiling information ifdef PROFILEMODE opts+=-pg -libs+=-pg +LDFLAGS+=-pg endif ifdef DEBUGMODE @@ -248,10 +258,10 @@ ifdef USELTO # compile with LTO ifdef MINGW opts+=-flto=auto -g -libs+=-flto=auto -g +LDFLAGS+=-flto=auto -g else opts+=-flto=auto -libs+=-flto=auto +LDFLAGS+=-flto=auto endif endif endif @@ -265,8 +275,10 @@ else opts+=-fsanitize=address libs+=-fsanitize=address endif -opts+=-fsanitize=address -libs+=-fsanitize=address +endif + +ifeq ($(CC),clang) + LDFLAGS+= -fuse-ld=lld endif # debug_opts also get passed to windres @@ -281,6 +293,7 @@ cxxopts:=$(opts) $(CXXFLAGS) opts+=$(CWFLAGS) # warning flags that shouldnt be passed to c++ compiler libs+=$(LDFLAGS) -lstdc++ -lpthread + asflags:=$(ASFLAGS) -x assembler-with-cpp cc=$(CC) diff --git a/src/Makefile.d/versions.mk b/src/Makefile.d/versions.mk index 8485b0b16..d34070bb9 100644 --- a/src/Makefile.d/versions.mk +++ b/src/Makefile.d/versions.mk @@ -144,6 +144,10 @@ ifdef GCC81 WFLAGS+=-Wno-error=multistatement-macros endif +ifeq ($(CC),clang) + WFLAGS+= -Wno-unknown-pragmas -Wno-cast-align +endif + ifdef NONX86 ifdef X86_64 # yeah that SEEMS contradictory opts+=-march=nocona diff --git a/src/hardware/hw_batching.c b/src/hardware/hw_batching.c index 3b5c5426e..28b568c54 100644 --- a/src/hardware/hw_batching.c +++ b/src/hardware/hw_batching.c @@ -99,7 +99,8 @@ void HWR_ProcessPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPt polygonArrayAllocSize *= 2; polygonArray = realloc(polygonArray, polygonArrayAllocSize * sizeof(PolygonArrayEntry)); // also need to redo the index array, dont need to copy it though - polygonArraySorted = realloc(polygonArraySorted, polygonArrayAllocSize * sizeof(PolygonArrayEntry*)); + free(polygonArraySorted); + polygonArraySorted = malloc(polygonArrayAllocSize * sizeof(PolygonArrayEntry *)); } while (unsortedVertexArraySize + (int)iNumPts > unsortedVertexArrayAllocSize) diff --git a/src/r_draw_column.cpp b/src/r_draw_column.cpp index dcc1a5b90..bae220e6d 100644 --- a/src/r_draw_column.cpp +++ b/src/r_draw_column.cpp @@ -57,7 +57,7 @@ static constexpr UINT8 R_GetColumnTranslucent(drawcolumndata_t* dc, UINT8 * rest } template -static constexpr UINT8 R_DrawColumnPixel(drawcolumndata_t* dc, UINT8 * restrict dest, UINT32 bit, const restrict UINT8 *source, const restrict UINT8 *colormap) +static constexpr UINT8 R_DrawColumnPixel(drawcolumndata_t* dc, UINT8 * restrict dest, UINT32 bit, const UINT8 * restrict source, const UINT8 * restrict colormap) { UINT8 col = source[bit]; @@ -217,7 +217,7 @@ static void R_DrawColumnTemplate(drawcolumndata_t *dc) { if (frac < 0) // adjust in case we underread - frac += FRACUNIT; + frac += fracstep; // texture has no height, so just go while (--count >= 0)