Skip to content

Commit 6986945

Browse files
author
joaosaffran
committed
adding more tests and addressing comments
1 parent 7343d95 commit 6986945

File tree

5 files changed

+38
-28
lines changed

5 files changed

+38
-28
lines changed

llvm/include/llvm/BinaryFormat/DXContainer.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,12 @@ ArrayRef<EnumEntry<RootParameterType>> getRootParameterTypes();
167167

168168
#define ROOT_PARAMETER(Val, Enum) \
169169
case Val: \
170-
return dxbc::RootParameterType::Enum;
171-
inline llvm::Expected<dxbc::RootParameterType>
172-
safeParseParameterType(uint32_t V) {
170+
return true;
171+
inline bool isValidParameterType(uint32_t V) {
173172
switch (V) {
174173
#include "DXContainerConstants.def"
175174
}
176-
return createStringError(std::errc::invalid_argument,
177-
"Invalid value for parameter type");
175+
return false;
178176
}
179177

180178
#define SHADER_VISIBILITY(Val, Enum) Enum = Val,
@@ -186,14 +184,12 @@ ArrayRef<EnumEntry<ShaderVisibility>> getShaderVisibility();
186184

187185
#define SHADER_VISIBILITY(Val, Enum) \
188186
case Val: \
189-
return dxbc::ShaderVisibility::Enum;
190-
inline llvm::Expected<dxbc::ShaderVisibility>
191-
safeParseShaderVisibility(uint32_t V) {
187+
return true;
188+
inline bool isValidShaderVisibility(uint32_t V) {
192189
switch (V) {
193190
#include "DXContainerConstants.def"
194191
}
195-
return createStringError(std::errc::invalid_argument,
196-
"Invalid value for parameter type");
192+
return false;
197193
}
198194

199195
PartType parsePartType(StringRef S);

llvm/include/llvm/ObjectYAML/DXContainerYAML.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ struct RootParameterYamlDesc {
9292
};
9393

9494
struct RootSignatureYamlDesc {
95+
RootSignatureYamlDesc() = default;
96+
9597
uint32_t Version;
9698
uint32_t NumStaticSamplers;
9799
uint32_t StaticSamplersOffset;
@@ -108,8 +110,6 @@ struct RootSignatureYamlDesc {
108110
create(const object::DirectX::RootSignature &Data);
109111

110112
#include "llvm/BinaryFormat/DXContainerConstants.def"
111-
112-
RootSignatureYamlDesc() = default;
113113
};
114114

115115
using ResourceFlags = dxbc::PSV::ResourceFlags;

llvm/lib/ObjectYAML/DXContainerYAML.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "llvm/BinaryFormat/DXContainer.h"
1717
#include "llvm/Support/Error.h"
1818
#include "llvm/Support/ScopedPrinter.h"
19-
#include <utility>
19+
#include <system_error>
2020

2121
namespace llvm {
2222

@@ -47,20 +47,17 @@ DXContainerYAML::RootSignatureYamlDesc::create(
4747
RootParameterYamlDesc NewP;
4848
NewP.Offset = PH.ParameterOffset;
4949

50-
llvm::Expected<dxbc::RootParameterType> TypeOrErr =
51-
dxbc::safeParseParameterType(PH.ParameterType);
52-
if (Error E = TypeOrErr.takeError()) {
53-
return std::move(E);
54-
}
50+
if (!dxbc::isValidParameterType(PH.ParameterType))
51+
return createStringError(std::errc::invalid_argument,
52+
"Invalid value for parameter type");
5553

56-
NewP.Type = TypeOrErr.get();
54+
NewP.Type = (dxbc::RootParameterType)PH.ParameterType;
5755

58-
llvm::Expected<dxbc::ShaderVisibility> VisibilityOrErr =
59-
dxbc::safeParseShaderVisibility(PH.ShaderVisibility);
60-
if (Error E = VisibilityOrErr.takeError()) {
61-
return std::move(E);
62-
}
63-
NewP.Visibility = VisibilityOrErr.get();
56+
if (!dxbc::isValidShaderVisibility(PH.ShaderVisibility))
57+
return createStringError(std::errc::invalid_argument,
58+
"Invalid value for shader visibility");
59+
60+
NewP.Visibility = (dxbc::ShaderVisibility)PH.ShaderVisibility;
6461

6562
llvm::Expected<object::DirectX::RootParameterView> ParamViewOrErr =
6663
Data.getParameter(PH);

llvm/unittests/Object/DXContainerTest.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88

99
#include "llvm/Object/DXContainer.h"
1010
#include "../../tools/obj2yaml/dxcontainer2yaml.cpp"
11-
#include "llvm/ADT/SmallString.h"
1211
#include "llvm/ADT/StringRef.h"
1312
#include "llvm/BinaryFormat/Magic.h"
1413
#include "llvm/ObjectYAML/DXContainerYAML.h"
1514
#include "llvm/ObjectYAML/yaml2obj.h"
1615
#include "llvm/Support/MemoryBufferRef.h"
1716
#include "llvm/Testing/Support/Error.h"
18-
#include "gmock/gmock.h"
1917
#include "gtest/gtest.h"
2018

2119
using namespace llvm;
@@ -930,4 +928,24 @@ TEST(RootSignature, ParseRootConstant) {
930928
EXPECT_THAT_ERROR(dxcontainer2yaml(OS, getMemoryBuffer<133>(Buffer)),
931929
FailedWithMessage("Invalid value for parameter type"));
932930
}
931+
{
932+
uint8_t Buffer[] = {
933+
0x44, 0x58, 0x42, 0x43, 0x32, 0x9a, 0x53, 0xd8, 0xec, 0xbe, 0x35, 0x6f,
934+
0x05, 0x39, 0xe1, 0xfe, 0x31, 0x20, 0xf0, 0xc1, 0x01, 0x00, 0x00, 0x00,
935+
0x85, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
936+
0x52, 0x54, 0x53, 0x30, 0x59, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
937+
0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
938+
0x2c, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
939+
0xFF, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00,
940+
0x0e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
941+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
942+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
943+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
944+
0x00};
945+
946+
SmallString<256> Storage;
947+
raw_svector_ostream OS(Storage);
948+
EXPECT_THAT_ERROR(dxcontainer2yaml(OS, getMemoryBuffer<133>(Buffer)),
949+
FailedWithMessage("Invalid value for shader visibility"));
950+
}
933951
}

llvm/unittests/ObjectYAML/DXContainerYAMLTest.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "llvm/ADT/SmallString.h"
109
#include "llvm/ADT/StringRef.h"
1110
#include "llvm/ADT/Twine.h"
1211
#include "llvm/ObjectYAML/ObjectYAML.h"

0 commit comments

Comments
 (0)