Parenthesize SPV_BIT macro to avoid surprises.

This commit is contained in:
David Neto 2015-08-14 13:57:02 -04:00
parent 17f1bae331
commit f6184a8b37
3 changed files with 37 additions and 1 deletions

View File

@ -158,6 +158,7 @@ if (TARGET gtest)
${CMAKE_CURRENT_SOURCE_DIR}/test/FixWord.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/BinaryHeaderGet.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/BinaryToText.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/LibspirvMacros.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/NamedId.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/OpcodeTableGet.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/OpcodeIsVariable.cpp

View File

@ -90,7 +90,7 @@ extern "C" {
#define spvIsInBitfield(value, bitfield) (value == (value & bitfield))
#define SPV_BIT(shift) 1 << shift
#define SPV_BIT(shift) (1 << (shift))
#define SPV_FORCE_16_BIT_ENUM(name) _##name = 0x7fff
#define SPV_FORCE_32_BIT_ENUM(name) _##name = 0x7fffffff

35
test/LibspirvMacros.cpp Normal file
View File

@ -0,0 +1,35 @@
// Copyright (c) 2015 The Khronos Group Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and/or associated documentation files (the
// "Materials"), to deal in the Materials without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Materials, and to
// permit persons to whom the Materials are furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Materials.
//
// MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS
// KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS
// SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT
// https://www.khronos.org/registry/
//
// THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
#include "UnitSPIRV.h"
TEST(Macros, BitShiftInnerParens) {
ASSERT_EQ(65536, SPV_BIT(2 << 3));
}
TEST(Macros, BitShiftOuterParens) {
ASSERT_EQ(15, SPV_BIT(4)-1);
}