diff options
Diffstat (limited to 'source')
| -rw-r--r-- | source/core/allocator.h | 5 | ||||
| -rw-r--r-- | source/core/common.h | 7 | ||||
| -rw-r--r-- | source/core/secure-crt.h | 20 | ||||
| -rw-r--r-- | source/core/slang-cpu-defines.h | 13 | ||||
| -rw-r--r-- | source/core/slang-math.h | 50 | ||||
| -rw-r--r-- | source/core/stream.cpp | 8 | ||||
| -rw-r--r-- | source/core/type-traits.h | 4 | ||||
| -rw-r--r-- | source/slang/check.cpp | 1 | ||||
| -rw-r--r-- | source/slang/core.meta.slang | 6 | ||||
| -rw-r--r-- | source/slang/core.meta.slang.h | 6 | ||||
| -rw-r--r-- | source/slang/default-file-system.h | 3 | ||||
| -rw-r--r-- | source/slang/diagnostics.cpp | 2 | ||||
| -rw-r--r-- | source/slang/emit.cpp | 7 | ||||
| -rw-r--r-- | source/slang/ir-legalize-types.cpp | 2 | ||||
| -rw-r--r-- | source/slang/ir-restructure.cpp | 2 | ||||
| -rw-r--r-- | source/slang/ir.cpp | 9 | ||||
| -rw-r--r-- | source/slang/lower-to-ir.cpp | 4 | ||||
| -rw-r--r-- | source/slang/mangle.cpp | 4 | ||||
| -rw-r--r-- | source/slang/parser.cpp | 4 | ||||
| -rw-r--r-- | source/slang/preprocessor.cpp | 6 | ||||
| -rw-r--r-- | source/slang/slang-stdlib.cpp | 1 | ||||
| -rw-r--r-- | source/slang/source-loc.h | 10 | ||||
| -rw-r--r-- | source/slang/syntax.h | 12 |
23 files changed, 107 insertions, 79 deletions
diff --git a/source/core/allocator.h b/source/core/allocator.h index 46550a054..3306d3780 100644 --- a/source/core/allocator.h +++ b/source/core/allocator.h @@ -2,6 +2,9 @@ #define CORE_LIB_ALLOCATOR_H #include <stdlib.h> +#ifdef _MSC_VER +# include <malloc.h> +#endif namespace Slang { @@ -9,6 +12,8 @@ namespace Slang { #ifdef _MSC_VER return _aligned_malloc(size, alignment); +#elif defined(__CYGWIN__) + return aligned_alloc(alignment, size); #else void * rs = 0; int succ = posix_memalign(&rs, alignment, size); diff --git a/source/core/common.h b/source/core/common.h index 17161ab14..5aa7b7737 100644 --- a/source/core/common.h +++ b/source/core/common.h @@ -38,9 +38,12 @@ namespace Slang } #ifdef _MSC_VER -#define SLANG_RETURN_NEVER __declspec(noreturn) +# define SLANG_RETURN_NEVER __declspec(noreturn) +//#elif SLANG_CLANG +//# define SLANG_RETURN_NEVER [[noreturn]] #else -#define SLANG_RETURN_NEVER /* empty */ +# define SLANG_RETURN_NEVER [[noreturn]] +//# define SLANG_RETURN_NEVER /* empty */ #endif #ifdef _MSC_VER diff --git a/source/core/secure-crt.h b/source/core/secure-crt.h index a76fb2679..52a0d4870 100644 --- a/source/core/secure-crt.h +++ b/source/core/secure-crt.h @@ -5,6 +5,8 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <strings.h> + #include <wchar.h> inline void memcpy_s(void *dest, size_t numberOfElements, const void * src, size_t count) @@ -30,16 +32,26 @@ inline size_t wcsnlen_s(const wchar_t * str, size_t /*numberofElements*/) return wcslen(str); } -inline size_t strnlen_s(const char * str, size_t numberofElements) +inline size_t strnlen_s(const char * str, size_t numberOfElements) { - return strnlen(str, numberofElements); +#if defined( __CYGWIN__ ) + const char* cur = str; + if (str) + { + const char*const end = str + numberOfElements; + while (*cur && cur < end) cur++; + } + return size_t(cur - str); +#else + return strnlen(str, numberOfElements); +#endif } inline int sprintf_s(char * buffer, size_t sizeOfBuffer, const char * format, ...) { va_list argptr; va_start(argptr, format); - int rs = snprintf(buffer, sizeOfBuffer, format, argptr); + int rs = vsnprintf(buffer, sizeOfBuffer, format, argptr); va_end(argptr); return rs; } @@ -48,7 +60,7 @@ inline int swprintf_s(wchar_t * buffer, size_t sizeOfBuffer, const wchar_t * for { va_list argptr; va_start(argptr, format); - int rs = swprintf(buffer, sizeOfBuffer, format, argptr); + int rs = vswprintf(buffer, sizeOfBuffer, format, argptr); va_end(argptr); return rs; } diff --git a/source/core/slang-cpu-defines.h b/source/core/slang-cpu-defines.h index dc76008b9..5ad1ecf88 100644 --- a/source/core/slang-cpu-defines.h +++ b/source/core/slang-cpu-defines.h @@ -54,6 +54,19 @@ #define SLANG_PTR_IS_64 (SLANG_PROCESSOR_ARM_64 | SLANG_PROCESSOR_X86_64 | SLANG_PROCESSOR_POWER_PC_64) #define SLANG_PTR_IS_32 (SLANG_PTR_IS_64 ^ 1) +// TODO: This isn't great. The problem is UInt maps to size_t, and on some targets (like OSX) +// size_t is distinct from any other integral type. So that creates an ambiguity +// Really we want to modify the StringBuilder and elsewhere to handle the case when it is known it can't unambiguously coerce +namespace Slang { +#ifdef SLANG_PTR_IS_64 +typedef UInt64 UnambigousUInt; +typedef Int64 UnambiguousInt; +#else +typedef UInt32 UnambigousUInt; +typedef Int32 UnambiguousInt; +#endif +} // namespace Slang + // Processor features #if SLANG_PROCESSOR_FAMILY_X86 # define SLANG_LITTLE_ENDIAN 1 diff --git a/source/core/slang-math.h b/source/core/slang-math.h index 6d6b3e7a1..a245e2d2c 100644 --- a/source/core/slang-math.h +++ b/source/core/slang-math.h @@ -8,6 +8,17 @@ namespace Slang class Math { public: + // Use to fix type punning issues with strict aliasing + union FloatIntUnion + { + float fvalue; + int ivalue; + + inline static FloatIntUnion makeFromInt(int i) { FloatIntUnion cast; cast.ivalue = i; return cast; } + inline static FloatIntUnion makeFromFloat(float f) { FloatIntUnion cast; cast.fvalue = f; return cast; } + }; + + static const float Pi; template<typename T> static T Min(const T& v1, const T&v2) @@ -110,30 +121,19 @@ namespace Slang } */ }; - inline int FloatAsInt(float val) + inline int FloatAsInt(float val) { - union InterCast - { - float fvalue; - int ivalue; - } cast; - cast.fvalue = val; - return cast.ivalue; + return Math::FloatIntUnion::makeFromFloat(val).ivalue; } - inline float IntAsFloat(int val) + inline float IntAsFloat(int val) { - union InterCast - { - float fvalue; - int ivalue; - } cast; - cast.ivalue = val; - return cast.fvalue; + return Math::FloatIntUnion::makeFromInt(val).fvalue; } inline unsigned short FloatToHalf(float val) { - int x = *(int*)&val; + const auto x = FloatAsInt(val); + unsigned short bits = (x >> 16) & 0x8000; unsigned short m = (x >> 12) & 0x07ff; unsigned int e = (x >> 23) & 0xff; @@ -158,19 +158,9 @@ namespace Slang inline float HalfToFloat(unsigned short input) { - union InterCast - { - float fvalue; - int ivalue; - InterCast() = default; - InterCast(int ival) - { - ivalue = ival; - } - }; - static const InterCast magic = InterCast((127 + (127 - 15)) << 23); - static const InterCast was_infnan = InterCast((127 + 16) << 23); - InterCast o; + static const auto magic = Math::FloatIntUnion::makeFromInt((127 + (127 - 15)) << 23); + static const auto was_infnan = Math::FloatIntUnion::makeFromInt((127 + 16) << 23); + Math::FloatIntUnion o; o.ivalue = (input & 0x7fff) << 13; // exponent/mantissa bits o.fvalue *= magic.fvalue; // exponent adjust if (o.fvalue >= was_infnan.fvalue) // make sure Inf/NaN survive diff --git a/source/core/stream.cpp b/source/core/stream.cpp index b705b13a1..949ce718c 100644 --- a/source/core/stream.cpp +++ b/source/core/stream.cpp @@ -91,9 +91,9 @@ namespace Slang default: break; } - int shFlag; #ifdef _WIN32 - switch (share) + int shFlag = _SH_DENYRW; + switch (share) { case Slang::FileShare::None: shFlag = _SH_DENYRW; @@ -130,13 +130,13 @@ namespace Slang } Int64 FileStream::GetPosition() { -#ifdef _WIN32 +#if defined(_WIN32) || defined(__CYGWIN__) fpos_t pos; fgetpos(handle, &pos); return pos; #elif defined(__APPLE__) return ftell(handle); -#else +#else fpos64_t pos; fgetpos64(handle, &pos); return *(Int64*)(&pos); diff --git a/source/core/type-traits.h b/source/core/type-traits.h index 5a05538d3..804b4d3fe 100644 --- a/source/core/type-traits.h +++ b/source/core/type-traits.h @@ -37,8 +37,8 @@ namespace Slang template <typename B, typename D> struct IsConvertible { - static TraitResultYes Use(B) {}; - static TraitResultNo Use(...) {}; + static TraitResultYes Use(B) { return TraitResultYes(); }; + static TraitResultNo Use(...) { return TraitResultNo(); }; enum { Value = sizeof(Use(*(D*)(nullptr))) == sizeof(TraitResultYes) }; }; } diff --git a/source/slang/check.cpp b/source/slang/check.cpp index 47713e6cc..278ba7b61 100644 --- a/source/slang/check.cpp +++ b/source/slang/check.cpp @@ -5283,7 +5283,6 @@ namespace Slang RefPtr<Type> bestType; if(auto basicType = type.As<BasicExpressionType>()) { - basicType->baseType; for(Int baseTypeFlavorIndex = 0; baseTypeFlavorIndex < Int(BaseType::CountOf); baseTypeFlavorIndex++) { // Don't consider `type`, since we already know it doesn't work. diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang index b1e6e0fd6..0502c9bf6 100644 --- a/source/slang/core.meta.slang +++ b/source/slang/core.meta.slang @@ -80,19 +80,19 @@ for (int tt = 0; tt < kBaseTypeCount; ++tt) case BaseType::Double: sb << "\n , __BuiltinFloatingPointType\n"; sb << "\n , __BuiltinRealType\n"; - // fall through to: + ; // fall through to: case BaseType::Int8: case BaseType::Int16: case BaseType::Int: case BaseType::Int64: sb << "\n , __BuiltinSignedArithmeticType\n"; - // fall through to: + ; // fall through to: case BaseType::UInt8: case BaseType::UInt16: case BaseType::UInt: case BaseType::UInt64: sb << "\n , __BuiltinArithmeticType\n"; - // fall through to: + ; // fall through to: case BaseType::Bool: sb << "\n , __BuiltinType\n"; break; diff --git a/source/slang/core.meta.slang.h b/source/slang/core.meta.slang.h index f0d61fa12..97a2d1edd 100644 --- a/source/slang/core.meta.slang.h +++ b/source/slang/core.meta.slang.h @@ -80,19 +80,19 @@ for (int tt = 0; tt < kBaseTypeCount; ++tt) case BaseType::Double: sb << "\n , __BuiltinFloatingPointType\n"; sb << "\n , __BuiltinRealType\n"; - // fall through to: + ; // fall through to: case BaseType::Int8: case BaseType::Int16: case BaseType::Int: case BaseType::Int64: sb << "\n , __BuiltinSignedArithmeticType\n"; - // fall through to: + ; // fall through to: case BaseType::UInt8: case BaseType::UInt16: case BaseType::UInt: case BaseType::UInt64: sb << "\n , __BuiltinArithmeticType\n"; - // fall through to: + ; // fall through to: case BaseType::Bool: sb << "\n , __BuiltinType\n"; break; diff --git a/source/slang/default-file-system.h b/source/slang/default-file-system.h index 47644f5ad..7805dd81a 100644 --- a/source/slang/default-file-system.h +++ b/source/slang/default-file-system.h @@ -43,6 +43,7 @@ public: private: /// Make so not constructible DefaultFileSystem() {} + virtual ~DefaultFileSystem() {} ISlangUnknown* getInterface(const Guid& guid); @@ -88,6 +89,8 @@ public: m_fileSystem(fileSystem) { } + virtual ~WrapFileSystem() {} + protected: ISlangUnknown* getInterface(const Guid& guid); diff --git a/source/slang/diagnostics.cpp b/source/slang/diagnostics.cpp index c4638f29a..7271c04d3 100644 --- a/source/slang/diagnostics.cpp +++ b/source/slang/diagnostics.cpp @@ -173,7 +173,7 @@ static void formatDiagnostic( sb << humaneLoc.pathInfo.foundPath; sb << "("; - sb << humaneLoc.line; + sb << Int32(humaneLoc.line); sb << "): "; sb << getSeverityName(diagnostic.severity); diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index c9e19dffc..9c7d61c51 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -2213,7 +2213,7 @@ struct EmitVisitor context->shared->uniqueNameCounters[key] = count+1; - sb.append(count); + sb.append(Int32(count)); return sb.ProduceString(); } @@ -2238,8 +2238,7 @@ struct EmitVisitor // for the instruction. StringBuilder sb; sb << "_S"; - sb << getID(inst); - + sb << Int32(getID(inst)); return sb.ProduceString(); } @@ -5000,7 +4999,7 @@ struct EmitVisitor String paramName; paramName.append("_"); - paramName.append(pp); + paramName.append(Int32(pp)); auto paramType = funcType->getParamType(pp); emitIRParamType(ctx, paramType, paramName); diff --git a/source/slang/ir-legalize-types.cpp b/source/slang/ir-legalize-types.cpp index 931ceb85a..b86c9f6e9 100644 --- a/source/slang/ir-legalize-types.cpp +++ b/source/slang/ir-legalize-types.cpp @@ -1201,7 +1201,7 @@ static LegalVal declareSimpleVar( if (mangledNameStr.Length() != 0) { mangledNameStr.append("L"); - mangledNameStr.append(globalNameInfo->counter++); + mangledNameStr.append(Int32(globalNameInfo->counter++)); globalVar->mangledName = context->session->getNameObj(mangledNameStr); } } diff --git a/source/slang/ir-restructure.cpp b/source/slang/ir-restructure.cpp index dc35a8aee..d8d3fe7c9 100644 --- a/source/slang/ir-restructure.cpp +++ b/source/slang/ir-restructure.cpp @@ -250,7 +250,7 @@ namespace Slang // information that can inform our control-flow restructuring pass. // SLANG_UNEXPECTED("unhandled terminator instruction opcode"); - // fall through to: + ; // fall through to: case kIROp_Unreachable: case kIROp_MissingReturn: case kIROp_ReturnVal: diff --git a/source/slang/ir.cpp b/source/slang/ir.cpp index f05aeabf6..6e14edc1f 100644 --- a/source/slang/ir.cpp +++ b/source/slang/ir.cpp @@ -3,6 +3,8 @@ #include "ir-insts.h" #include "../core/basic.h" +#include "../core/slang-cpu-defines.h" + #include "mangle.h" namespace Slang @@ -2570,8 +2572,7 @@ namespace Slang IRDumpContext* context, UInt val) { - context->builder->append(val); - + context->builder->append(UnambigousUInt(val)); // fprintf(context->file, "%llu", (unsigned long long)val); } @@ -2771,10 +2772,6 @@ namespace Slang IRDumpContext* context, IRType* type); - static void dumpDeclRef( - IRDumpContext* context, - DeclRef<Decl> const& declRef); - static void dumpOperand( IRDumpContext* context, IRInst* inst) diff --git a/source/slang/lower-to-ir.cpp b/source/slang/lower-to-ir.cpp index 1ee521e3b..6cce469ea 100644 --- a/source/slang/lower-to-ir.cpp +++ b/source/slang/lower-to-ir.cpp @@ -2691,7 +2691,7 @@ struct StmtLoweringVisitor : StmtVisitor<StmtLoweringVisitor> // We just need to look up the basic block that // corresponds to the break label for that statement, // and then emit an instruction to jump to it. - IRBlock* targetBlock; + IRBlock* targetBlock = nullptr; context->shared->breakLabels.TryGetValue(parentStmt, targetBlock); SLANG_ASSERT(targetBlock); getBuilder()->emitBreak(targetBlock); @@ -2710,7 +2710,7 @@ struct StmtLoweringVisitor : StmtVisitor<StmtLoweringVisitor> // We just need to look up the basic block that // corresponds to the continue label for that statement, // and then emit an instruction to jump to it. - IRBlock* targetBlock; + IRBlock* targetBlock = nullptr; context->shared->continueLabels.TryGetValue(parentStmt, targetBlock); SLANG_ASSERT(targetBlock); getBuilder()->emitContinue(targetBlock); diff --git a/source/slang/mangle.cpp b/source/slang/mangle.cpp index c35ad1e14..c2645929f 100644 --- a/source/slang/mangle.cpp +++ b/source/slang/mangle.cpp @@ -4,6 +4,8 @@ #include "ir-insts.h" #include "syntax.h" +#include "../core/slang-cpu-defines.h" + namespace Slang { struct ManglingContext @@ -22,7 +24,7 @@ namespace Slang ManglingContext* context, UInt value) { - context->sb.append(value); + context->sb.append(UnambigousUInt(value)); } void emit( diff --git a/source/slang/parser.cpp b/source/slang/parser.cpp index 4ebbdd191..9ccd7b962 100644 --- a/source/slang/parser.cpp +++ b/source/slang/parser.cpp @@ -993,7 +993,7 @@ namespace Slang nameToken.Content = nameToken.Content + ":"; break; } - + ; // fall-thru default: parser->sink->diagnose(nameToken.loc, Diagnostics::invalidOperator, nameToken); break; @@ -3689,12 +3689,14 @@ namespace Slang case TokenType::OpGeq: // Don't allow these ops inside a generic argument if (parser->genericDepth > 0) return Precedence::Invalid; + ; // fall-thru case TokenType::OpLeq: case TokenType::OpLess: return Precedence::RelationalComparison; case TokenType::OpRsh: // Don't allow this op inside a generic argument if (parser->genericDepth > 0) return Precedence::Invalid; + ; // fall-thru case TokenType::OpLsh: return Precedence::BitShift; case TokenType::OpAdd: diff --git a/source/slang/preprocessor.cpp b/source/slang/preprocessor.cpp index ca11b24e8..47aa0cfd4 100644 --- a/source/slang/preprocessor.cpp +++ b/source/slang/preprocessor.cpp @@ -992,7 +992,7 @@ static Token AdvanceToken(PreprocessorDirectiveContext* context) static Token PeekToken(PreprocessorDirectiveContext* context) { if (IsEndOfLine(context)) - context->preprocessor->endOfFileToken; + return context->preprocessor->endOfFileToken; return PeekToken(context->preprocessor); } @@ -2091,11 +2091,11 @@ static const PreprocessorDirective kDirectives[] = { "version", &handleGLSLVersionDirective, 0 }, { "extension", &handleGLSLExtensionDirective, 0 }, - { NULL, NULL }, + { nullptr, nullptr, 0 }, }; static const PreprocessorDirective kInvalidDirective = { - NULL, &HandleInvalidDirective, 0, + nullptr, &HandleInvalidDirective, 0, }; // Look up the directive with the given name. diff --git a/source/slang/slang-stdlib.cpp b/source/slang/slang-stdlib.cpp index 5a4718af4..936c92fdd 100644 --- a/source/slang/slang-stdlib.cpp +++ b/source/slang/slang-stdlib.cpp @@ -24,6 +24,7 @@ namespace Slang case '\t': case '\\': pathBuilder << "\\"; + ; // fall-thru default: pathBuilder << *cc; break; diff --git a/source/slang/source-loc.h b/source/slang/source-loc.h index 8f6b8f7cb..aba9b7bd9 100644 --- a/source/slang/source-loc.h +++ b/source/slang/source-loc.h @@ -60,12 +60,12 @@ struct PathInfo const String getMostUniquePath() const; // So simplify construction. In normal usage it's safer to use make methods over constructing directly. - static PathInfo makeUnknown() { return PathInfo { Type::Unknown, "unknown" }; } - static PathInfo makeTokenPaste() { return PathInfo{ Type::TokenPaste, "token paste" }; } + static PathInfo makeUnknown() { return PathInfo { Type::Unknown, "unknown", String() }; } + static PathInfo makeTokenPaste() { return PathInfo{ Type::TokenPaste, "token paste", String()}; } static PathInfo makeNormal(const String& foundPathIn, const String& canonicalPathIn) { SLANG_ASSERT(canonicalPathIn.Length() > 0 && foundPathIn.Length() > 0); return PathInfo { Type::Normal, foundPathIn, canonicalPathIn }; } - static PathInfo makePath(const String& pathIn) { SLANG_ASSERT(pathIn.Length() > 0); return PathInfo { Type::FoundPath, pathIn }; } - static PathInfo makeTypeParse() { return PathInfo { Type::TypeParse, "type string" }; } - static PathInfo makeCommandLine() { return PathInfo { Type::CommandLine, "command line" }; } + static PathInfo makePath(const String& pathIn) { SLANG_ASSERT(pathIn.Length() > 0); return PathInfo { Type::FoundPath, pathIn, String()}; } + static PathInfo makeTypeParse() { return PathInfo { Type::TypeParse, "type string", String() }; } + static PathInfo makeCommandLine() { return PathInfo { Type::CommandLine, "command line", String() }; } Type type; ///< The type of path String foundPath; ///< The path where the file was found (might contain relative elements) diff --git a/source/slang/syntax.h b/source/slang/syntax.h index 019740a5e..7bd2afc12 100644 --- a/source/slang/syntax.h +++ b/source/slang/syntax.h @@ -330,8 +330,8 @@ namespace Slang SyntaxClassBase() {} - SyntaxClassBase(ClassInfo const* classInfo) - : classInfo(classInfo) + SyntaxClassBase(ClassInfo const* classInfoIn) + : classInfo(classInfoIn) {} void* createInstanceImpl() const @@ -375,11 +375,13 @@ namespace Slang return (T*)createInstanceImpl(); } + SyntaxClass(const ClassInfo* classInfoIn): + SyntaxClassBase(classInfoIn) + {} + static SyntaxClass<T> getClass() { - SyntaxClass<T> result; - result.classInfo = &SyntaxClass::Impl<T>::kClassInfo; - return result; + return SyntaxClass<T>(&SyntaxClassBase::Impl<T>::kClassInfo); } template<typename U> |
