From 93202a548895fb5222fb64338f3dd7efd3f76a7b Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Sun, 2 Aug 2009 03:38:57 +0000 Subject: [PATCH] - Removed -fno-strict-aliasing from the GCC flags for ZDoom and fixed the issues that caused its inclusion. Is an optimized GCC build any faster for being able to use strict aliasing rules? I dunno. It's still slower than a VC++ build. I did run into two cases where TAutoSegIterator caused intractable problems with breaking strict aliasing rules, so I removed the templating from it, and the caller is now responsible for casting the probe value from void *. - Removed #include "autosegs.h" from several files that did not need it (in particular, dobject.h when not compiling with VC++). SVN r1743 (trunk) --- docs/rh-log.txt | 14 +++++- src/CMakeLists.txt | 9 +++- src/autosegs.h | 55 ++++++------------------ src/autostart.cpp | 12 +++--- src/autozend.cpp | 12 +++--- src/compatibility.h | 3 +- src/dobject.h | 26 ++++++++--- src/dobjgc.cpp | 2 +- src/dobjtype.cpp | 8 ++-- src/doomtype.h | 31 ++++++++++++-- src/f_finale.cpp | 4 +- src/farchive.cpp | 27 +++++++----- src/g_level.h | 17 ++++++-- src/g_mapinfo.cpp | 9 ++-- src/g_shared/sbarinfo.h | 15 ++++--- src/g_shared/sbarinfo_display.cpp | 9 +--- src/g_shared/sbarinfo_parser.cpp | 12 +++--- src/m_menu.cpp | 6 +++ src/m_options.cpp | 5 ++- src/mus2midi.cpp | 5 ++- src/r_defs.h | 6 ++- src/r_things.cpp | 14 +++--- src/resourcefiles/resourcefile.h | 8 +++- src/textures/textures.h | 6 ++- src/thingdef/thingdef.h | 9 ++-- src/thingdef/thingdef_data.cpp | 22 +++++----- src/thingdef/thingdef_expression.cpp | 1 - src/thingdef/thingdef_parse.cpp | 5 +-- src/thingdef/thingdef_properties.cpp | 1 - src/thingdef/thingdef_states.cpp | 1 - src/w_wad.cpp | 37 ++++++++++------ src/win32/i_crash.cpp | 10 +++-- src/win32/i_dijoy.cpp | 2 +- src/x86.cpp | 20 ++++----- src/x86.h | 64 +++++++++++++++++++--------- 35 files changed, 298 insertions(+), 189 deletions(-) diff --git a/docs/rh-log.txt b/docs/rh-log.txt index c4e79f2667..ab6dfb600a 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,4 +1,16 @@ -July 31, 2009 +August 1, 2009 +- Removed -fno-strict-aliasing from the GCC flags for ZDoom and fixed the + issues that caused its inclusion. Is an optimized GCC build any faster + for being able to use strict aliasing rules? I dunno. It's still slower + than a VC++ build. + + I did run into two cases where TAutoSegIterator caused intractable problems + with breaking strict aliasing rules, so I removed the templating from it, + and the caller is now responsible for casting the probe value from void *. + +July 31, 2009 +- Removed #include "autosegs.h" from several files that did not need it + (in particular, dobject.h when not compiling with VC++). - gdtoa now performs all type aliasing through unions. -Wall has been added to the GCC flags for the library to help verify this. - Changed A_SpawnFly to do nothing if reactiontime is 0. Reactiontime was diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4da428030c..d3f67baaa3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -324,7 +324,14 @@ if( CMAKE_COMPILER_IS_GNUCXX ) set( CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} ${REL_CXX_FLAGS}" ) set( CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${REL_CXX_FLAGS}" ) - set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-unused -fno-strict-aliasing" ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-unused" ) + + # Remove extra warnings when using the official DirectX headers. + # Also, TDM-GCC 4.4.0 no longer accepts glibc-style printf formats as valid, + # which is a royal pain. The previous version I had been using was fine with them. + if( WIN32 ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas -Wno-comment -Wno-format" ) + endif( WIN32 ) if( NOT NO_STRIP ) set (CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -s" ) diff --git a/src/autosegs.h b/src/autosegs.h index a58b6d14d1..fb3c0d3ee5 100644 --- a/src/autosegs.h +++ b/src/autosegs.h @@ -35,22 +35,6 @@ #ifndef AUTOSEGS_H #define AUTOSEGS_H -#ifdef __GNUC__ -#ifdef __MACH__ -#define AREG_SECTION "__DATA,areg" -#define CREG_SECTION "__DATA,creg" -#define GREG_SECTION "__DATA,greg" -#define MREG_SECTION "__DATA,mreg" -#define YREG_SECTION "__DATA,yreg" -#else -#define AREG_SECTION "areg" -#define CREG_SECTION "creg" -#define GREG_SECTION "greg" -#define MREG_SECTION "mreg" -#define YREG_SECTION "yreg" -#endif -#endif - #define REGMARKER(x) (x) typedef void *REGINFO; @@ -74,56 +58,45 @@ extern REGINFO MRegTail; extern REGINFO YRegHead; extern REGINFO YRegTail; -template -class TAutoSegIteratorNoArrow +class FAutoSegIterator { public: - TAutoSegIteratorNoArrow () + FAutoSegIterator(REGINFO &head, REGINFO &tail) { // Weirdness. Mingw's linker puts these together backwards. - if (_head < _tail) + if (&head <= &tail) { - Head = _head; - Tail = _tail; + Head = &head; + Tail = &tail; } else { - Head = _tail; - Tail = _head; + Head = &tail; + Tail = &head; } - Probe = (T *)REGMARKER(Head); + Probe = Head; } - operator T () const + REGINFO operator*() const { return *Probe; } - TAutoSegIteratorNoArrow &operator++() + FAutoSegIterator &operator++() { do { ++Probe; - } while (*Probe == 0 && Probe < (T *)REGMARKER(Tail)); + } while (*Probe == 0 && Probe < Tail); return *this; } - void Reset () + void Reset() { - Probe = (T *)REGMARKER(Head); + Probe = Head; } protected: - T *Probe; + REGINFO *Probe; REGINFO *Head; REGINFO *Tail; }; -template -class TAutoSegIterator : public TAutoSegIteratorNoArrow -{ - public: - T operator->() const - { - return *(this->Probe); - } -}; - #endif diff --git a/src/autostart.cpp b/src/autostart.cpp index e8e940c5d1..6ed85ae157 100644 --- a/src/autostart.cpp +++ b/src/autostart.cpp @@ -86,11 +86,13 @@ void *YRegHead = 0; #elif defined(__GNUC__) -void *ARegHead __attribute__((section(AREG_SECTION))) = 0; -void *CRegHead __attribute__((section(CREG_SECTION))) = 0; -void *GRegHead __attribute__((section(GREG_SECTION))) = 0; -void *MRegHead __attribute__((section(MREG_SECTION))) = 0; -void *YRegHead __attribute__((section(YREG_SECTION))) = 0; +#include "doomtype.h" + +void *ARegHead __attribute__((section(SECTION_AREG))) = 0; +void *CRegHead __attribute__((section(SECTION_CREG))) = 0; +void *GRegHead __attribute__((section(SECTION_GREG))) = 0; +void *MRegHead __attribute__((section(SECTION_MREG))) = 0; +void *YRegHead __attribute__((section(SECTION_YREG))) = 0; #else diff --git a/src/autozend.cpp b/src/autozend.cpp index 58564bca89..023f8c733c 100644 --- a/src/autozend.cpp +++ b/src/autozend.cpp @@ -58,11 +58,13 @@ void *YRegTail = 0; #elif defined(__GNUC__) -void *ARegTail __attribute__((section(AREG_SECTION))) = 0; -void *CRegTail __attribute__((section(CREG_SECTION))) = 0; -void *GRegTail __attribute__((section(GREG_SECTION))) = 0; -void *MRegTail __attribute__((section(MREG_SECTION))) = 0; -void *YRegTail __attribute__((section(YREG_SECTION))) = 0; +#include "doomtype.h" + +void *ARegTail __attribute__((section(SECTION_AREG))) = 0; +void *CRegTail __attribute__((section(SECTION_CREG))) = 0; +void *GRegTail __attribute__((section(SECTION_GREG))) = 0; +void *MRegTail __attribute__((section(SECTION_MREG))) = 0; +void *YRegTail __attribute__((section(SECTION_YREG))) = 0; #else diff --git a/src/compatibility.h b/src/compatibility.h index 1b5cfa0cb2..f80314cbd7 100644 --- a/src/compatibility.h +++ b/src/compatibility.h @@ -9,6 +9,7 @@ union FMD5Holder { BYTE Bytes[16]; DWORD DWords[4]; + hash_t Hash; }; struct FCompatValues @@ -21,7 +22,7 @@ struct FMD5HashTraits { hash_t Hash(const FMD5Holder key) { - return *(hash_t *)key.Bytes; + return key.Hash; } int Compare(const FMD5Holder left, const FMD5Holder right) { diff --git a/src/dobject.h b/src/dobject.h index 62c5ee3ba5..e853b7ec0b 100644 --- a/src/dobject.h +++ b/src/dobject.h @@ -36,9 +36,6 @@ #include #include "doomtype.h" -#ifndef _MSC_VER -#include "autosegs.h" -#endif struct PClass; @@ -146,7 +143,7 @@ struct ClassReg const size_t *Pointers; void (*ConstructNative)(void *); - void RegisterClass(); + void RegisterClass() const; }; enum EInPlace { EC_InPlace }; @@ -177,7 +174,7 @@ private: \ # pragma data_seg() # define _DECLARE_TI(cls) __declspec(allocate(".creg$u")) ClassReg *cls::RegistrationInfoPtr = &cls::RegistrationInfo; #else -# define _DECLARE_TI(cls) ClassReg *cls::RegistrationInfoPtr __attribute__((section(CREG_SECTION))) = &cls::RegistrationInfo; +# define _DECLARE_TI(cls) ClassReg *cls::RegistrationInfoPtr __attribute__((section(SECTION_CREG))) = &cls::RegistrationInfo; #endif #define _IMP_PCLASS(cls,ptrs,create) \ @@ -323,7 +320,17 @@ namespace GC // Unroots an object. void DelSoftRoot(DObject *obj); - template void Mark(T *&obj) { Mark((DObject **)&obj); } + template void Mark(T *&obj) + { + union + { + T *t; + DObject *o; + }; + o = obj; + Mark(&o); + obj = t; + } template void Mark(TObjPtr &obj); } @@ -334,6 +341,7 @@ template class TObjPtr { T *p; + DObject *o; // For GC::Mark below to make GCC's strict aliasing happy public: TObjPtr() throw() { @@ -398,6 +406,7 @@ public: } template friend inline FArchive &operator<<(FArchive &arc, TObjPtr &o); + template friend inline void GC::Mark(TObjPtr &obj); friend class DObject; }; @@ -413,7 +422,10 @@ template inline T barrier_cast(TObjPtr &o) return static_cast(static_cast(o)); } -template void GC::Mark(TObjPtr &obj) { GC::Mark((DObject **)&obj); } +template inline void GC::Mark(TObjPtr &obj) +{ + GC::Mark(&obj.o); +} class DObject { diff --git a/src/dobjgc.cpp b/src/dobjgc.cpp index b17fcc2aad..1c8e618bdd 100644 --- a/src/dobjgc.cpp +++ b/src/dobjgc.cpp @@ -270,7 +270,7 @@ void Mark(DObject **obj) { if (lobj->ObjectFlags & OF_EuthanizeMe) { - *obj = NULL; + *obj = (DObject *)NULL; } else if (lobj->IsWhite()) { diff --git a/src/dobjtype.cpp b/src/dobjtype.cpp index 5030cc70d4..03eecc7a95 100644 --- a/src/dobjtype.cpp +++ b/src/dobjtype.cpp @@ -71,11 +71,11 @@ void PClass::StaticInit () } qsort (head + 1, tail - head - 1, sizeof(REGINFO), cregcmp); - TAutoSegIterator probe; + FAutoSegIterator probe(CRegHead, CRegTail); - while (++probe != NULL) + while (*++probe != NULL) { - probe->RegisterClass (); + ((ClassReg *)*probe)->RegisterClass (); } } @@ -153,7 +153,7 @@ void PClass::StaticFreeData (PClass *type) } } -void ClassReg::RegisterClass () +void ClassReg::RegisterClass () const { assert (MyClass != NULL); diff --git a/src/doomtype.h b/src/doomtype.h index 72feddbc79..6d8ed80113 100644 --- a/src/doomtype.h +++ b/src/doomtype.h @@ -155,9 +155,9 @@ enum struct PalEntry { PalEntry () {} - PalEntry (DWORD argb) { *(DWORD *)this = argb; } - operator DWORD () const { return *(DWORD *)this; } - PalEntry &operator= (DWORD other) { *(DWORD *)this = other; return *this; } + PalEntry (DWORD argb) { d = argb; } + operator DWORD () const { return d; } + PalEntry &operator= (DWORD other) { d = other; return *this; } PalEntry InverseColor() const { PalEntry nc; nc.a = a; nc.r = 255 - r; nc.g = 255 - g; nc.b = 255 - b; return nc; } #ifdef WORDS_BIGENDIAN PalEntry (BYTE ir, BYTE ig, BYTE ib) : a(0), r(ir), g(ig), b(ib) {} @@ -166,7 +166,14 @@ struct PalEntry #else PalEntry (BYTE ir, BYTE ig, BYTE ib) : b(ib), g(ig), r(ir), a(0) {} PalEntry (BYTE ia, BYTE ir, BYTE ig, BYTE ib) : b(ib), g(ig), r(ir), a(ia) {} - BYTE b,g,r,a; + union + { + struct + { + BYTE b,g,r,a; + }; + DWORD d; + }; #endif }; @@ -187,4 +194,20 @@ char ( &_ArraySizeHelper( T (&array)[N] ))[N]; #define countof( array ) (sizeof( _ArraySizeHelper( array ) )) +// Auto-registration sections for GCC. +// Apparently, you cannot do string concatenation inside section attributes. +#ifdef __MACH__ +#define SECTION_AREG "__DATA,areg" +#define SECTION_CREG "__DATA,creg" +#define SECTION_GREG "__DATA,greg" +#define SECTION_MREG "__DATA,mreg" +#define SECTION_YREG "__DATA,yreg" +#else +#define SECTION_AREG "areg" +#define SECTION_CREG "creg" +#define SECTION_GREG "greg" +#define SECTION_MREG "mreg" +#define SECTION_YREG "yreg" +#endif + #endif diff --git a/src/f_finale.cpp b/src/f_finale.cpp index 5e1fa04cd6..b295aefbf5 100644 --- a/src/f_finale.cpp +++ b/src/f_finale.cpp @@ -150,7 +150,7 @@ void F_StartFinale (const char *music, int musicorder, int cdtrack, unsigned int if (ending) { - FinaleSequence = *((WORD *)&level.nextmap[6]); + FinaleSequence = level.EndSequence; if (EndSequences[FinaleSequence].EndType == END_Chess) { TEXTSPEED = 3; // Slow the text to its original rate to match the music. @@ -244,7 +244,7 @@ void F_Ticker () // [RH] Don't automatically advance end-of-game messages if (interrupt) { - FinaleSequence = *((WORD *)&level.nextmap[6]); + FinaleSequence = level.EndSequence; if (EndSequences[FinaleSequence].EndType == END_Cast) { F_StartCast (); diff --git a/src/farchive.cpp b/src/farchive.cpp index b077583233..9a4692cf27 100644 --- a/src/farchive.cpp +++ b/src/farchive.cpp @@ -92,8 +92,10 @@ static inline DWORD SWAP_DWORD(DWORD x) { return _byteswap_ulong(x); } static inline QWORD SWAP_QWORD(QWORD x) { return _byteswap_uint64(x); } static inline void SWAP_DOUBLE(double &dst, double &src) { - union twiddle { QWORD q; double d; } *tdst = (twiddle *)&dst, *tsrc = (twiddle *)&src; - tdst->q = _byteswap_uint64(tsrc->q); + union twiddle { QWORD q; double d; } tdst, tsrc; + tsrc.d = src; + tdst.q = _byteswap_uint64(tsrc.q); + dst = tdst.d; } #else static inline WORD SWAP_WORD(WORD x) { return (((x)<<8) | ((x)>>8)); } @@ -108,17 +110,22 @@ static inline QWORD SWAP_QWORD(QWORD x) } static inline void SWAP_DOUBLE(double &dst, double &src) { - union twiddle { double f; DWORD d[2]; } *tdst = (twiddle *)&dst, *tsrc = (twiddle *)&src; + union twiddle { double f; DWORD d[2]; } tdst, tsrc; DWORD t; - t = tsrc->d[0]; - tdst->d[0] = SWAP_DWORD(tsrc->d[1]); - tdst->d[1] = SWAP_DWORD(t); + + tsrc.f = src; + t = tsrc.d[0]; + tdst.d[0] = SWAP_DWORD(tsrc.d[1]); + tdst.d[1] = SWAP_DWORD(t); + dst = tdst.f; } #endif static inline void SWAP_FLOAT(float &x) { - union twiddle { DWORD i; float f; } *t = (twiddle *)&x; - t->i = SWAP_DWORD(t->i); + union twiddle { DWORD i; float f; } t; + t.f = x; + t.i = SWAP_DWORD(t.i); + x = t.f; } #endif @@ -1278,11 +1285,11 @@ int FArchive::ReadSprite () Read (&name, 4); hint = ReadCount (); - if (hint >= NumStdSprites || *(DWORD *)&sprites[hint].name != name) + if (hint >= NumStdSprites || sprites[hint].dwName != name) { for (hint = NumStdSprites; hint-- != 0; ) { - if (*(DWORD *)&sprites[hint].name == name) + if (sprites[hint].dwName == name) { break; } diff --git a/src/g_level.h b/src/g_level.h index 01d3e91e43..cc4b5e9b11 100644 --- a/src/g_level.h +++ b/src/g_level.h @@ -36,7 +36,7 @@ #include "doomtype.h" #include "doomdef.h" -#include "autosegs.h" +//#include "autosegs.h" #include "sc_man.h" struct level_info_t; @@ -51,7 +51,7 @@ class FScanner; #define GCC_YSEG #else #define MSVC_YSEG -#define GCC_YSEG __attribute__((section(YREG_SECTION))) +#define GCC_YSEG __attribute__((section(SECTION_YREG))) #endif @@ -355,7 +355,18 @@ struct FLevelLocals int levelnum; int lumpnum; FString LevelName; - char mapname[256]; // the server name (base1, etc) + union + { + char mapname[256]; // the server name (base1, etc) + // The endsequence is embedded in the name so that it can be + // carried around as a name. The first 6 character ought to + // match the string "enDSeQ". + struct + { + char pad[6]; + WORD EndSequence; + }; + }; char nextmap[9]; // go here when fraglimit is hit char secretmap[9]; // map to go to when used secret exit diff --git a/src/g_mapinfo.cpp b/src/g_mapinfo.cpp index 736c568cd5..bb68e7d726 100644 --- a/src/g_mapinfo.cpp +++ b/src/g_mapinfo.cpp @@ -50,6 +50,7 @@ #include "p_acs.h" #include "doomstat.h" #include "d_player.h" +#include "autosegs.h" int FindEndSequence (int type, const char *picname); @@ -1434,14 +1435,14 @@ void FMapInfoParser::ParseMapDefinition(level_info_t &info) } else { - TAutoSegIterator probe; + FAutoSegIterator probe(YRegHead, YRegTail); bool success = false; - while (++probe != NULL) + while (*++probe != NULL) { - if (sc.Compare(probe->name)) + if (sc.Compare(((FMapOptInfo *)(*probe))->name)) { - probe->handler(*this, &info); + ((FMapOptInfo *)(*probe))->handler(*this, &info); success = true; break; } diff --git a/src/g_shared/sbarinfo.h b/src/g_shared/sbarinfo.h index 91afb8f8a3..1d4a4ec40d 100644 --- a/src/g_shared/sbarinfo.h +++ b/src/g_shared/sbarinfo.h @@ -55,9 +55,6 @@ class FScanner; class SBarInfoCoordinate { public: - SBarInfoCoordinate() {} - SBarInfoCoordinate(int coord, bool relCenter); - SBarInfoCoordinate &Add(int add); int Coordinate() const { return value; } bool RelCenter() const { return relCenter; } @@ -132,8 +129,16 @@ struct SBarInfoCommand int type; int special; - int special2; - int special3; + union + { + int special2; + SBarInfoCoordinate sbcoord2; + }; + union + { + int special3; + SBarInfoCoordinate sbcoord3; + }; int special4; int flags; SBarInfoCoordinate x; diff --git a/src/g_shared/sbarinfo_display.cpp b/src/g_shared/sbarinfo_display.cpp index 2e816baacf..d2d7ec8172 100644 --- a/src/g_shared/sbarinfo_display.cpp +++ b/src/g_shared/sbarinfo_display.cpp @@ -91,11 +91,6 @@ enum //////////////////////////////////////////////////////////////////////////////// -SBarInfoCoordinate::SBarInfoCoordinate(int coord, bool relCenter) : - relCenter(relCenter), value(coord) -{ -} - SBarInfoCoordinate &SBarInfoCoordinate::Add(int add) { value += add; @@ -756,7 +751,7 @@ void DSBarInfo::doCommands(SBarInfoBlock &block, int xOffset, int yOffset, int a { drawingFont = cmd.font; } - DrawNumber(CPlayer->mo->InvSel->Amount, 3, *(SBarInfoCoordinate*)&cmd.special2, *(SBarInfoCoordinate*)&cmd.special3, xOffset, yOffset, alpha, block.fullScreenOffsets, cmd.translation, cmd.special4, false, !!(cmd.flags & DRAWSELECTEDINVENTORY_DRAWSHADOW)); + DrawNumber(CPlayer->mo->InvSel->Amount, 3, cmd.sbcoord2, cmd.sbcoord3, xOffset, yOffset, alpha, block.fullScreenOffsets, cmd.translation, cmd.special4, false, !!(cmd.flags & DRAWSELECTEDINVENTORY_DRAWSHADOW)); } } else if((cmd.flags & DRAWSELECTEDINVENTORY_ALTERNATEONEMPTY)) @@ -785,7 +780,7 @@ void DSBarInfo::doCommands(SBarInfoBlock &block, int xOffset, int yOffset, int a { drawingFont = cmd.font; } - DrawInventoryBar(cmd.special, cmd.value, cmd.x, cmd.y, xOffset, yOffset, alpha, block.fullScreenOffsets, alwaysshow, *(SBarInfoCoordinate*)&cmd.special2, *(SBarInfoCoordinate*)&cmd.special3, cmd.translation, artibox, noarrows, alwaysshowcounter, bgalpha); + DrawInventoryBar(cmd.special, cmd.value, cmd.x, cmd.y, xOffset, yOffset, alpha, block.fullScreenOffsets, alwaysshow, cmd.sbcoord2, cmd.sbcoord3, cmd.translation, artibox, noarrows, alwaysshowcounter, bgalpha); break; } case SBARINFO_DRAWBAR: diff --git a/src/g_shared/sbarinfo_parser.cpp b/src/g_shared/sbarinfo_parser.cpp index d0b4551419..0ad46df339 100644 --- a/src/g_shared/sbarinfo_parser.cpp +++ b/src/g_shared/sbarinfo_parser.cpp @@ -765,12 +765,12 @@ void SBarInfo::ParseSBarInfoBlock(FScanner &sc, SBarInfoBlock &block) sc.MustGetToken(','); } this->getCoordinates(sc, block.fullScreenOffsets, cmd.x, cmd.y); - *(SBarInfoCoordinate*)&cmd.special2 = cmd.x + 30; - *(SBarInfoCoordinate*)&cmd.special3 = cmd.y + 24; + cmd.sbcoord2 = cmd.x + 30; + cmd.sbcoord3 = cmd.y + 24; cmd.translation = CR_GOLD; if(sc.CheckToken(',')) //more font information { - this->getCoordinates(sc, block.fullScreenOffsets, *(SBarInfoCoordinate*)&cmd.special2, *(SBarInfoCoordinate*)&cmd.special3); + this->getCoordinates(sc, block.fullScreenOffsets, cmd.sbcoord2, cmd.sbcoord3); if(sc.CheckToken(',')) { sc.MustGetToken(TK_Identifier); @@ -847,12 +847,12 @@ void SBarInfo::ParseSBarInfoBlock(FScanner &sc, SBarInfoBlock &block) sc.MustGetToken(','); this->getCoordinates(sc, block.fullScreenOffsets, cmd.x, cmd.y); - *(SBarInfoCoordinate*)&cmd.special2 = cmd.x + 26; - *(SBarInfoCoordinate*)&cmd.special3 = cmd.y + 22; + cmd.sbcoord2 = cmd.x + 26; + cmd.sbcoord3 = cmd.y + 22; cmd.translation = CR_GOLD; if(sc.CheckToken(',')) //more font information { - this->getCoordinates(sc, block.fullScreenOffsets, *(SBarInfoCoordinate*)&cmd.special2, *(SBarInfoCoordinate*)&cmd.special3); + this->getCoordinates(sc, block.fullScreenOffsets, cmd.sbcoord2, cmd.sbcoord3); if(sc.CheckToken(',')) { sc.MustGetToken(TK_Identifier); diff --git a/src/m_menu.cpp b/src/m_menu.cpp index a3447e2668..054885a4ab 100644 --- a/src/m_menu.cpp +++ b/src/m_menu.cpp @@ -3152,6 +3152,9 @@ void M_ButtonHandler(EMenuKey key, bool repeat) PlayerRotation ^= 8; } break; + + default: + break; // Keep GCC quiet } } @@ -3204,6 +3207,9 @@ static void M_SaveLoadButtonHandler(EMenuKey key) M_SaveSelect (SelSaveGame); } break; + + default: + break; // Keep GCC quiet } } diff --git a/src/m_options.cpp b/src/m_options.cpp index 58c37e70e6..543c10599e 100644 --- a/src/m_options.cpp +++ b/src/m_options.cpp @@ -2169,6 +2169,9 @@ void M_OptButtonHandler(EMenuKey key, bool repeat) switch (key) { + default: + break; // Keep GCC quiet + case MKEY_Down: if (CurrentMenu->numitems > 1) { @@ -3289,7 +3292,7 @@ void UpdateJoystickMenu(IJoystickConfig *selected) break; } } - if (i == Joysticks.Size()) + if (i == (int)Joysticks.Size()) { SELECTED_JOYSTICK = NULL; if (CurrentMenu == &JoystickConfigMenu) diff --git a/src/mus2midi.cpp b/src/mus2midi.cpp index 1e6573565c..9dafcaabf1 100644 --- a/src/mus2midi.cpp +++ b/src/mus2midi.cpp @@ -41,6 +41,7 @@ #include "m_swap.h" #include "mus2midi.h" +#include "doomdef.h" static const BYTE StaticMIDIhead[] = { 'M','T','h','d', 0, 0, 0, 6, @@ -52,7 +53,7 @@ static const BYTE StaticMIDIhead[] = 0, 255, 81, 3, 0x07, 0xa1, 0x20 }; -static const BYTE MUSMagic[4] = { 'M','U','S',0x1a }; +static const DWORD MUSMagic = MAKE_ID('M','U','S',0x1a); static const BYTE CtrlTranslate[15] = { @@ -122,7 +123,7 @@ bool ProduceMIDI (const BYTE *musBuf, TArray &outFile) long trackLen; // Do some validation of the MUS file - if (*(DWORD *)MUSMagic != musHead->Magic) + if (MUSMagic != musHead->Magic) return false; if (LittleShort(musHead->NumChans) > 15) diff --git a/src/r_defs.h b/src/r_defs.h index 4e4433ca39..5679e463f1 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -1070,7 +1070,11 @@ struct spriteframe_t // struct spritedef_t { - char name[5]; + union + { + char name[5]; + DWORD dwName; + }; BYTE numframes; WORD spriteframes; }; diff --git a/src/r_things.cpp b/src/r_things.cpp index 1acea38789..ffc9ed3dd7 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -345,9 +345,9 @@ void R_InitSpriteDefs () for (i = 0; i < max; ++i) { FTexture *tex = TexMan.ByIndex(i); - if (tex->UseType == FTexture::TEX_Sprite && strlen (tex->Name) >= 6) + if (tex->UseType == FTexture::TEX_Sprite && strlen(tex->Name) >= 6) { - DWORD bucket = *(DWORD *)tex->Name % max; + DWORD bucket = tex->dwName % max; hashes[i].Next = hashes[bucket].Head; hashes[bucket].Head = i; } @@ -363,14 +363,14 @@ void R_InitSpriteDefs () } maxframe = -1; - intname = *(DWORD *)sprites[i].name; + intname = sprites[i].dwName; // scan the lumps, filling in the frames for whatever is found int hash = hashes[intname % max].Head; while (hash != -1) { FTexture *tex = TexMan[hash]; - if (*(DWORD *)tex->Name == intname) + if (tex->dwName == intname) { R_InstallSpriteLump (FTextureID(hash), tex->Name[4] - 'A', tex->Name[5], false); @@ -673,7 +673,7 @@ void R_InitSkins (void) { char name[9]; Wads.GetLumpName (name, base+1); - intname = *(DWORD *)name; + memcpy(&intname, name, 4); } int basens = Wads.GetLumpNamespace(base); @@ -703,8 +703,10 @@ void R_InitSkins (void) for (k = base + 1; Wads.GetLumpNamespace(k) == basens; k++) { char lname[9]; + DWORD lnameint; Wads.GetLumpName (lname, k); - if (*(DWORD *)lname == intname) + memcpy(&lnameint, lname, 4); + if (lnameint == intname) { FTextureID picnum = TexMan.CreateTexture(k, FTexture::TEX_SkinSprite); R_InstallSpriteLump (picnum, lname[4] - 'A', lname[5], false); diff --git a/src/resourcefiles/resourcefile.h b/src/resourcefiles/resourcefile.h index bc07426e9f..39c9594f81 100644 --- a/src/resourcefiles/resourcefile.h +++ b/src/resourcefiles/resourcefile.h @@ -13,7 +13,13 @@ struct FResourceLump int LumpSize; char * FullName; // only valid for files loaded from a .zip file - char Name[9]; + union + { + char Name[9]; + + DWORD dwName; // These are for accessing the first 4 or 8 chars of + QWORD qwName; // Name as a unit without breaking strict aliasing rules + }; BYTE Flags; SBYTE RefCount; char * Cache; diff --git a/src/textures/textures.h b/src/textures/textures.h index 664970036d..06d373f1f7 100644 --- a/src/textures/textures.h +++ b/src/textures/textures.h @@ -101,7 +101,11 @@ public: int SourceLump; - char Name[9]; + union + { + char Name[9]; + DWORD dwName; // Used with sprites + }; BYTE UseType; // This texture's primary purpose BYTE bNoDecals:1; // Decals should not stick to texture diff --git a/src/thingdef/thingdef.h b/src/thingdef/thingdef.h index dfcf3f293f..1d95bc92d0 100644 --- a/src/thingdef/thingdef.h +++ b/src/thingdef/thingdef.h @@ -175,8 +175,7 @@ struct AFuncDesc actionf_p Function; }; -AFuncDesc * FindFunction(const char * string); - +AFuncDesc *FindFunction(const char * string); void ParseStates(FScanner &sc, FActorInfo *actor, AActor *defaults, Baggage &bag); @@ -250,11 +249,11 @@ enum EDefinitionType #define GCC_MSEG #else #define MSVC_ASEG -#define GCC_ASEG __attribute__((section(AREG_SECTION))) +#define GCC_ASEG __attribute__((section(SECTION_AREG))) #define MSVC_PSEG -#define GCC_PSEG __attribute__((section(GREG_SECTION))) +#define GCC_PSEG __attribute__((section(SECTION_GREG))) #define MSVC_MSEG -#define GCC_MSEG __attribute__((section(MREG_SECTION))) +#define GCC_MSEG __attribute__((section(SECTION_MREG))) #endif diff --git a/src/thingdef/thingdef_data.cpp b/src/thingdef/thingdef_data.cpp index 18231e5cbf..a6f81923bd 100644 --- a/src/thingdef/thingdef_data.cpp +++ b/src/thingdef/thingdef_data.cpp @@ -417,7 +417,7 @@ FPropertyInfo *FindProperty(const char * string) // //========================================================================== -AFuncDesc * FindFunction(const char * string) +AFuncDesc *FindFunction(const char * string) { int min = 0, max = AFTable.Size()-1; @@ -444,7 +444,7 @@ AFuncDesc * FindFunction(const char * string) //========================================================================== // -// Find a varIABLE by name using a binary search +// Find a variable by name using a binary search // //========================================================================== @@ -541,11 +541,11 @@ void InitThingdef() // Create a sorted list of properties { - TAutoSegIterator probe; + FAutoSegIterator probe(GRegHead, GRegTail); - while (++probe != NULL) + while (*++probe != NULL) { - properties.Push(probe); + properties.Push((FPropertyInfo *)*probe); } properties.ShrinkToFit(); qsort(&properties[0], properties.Size(), sizeof(properties[0]), propcmp); @@ -553,11 +553,11 @@ void InitThingdef() // Create a sorted list of native action functions { - TAutoSegIterator probe; + FAutoSegIterator probe(ARegHead, ARegTail); - while (++probe != NULL) + while (*++probe != NULL) { - AFTable.Push(*probe); + AFTable.Push(*(AFuncDesc *)*probe); } AFTable.ShrinkToFit(); qsort(&AFTable[0], AFTable.Size(), sizeof(AFTable[0]), funccmp); @@ -565,11 +565,11 @@ void InitThingdef() // Create a sorted list of native variables { - TAutoSegIterator probe; + FAutoSegIterator probe(MRegHead, MRegTail); - while (++probe != NULL) + while (*++probe != NULL) { - variables.Push(probe); + variables.Push((FVariableInfo *)*probe); } variables.ShrinkToFit(); qsort(&variables[0], variables.Size(), sizeof(variables[0]), varcmp); diff --git a/src/thingdef/thingdef_expression.cpp b/src/thingdef/thingdef_expression.cpp index a2fe4935e5..6074fdd876 100644 --- a/src/thingdef/thingdef_expression.cpp +++ b/src/thingdef/thingdef_expression.cpp @@ -49,7 +49,6 @@ #include "p_lnspec.h" #include "doomstat.h" #include "thingdef_exp.h" -#include "autosegs.h" int testglobalvar = 1337; // just for having one global variable to test with DEFINE_GLOBAL_VARIABLE(testglobalvar) diff --git a/src/thingdef/thingdef_parse.cpp b/src/thingdef/thingdef_parse.cpp index a45b4dc409..fedb89c7ad 100644 --- a/src/thingdef/thingdef_parse.cpp +++ b/src/thingdef/thingdef_parse.cpp @@ -48,7 +48,6 @@ #include "templates.h" #include "v_palette.h" #include "doomerrors.h" -#include "autosegs.h" #include "i_system.h" #include "thingdef_exp.h" #include "w_wad.h" @@ -311,7 +310,7 @@ static void ParseVariable (FScanner &sc, PSymbolTable * symt, PClass *cls) } sc.MustGetToken(';'); - FVariableInfo *vi = FindVariable(symname, cls); + const FVariableInfo *vi = FindVariable(symname, cls); if (vi == NULL) { sc.ScriptError("Unknown native variable '%s'", symname.GetChars()); @@ -746,7 +745,7 @@ static void ParseActionDef (FScanner &sc, PClass *cls) }; bool error = false; - AFuncDesc *afd; + const AFuncDesc *afd; FName funcname; FString args; TArray DefaultParams; diff --git a/src/thingdef/thingdef_properties.cpp b/src/thingdef/thingdef_properties.cpp index 401b15914b..a271e3890e 100644 --- a/src/thingdef/thingdef_properties.cpp +++ b/src/thingdef/thingdef_properties.cpp @@ -67,7 +67,6 @@ #include "r_translate.h" #include "a_morph.h" #include "colormatcher.h" -#include "autosegs.h" //========================================================================== diff --git a/src/thingdef/thingdef_states.cpp b/src/thingdef/thingdef_states.cpp index 500e215f3b..d7252c4197 100644 --- a/src/thingdef/thingdef_states.cpp +++ b/src/thingdef/thingdef_states.cpp @@ -39,7 +39,6 @@ */ #include "actor.h" -#include "autosegs.h" #include "info.h" #include "sc_man.h" #include "tarray.h" diff --git a/src/w_wad.cpp b/src/w_wad.cpp index 813d12789f..a322f0aa80 100644 --- a/src/w_wad.cpp +++ b/src/w_wad.cpp @@ -369,7 +369,11 @@ int FWadCollection::GetNumWads () const int FWadCollection::CheckNumForName (const char *name, int space) { - char uname[8]; + union + { + char uname[8]; + QWORD qname; + }; DWORD i; if (name == NULL) @@ -391,7 +395,7 @@ int FWadCollection::CheckNumForName (const char *name, int space) { FResourceLump *lump = LumpInfo[i].lump; - if (*(QWORD *)&lump->Name == *(QWORD *)&uname) + if (lump->qwName == qname) { if (lump->Namespace == space) break; // If the lump is from one of the special namespaces exclusive to Zips @@ -411,7 +415,11 @@ int FWadCollection::CheckNumForName (const char *name, int space) int FWadCollection::CheckNumForName (const char *name, int space, int wadnum, bool exact) { FResourceLump *lump; - char uname[8]; + union + { + char uname[8]; + QWORD qname; + }; DWORD i; if (wadnum < 0) @@ -426,7 +434,7 @@ int FWadCollection::CheckNumForName (const char *name, int space, int wadnum, bo // also those in earlier WADs. while (i != NULL_INDEX && - (lump = LumpInfo[i].lump, *(QWORD *)&lump->Name != *(QWORD *)&uname || + (lump = LumpInfo[i].lump, lump->qwName != qname || lump->Namespace != space || (exact? (LumpInfo[i].wadnum != wadnum) : (LumpInfo[i].wadnum > wadnum)) )) { @@ -738,7 +746,7 @@ void FWadCollection::RenameSprites () // some frames need to be renamed. if (LumpInfo[i].lump->Namespace == ns_sprites) { - if (*(DWORD *)LumpInfo[i].lump->Name == MAKE_ID('M', 'N', 'T', 'R') && LumpInfo[i].lump->Name[4] == 'Z' ) + if (LumpInfo[i].lump->dwName == MAKE_ID('M', 'N', 'T', 'R') && LumpInfo[i].lump->Name[4] == 'Z' ) { MNTRZfound = true; break; @@ -757,9 +765,9 @@ void FWadCollection::RenameSprites () { for (int j = 0; j < numrenames; ++j) { - if (*(DWORD *)LumpInfo[i].lump->Name == renames[j*2]) + if (LumpInfo[i].lump->dwName == renames[j*2]) { - *(DWORD *)LumpInfo[i].lump->Name = renames[j*2+1]; + LumpInfo[i].lump->dwName = renames[j*2+1]; } } if (gameinfo.gametype == GAME_Hexen) @@ -774,7 +782,7 @@ void FWadCollection::RenameSprites () if (!MNTRZfound) { - if (*(DWORD *)LumpInfo[i].lump->Name == MAKE_ID('M', 'N', 'T', 'R')) + if (LumpInfo[i].lump->dwName == MAKE_ID('M', 'N', 'T', 'R')) { if (LumpInfo[i].lump->Name[4] >= 'F' && LumpInfo[i].lump->Name[4] <= 'K') { @@ -787,9 +795,9 @@ void FWadCollection::RenameSprites () // the same blood states can be used everywhere if (!(gameinfo.gametype & GAME_DoomChex)) { - if (*(DWORD *)LumpInfo[i].lump->Name == MAKE_ID('B', 'L', 'O', 'D')) + if (LumpInfo[i].lump->dwName == MAKE_ID('B', 'L', 'O', 'D')) { - *(DWORD *)LumpInfo[i].lump->Name = MAKE_ID('B', 'L', 'U', 'D'); + LumpInfo[i].lump->dwName = MAKE_ID('B', 'L', 'U', 'D'); } } } @@ -807,7 +815,11 @@ void FWadCollection::RenameSprites () int FWadCollection::FindLump (const char *name, int *lastlump, bool anyns) { - char name8[8]; + union + { + char name8[8]; + QWORD qname; + }; LumpRecord *lump_p; uppercopy (name8, name); @@ -817,8 +829,7 @@ int FWadCollection::FindLump (const char *name, int *lastlump, bool anyns) { FResourceLump *lump = lump_p->lump; - if ((anyns || lump->Namespace == ns_global) && - *(QWORD *)&lump->Name == *(QWORD *)&name8) + if ((anyns || lump->Namespace == ns_global) && lump->qwName == qname) { int lump = int(lump_p - &LumpInfo[0]); *lastlump = lump + 1; diff --git a/src/win32/i_crash.cpp b/src/win32/i_crash.cpp index 6f8963b27a..496c6189c6 100644 --- a/src/win32/i_crash.cpp +++ b/src/win32/i_crash.cpp @@ -732,8 +732,10 @@ HANDLE WriteTextReport () for (i = 0; i < 8; ++i) { - Writef (file, "MM%d=%08x%08x\r\n", i, *(DWORD *)(&ctxt->FloatSave.RegisterArea[20*i+4]), - *(DWORD *)(&ctxt->FloatSave.RegisterArea[20*i])); + DWORD d0, d1; + memcpy(&d0, &ctxt->FloatSave.RegisterArea[20*i+4], sizeof(DWORD)); + memcpy(&d1, &ctxt->FloatSave.RegisterArea[20*i], sizeof(DWORD)); + Writef (file, "MM%d=%08x%08x\r\n", i, d0, d1); } #else for (i = 0; i < 8; ++i) @@ -2115,7 +2117,9 @@ repeat: { if (i <= read - 4) { - buff_p += mysnprintf (buff_p, buff_end - buff_p, " %08lx", *(DWORD *)&buf16[i]); + DWORD d; + memcpy(&d, &buf16[i], sizeof(d)); + buff_p += mysnprintf (buff_p, buff_end - buff_p, " %08lx", d); i += 4; } else diff --git a/src/win32/i_dijoy.cpp b/src/win32/i_dijoy.cpp index 5929d4a03b..e21f77e25c 100644 --- a/src/win32/i_dijoy.cpp +++ b/src/win32/i_dijoy.cpp @@ -1293,7 +1293,7 @@ bool FDInputJoystickManager::IsXInputDeviceFast(const GUID *guid) cbSize = rdi.cbSize = sizeof(rdi); if (MyGetRawInputDeviceInfoA(devices[i].hDevice, RIDI_DEVICEINFO, &rdi, &cbSize) >= 0) { - if(MAKELONG(rdi.hid.dwVendorId, rdi.hid.dwProductId) == guid->Data1) + if(MAKELONG(rdi.hid.dwVendorId, rdi.hid.dwProductId) == (LONG)guid->Data1) { char name[256]; UINT namelen = countof(name); diff --git a/src/x86.cpp b/src/x86.cpp index 99e39d553c..8f28bb94ca 100644 --- a/src/x86.cpp +++ b/src/x86.cpp @@ -73,9 +73,9 @@ haveid: // Get vendor ID __cpuid(foo, 0); - ((int *)cpu->VendorID)[0] = foo[1]; - ((int *)cpu->VendorID)[1] = foo[3]; - ((int *)cpu->VendorID)[2] = foo[2]; + cpu->VendorID[0] = foo[1]; + cpu->VendorID[1] = foo[3]; + cpu->VendorID[2] = foo[2]; if (foo[1] == MAKE_ID('A','u','t','h') && foo[3] == MAKE_ID('e','n','t','i') && foo[2] == MAKE_ID('c','A','M','D')) @@ -85,9 +85,9 @@ haveid: // Get features flags and other info __cpuid(foo, 1); - ((int *)cpu)[17] = foo[1]; // Store brand index and other stuff - ((int *)cpu)[18] = foo[2]; // Store extended feature flags - ((int *)cpu)[19] = foo[3]; // Store feature flags + cpu->FeatureFlags[0] = foo[1]; // Store brand index and other stuff + cpu->FeatureFlags[1] = foo[2]; // Store extended feature flags + cpu->FeatureFlags[2] = foo[3]; // Store feature flags // If CLFLUSH instruction is supported, get the real cache line size. if (foo[3] & (1 << 19)) @@ -115,9 +115,9 @@ haveid: if (maxext >= 0x80000004) { // Get processor brand string. - __cpuid((int *)&cpu->CPUString[0], 0x80000002); - __cpuid((int *)&cpu->CPUString[16], 0x80000003); - __cpuid((int *)&cpu->CPUString[32], 0x80000004); + __cpuid((int *)&cpu->dwCPUString[0], 0x80000002); + __cpuid((int *)&cpu->dwCPUString[4], 0x80000003); + __cpuid((int *)&cpu->dwCPUString[8], 0x80000004); } if (cpu->bIsAMD) @@ -125,7 +125,7 @@ haveid: if (maxext >= 0x80000005) { // Get data L1 cache info. __cpuid(foo, 0x80000005); - *(int *)(&cpu->DataL1LineSize) = foo[2]; + cpu->AMD_DataL1Info = foo[2]; } if (maxext >= 0x80000001) { // Get AMD-specific feature flags. diff --git a/src/x86.h b/src/x86.h index 90904c30ac..8768161576 100644 --- a/src/x86.h +++ b/src/x86.h @@ -5,26 +5,41 @@ struct CPUInfo // 92 bytes { - char VendorID[16]; - char CPUString[48]; + union + { + char VendorID[16]; + DWORD dwVendorID[4]; + }; + union + { + char CPUString[48]; + DWORD dwCPUString[12]; + }; - BYTE Stepping; - BYTE Model; - BYTE Family; - BYTE Type; + union + { + struct + { + BYTE Stepping; + BYTE Model; + BYTE Family; + BYTE Type; - BYTE BrandIndex; - BYTE CLFlush; - BYTE CPUCount; - BYTE APICID; + BYTE BrandIndex; + BYTE CLFlush; + BYTE CPUCount; + BYTE APICID; - DWORD bSSE3:1; - DWORD DontCare1:8; - DWORD bSSSE3:1; - DWORD DontCare1a:9; - DWORD bSSE41:1; - DWORD bSSE42:1; - DWORD DontCare2a:11; + DWORD bSSE3:1; + DWORD DontCare1:8; + DWORD bSSSE3:1; + DWORD DontCare1a:9; + DWORD bSSE41:1; + DWORD bSSE42:1; + DWORD DontCare2a:11; + }; + DWORD FeatureFlags[3]; + }; DWORD bFPU:1; DWORD bVME:1; @@ -71,10 +86,17 @@ struct CPUInfo // 92 bytes BYTE AMDFamily; BYTE bIsAMD; - BYTE DataL1LineSize; - BYTE DataL1LinesPerTag; - BYTE DataL1Associativity; - BYTE DataL1SizeKB; + union + { + struct + { + BYTE DataL1LineSize; + BYTE DataL1LinesPerTag; + BYTE DataL1Associativity; + BYTE DataL1SizeKB; + }; + DWORD AMD_DataL1Info; + }; };