From 00b1fe044840e7818c6c9bcd4c42d4baafd5b78a Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Tue, 4 Aug 2020 10:43:05 -0700 Subject: Fix stdlib declarations of bit-shift ops (#1471) The declarations of the left- and right-shift operations in the Slang standard library were set up identically to the declarations of operator binary (and compound binary) operations. A consequence of this choice was that both operands to a shift were expected to have the same type, which can lead to a confusing result. If the user wrote a shift of the form `int >> uint`, then the ordinary promotion rules for Slang would decide to perform the operation on `uint` value, so it would change to `uint(int) >> uint` and perform an unsigned shift, which isn't what the user would expect. The fix implemented here is to make the shift operations be declared separately from the other binary operations, with *two* generic type parameters instead of one: distinct parameters for the left-hand-side and right-hand side types. Each parameter is only constrained to be a built-in integer type. --- source/slang/slang-stdlib.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'source/slang/slang-stdlib.cpp') diff --git a/source/slang/slang-stdlib.cpp b/source/slang/slang-stdlib.cpp index a310ba748..e0727f19a 100644 --- a/source/slang/slang-stdlib.cpp +++ b/source/slang/slang-stdlib.cpp @@ -208,8 +208,6 @@ namespace Slang { kIROp_BitAnd, "&", "__BuiltinLogicalType", LOGICAL_MASK }, { kIROp_BitOr, "|", "__BuiltinLogicalType", LOGICAL_MASK }, { kIROp_BitXor, "^", "__BuiltinLogicalType", LOGICAL_MASK }, - { kIROp_Lsh, "<<", "__BuiltinIntegerType", INT_MASK }, - { kIROp_Rsh, ">>", "__BuiltinIntegerType", INT_MASK }, { kIROp_Eql, "==", "__BuiltinType", ANY_MASK | BOOL_RESULT }, { kIROp_Neq, "!=", "__BuiltinType", ANY_MASK | BOOL_RESULT }, { kIROp_Greater, ">", "__BuiltinArithmeticType", ARITHMETIC_MASK | BOOL_RESULT }, -- cgit v1.2.3