mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-08-10 22:19:09 +00:00
The reason being that some tests called parse() twice, which will silently destruct the first parser. Once the `Module` owns the AST nodes, the second call will end up deleting all the AST nodes. Tests would then perform use-after-free for the AST nodes belonging to the first parser / module. There's no reason why the unique_ptr can't be returned, which is cleaner overall. Bug: tint:335 Change-Id: I7ff2e9777a7ebeb76702f806294fe4c2c49bd7c9 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/33241 Auto-Submit: Ben Clayton <bclayton@google.com> Reviewed-by: dan sinclair <dsinclair@chromium.org> Commit-Queue: dan sinclair <dsinclair@chromium.org>
79 lines
2.5 KiB
C++
79 lines
2.5 KiB
C++
// Copyright 2020 The Tint Authors.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
#include "gtest/gtest.h"
|
|
#include "src/ast/storage_class.h"
|
|
#include "src/reader/wgsl/parser_impl.h"
|
|
#include "src/reader/wgsl/parser_impl_test_helper.h"
|
|
|
|
namespace tint {
|
|
namespace reader {
|
|
namespace wgsl {
|
|
namespace {
|
|
|
|
struct StorageClassData {
|
|
const char* input;
|
|
ast::StorageClass result;
|
|
};
|
|
inline std::ostream& operator<<(std::ostream& out, StorageClassData data) {
|
|
out << std::string(data.input);
|
|
return out;
|
|
}
|
|
|
|
class StorageClassTest : public ParserImplTestWithParam<StorageClassData> {};
|
|
|
|
TEST_P(StorageClassTest, Parses) {
|
|
auto params = GetParam();
|
|
auto p = parser(params.input);
|
|
|
|
auto sc = p->expect_storage_class("test");
|
|
EXPECT_FALSE(sc.errored);
|
|
EXPECT_FALSE(p->has_error());
|
|
EXPECT_EQ(sc.value, params.result);
|
|
|
|
auto t = p->next();
|
|
EXPECT_TRUE(t.IsEof());
|
|
}
|
|
INSTANTIATE_TEST_SUITE_P(
|
|
ParserImplTest,
|
|
StorageClassTest,
|
|
testing::Values(
|
|
StorageClassData{"in", ast::StorageClass::kInput},
|
|
StorageClassData{"out", ast::StorageClass::kOutput},
|
|
StorageClassData{"uniform", ast::StorageClass::kUniform},
|
|
StorageClassData{"workgroup", ast::StorageClass::kWorkgroup},
|
|
StorageClassData{"uniform_constant",
|
|
ast::StorageClass::kUniformConstant},
|
|
StorageClassData{"storage_buffer", ast::StorageClass::kStorageBuffer},
|
|
StorageClassData{"image", ast::StorageClass::kImage},
|
|
StorageClassData{"private", ast::StorageClass::kPrivate},
|
|
StorageClassData{"function", ast::StorageClass::kFunction}));
|
|
|
|
TEST_F(ParserImplTest, StorageClass_NoMatch) {
|
|
auto p = parser("not-a-storage-class");
|
|
auto sc = p->expect_storage_class("test");
|
|
EXPECT_EQ(sc.errored, true);
|
|
EXPECT_TRUE(p->has_error());
|
|
EXPECT_EQ(p->error(), "1:1: invalid storage class for test");
|
|
|
|
auto t = p->next();
|
|
EXPECT_TRUE(t.IsIdentifier());
|
|
EXPECT_EQ(t.to_str(), "not");
|
|
}
|
|
|
|
} // namespace
|
|
} // namespace wgsl
|
|
} // namespace reader
|
|
} // namespace tint
|