Skip to content

Commit b0ac6be

Browse files
author
joaosaffran
committed
addressing comments and fix tests
1 parent 8ec40aa commit b0ac6be

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

llvm/include/llvm/BinaryFormat/DXContainer.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -550,12 +550,17 @@ static_assert(sizeof(ProgramSignatureElement) == 32,
550550

551551
struct RootSignatureValidations {
552552

553-
static bool validateRootFlag(uint32_t Flags) {
554-
return (Flags & ~0x80000fff) != 0;
553+
static Expected<uint32_t> validateRootFlag(uint32_t Flags) {
554+
if ((Flags & ~0x80000fff) != 0)
555+
return llvm::make_error<BinaryStreamError>("Invalid Root Signature flag");
556+
return Flags;
555557
}
556558

557-
static bool validateVersion(uint32_t Version) {
558-
return (Version < 1 || Version > 2);
559+
static Expected<uint32_t> validateVersion(uint32_t Version) {
560+
if (Version < 1 || Version > 2)
561+
return llvm::make_error<BinaryStreamError>(
562+
"Invalid Root Signature Version");
563+
return Version;
559564
}
560565
};
561566

llvm/lib/Object/DXContainer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,9 @@ Error DirectX::RootSignature::parse(StringRef Data) {
250250
const char *Current = Data.begin();
251251

252252
// Root Signature headers expects 6 integers to be present.
253-
if (Data.size() < 6 * sizeof(uint32_t)) {
254-
return parseFailed("Invalid data. Too small.");
255-
}
253+
if (Data.size() < 6 * sizeof(uint32_t))
254+
return parseFailed(
255+
"Invalid root signature, insufficient space for header.");
256256

257257
uint32_t VValue =
258258
support::endian::read<uint32_t, llvm::endianness::little>(Current);

llvm/unittests/Object/DXContainerTest.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -855,8 +855,10 @@ TEST(RootSignature, ParseRootFlags) {
855855
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
856856
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
857857
};
858-
EXPECT_THAT_EXPECTED(DXContainer::create(getMemoryBuffer<64>(Buffer)),
859-
FailedWithMessage("Invalid data. Too small."));
858+
EXPECT_THAT_EXPECTED(
859+
DXContainer::create(getMemoryBuffer<64>(Buffer)),
860+
FailedWithMessage(
861+
"Invalid root signature, insufficient space for header."));
860862
}
861863
{
862864
// Version has been changed to an invalid number.
@@ -868,8 +870,10 @@ TEST(RootSignature, ParseRootFlags) {
868870
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
869871
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
870872
};
871-
EXPECT_THAT_EXPECTED(DXContainer::create(getMemoryBuffer<68>(Buffer)),
872-
FailedWithMessage("Invalid Version"));
873+
EXPECT_THAT_EXPECTED(
874+
DXContainer::create(getMemoryBuffer<68>(Buffer)),
875+
FailedWithMessage("Stream Error: An unspecified error has occurred. "
876+
"Invalid Root Signature Version"));
873877
}
874878
{
875879
// Flag has been set to an invalid value
@@ -881,7 +885,9 @@ TEST(RootSignature, ParseRootFlags) {
881885
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
882886
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xFF,
883887
};
884-
EXPECT_THAT_EXPECTED(DXContainer::create(getMemoryBuffer<68>(Buffer)),
885-
FailedWithMessage("Invalid flag"));
888+
EXPECT_THAT_EXPECTED(
889+
DXContainer::create(getMemoryBuffer<68>(Buffer)),
890+
FailedWithMessage("Stream Error: An unspecified error has occurred. "
891+
"Invalid Root Signature flag"));
886892
}
887893
}

0 commit comments

Comments
 (0)