diff --git a/cmake/CompileFlags.cmake b/cmake/CompileFlags.cmake index a85a915c3b..8da4be8bab 100644 --- a/cmake/CompileFlags.cmake +++ b/cmake/CompileFlags.cmake @@ -74,12 +74,6 @@ macro(compile_flags) # We use 'ABCD' multichar for SaveLoad chunks identifiers -Wno-multichar - - # Compilers complains about that we break strict-aliasing. - # On most places we don't see how to fix it, and it doesn't - # break anything. So disable strict-aliasing to make the - # compiler all happy. - -fno-strict-aliasing ) # Ninja processes the output so the output from the compiler diff --git a/src/3rdparty/squirrel/squirrel/sqcompiler.cpp b/src/3rdparty/squirrel/squirrel/sqcompiler.cpp index 6f67796839..560edfc66b 100644 --- a/src/3rdparty/squirrel/squirrel/sqcompiler.cpp +++ b/src/3rdparty/squirrel/squirrel/sqcompiler.cpp @@ -650,8 +650,7 @@ public: _fs->AddInstruction(_OP_LOADINT, _exst._deref,_integer(constval)); } else if(ctype == OT_FLOAT && sizeof(SQFloat) == sizeof(SQInt32)) { - SQFloat f = _float(constval); - _fs->AddInstruction(_OP_LOADFLOAT, _exst._deref,*((SQInt32 *)&f)); + _fs->AddInstruction(_OP_LOADFLOAT, _exst._deref, std::bit_cast(_float(constval))); } else { _fs->AddInstruction(_OP_LOAD, _exst._deref, _fs->GetConstant(constval)); @@ -697,7 +696,7 @@ public: break; case TK_FLOAT: if(sizeof(SQFloat) == sizeof(SQInt32)) { - _fs->AddInstruction(_OP_LOADFLOAT, _fs->PushTarget(),*((SQInt32 *)&_lex._fvalue)); + _fs->AddInstruction(_OP_LOADFLOAT, _fs->PushTarget(), std::bit_cast(_lex._fvalue)); } else { _fs->AddInstruction(_OP_LOAD, _fs->PushTarget(), _fs->GetNumericConstant(_lex._fvalue)); diff --git a/src/3rdparty/squirrel/squirrel/sqfuncstate.cpp b/src/3rdparty/squirrel/squirrel/sqfuncstate.cpp index e6e64ba81a..54744292a9 100644 --- a/src/3rdparty/squirrel/squirrel/sqfuncstate.cpp +++ b/src/3rdparty/squirrel/squirrel/sqfuncstate.cpp @@ -199,7 +199,7 @@ void SQFuncState::Dump(SQFunctionProto *func) } } else if(inst.op==_OP_LOADFLOAT) { - printf("[%03d] %15s %d %f %d %d\n",n,g_InstrDesc[inst.op].name,inst._arg0,*((SQFloat*)&inst._arg1),inst._arg2,inst._arg3); + printf("[%03d] %15s %d %f %d %d\n",n,g_InstrDesc[inst.op].name,inst._arg0,std::bit_cast(inst._arg1),inst._arg2,inst._arg3); } else if(inst.op==_OP_ARITH){ printf("[%03d] %15s %d %d %d %c\n",n,g_InstrDesc[inst.op].name,inst._arg0,inst._arg1,inst._arg2,inst._arg3); @@ -242,19 +242,20 @@ SQInteger SQFuncState::GetConstant(const SQObject &cons) void SQFuncState::SetIntructionParams(SQInteger pos,SQInteger arg0,SQInteger arg1,SQInteger arg2,SQInteger arg3) { - _instructions[pos]._arg0=(unsigned char)*((SQUnsignedInteger *)&arg0); - _instructions[pos]._arg1=(SQInt32)*((SQUnsignedInteger *)&arg1); - _instructions[pos]._arg2=(unsigned char)*((SQUnsignedInteger *)&arg2); - _instructions[pos]._arg3=(unsigned char)*((SQUnsignedInteger *)&arg3); + _instructions[pos]._arg0 = (unsigned char)std::bit_cast(arg0); + _instructions[pos]._arg1 = (SQInt32)std::bit_cast(arg1); + _instructions[pos]._arg2 = (unsigned char)std::bit_cast(arg2); + _instructions[pos]._arg3 = (unsigned char)std::bit_cast(arg3); } void SQFuncState::SetIntructionParam(SQInteger pos,SQInteger arg,SQInteger val) { switch(arg){ - case 0:_instructions[pos]._arg0=(unsigned char)*((SQUnsignedInteger *)&val);break; - case 1:case 4:_instructions[pos]._arg1=(SQInt32)*((SQUnsignedInteger *)&val);break; - case 2:_instructions[pos]._arg2=(unsigned char)*((SQUnsignedInteger *)&val);break; - case 3:_instructions[pos]._arg3=(unsigned char)*((SQUnsignedInteger *)&val);break; + case 0: _instructions[pos]._arg0 = (unsigned char)std::bit_cast(val); break; + case 1: + case 4: _instructions[pos]._arg1 = (SQInt32)std::bit_cast(val); break; + case 2: _instructions[pos]._arg2 = (unsigned char)std::bit_cast(val); break; + case 3: _instructions[pos]._arg3 = (unsigned char)std::bit_cast(val); break; }; } diff --git a/src/3rdparty/squirrel/squirrel/sqvm.cpp b/src/3rdparty/squirrel/squirrel/sqvm.cpp index 02dbc1625d..52a4dfe85c 100644 --- a/src/3rdparty/squirrel/squirrel/sqvm.cpp +++ b/src/3rdparty/squirrel/squirrel/sqvm.cpp @@ -51,7 +51,7 @@ bool SQVM::BW_OP(SQUnsignedInteger op,SQObjectPtr &trg,const SQObjectPtr &o1,con case BW_XOR: res = i1 ^ i2; break; case BW_SHIFTL: res = i1 << i2; break; case BW_SHIFTR: res = i1 >> i2; break; - case BW_USHIFTR:res = (SQInteger)(*((SQUnsignedInteger*)&i1) >> i2); break; + case BW_USHIFTR:res = (SQInteger)(std::bit_cast(i1) >> i2); break; default: { Raise_Error("internal vm error bitwise op failed"); return false; } } } @@ -472,10 +472,10 @@ bool SQVM::DerefInc(SQInteger op,SQObjectPtr &target, SQObjectPtr &self, SQObjec #define arg0 (_i_._arg0) #define arg1 (_i_._arg1) -#define sarg1 (*(const_cast(&_i_._arg1))) +#define sarg1 (std::bit_cast(_i_._arg1)) #define arg2 (_i_._arg2) #define arg3 (_i_._arg3) -#define sarg3 ((SQInteger)*((const signed char *)&_i_._arg3)) +#define sarg3 ((SQInteger)std::bit_cast(_i_._arg3)) SQRESULT SQVM::Suspend() { @@ -764,7 +764,7 @@ exception_restore: continue; case _OP_LOAD: TARGET = ci->_literals[arg1]; continue; case _OP_LOADINT: TARGET = (SQInteger)arg1; continue; - case _OP_LOADFLOAT: TARGET = *((const SQFloat *)&arg1); continue; + case _OP_LOADFLOAT: TARGET = std::bit_cast(arg1); continue; case _OP_DLOAD: TARGET = ci->_literals[arg1]; STK(arg2) = ci->_literals[arg3];continue; case _OP_TAILCALL: temp_reg = STK(arg1);