From 4c5ab90452d0a6bb93cf645a1a79dbfce53c6ee1 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Tue, 12 Jan 2021 08:50:31 +0000 Subject: [PATCH] ShaderModule: Refactor ParseWGSL() to take a File* The tint::ast::Module holds a diagnostic list (tint::diag::List) which references the source tint::Source::File. If you try to enable any of the more pretty diagnostic printing functionality, and attempt to print these after ParseWGSL() has returned, you'll then dereference a pointer to the now stack unwound `tint::Source::File`. Promote the file up one callstack level to fix this. Bug: none. Only exposed when using pretty printing. Change-Id: I9432dd9d668fd1d92efa228bb5ed31278fd3ddfc Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/37280 Reviewed-by: Corentin Wallez Reviewed-by: Austin Eng Commit-Queue: Corentin Wallez Auto-Submit: Ben Clayton --- src/dawn_native/ShaderModule.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/dawn_native/ShaderModule.cpp b/src/dawn_native/ShaderModule.cpp index 909ecbb737..3e1f3d90d6 100644 --- a/src/dawn_native/ShaderModule.cpp +++ b/src/dawn_native/ShaderModule.cpp @@ -173,12 +173,11 @@ namespace dawn_native { } #ifdef DAWN_ENABLE_WGSL - ResultOrError ParseWGSL(const char* wgsl) { + ResultOrError ParseWGSL(const tint::Source::File* file) { std::ostringstream errorStream; errorStream << "Tint WGSL reader failure:" << std::endl; - tint::Source::File file("", wgsl); - tint::reader::wgsl::Parser parser(&file); + tint::reader::wgsl::Parser parser(file); if (!parser.Parse()) { errorStream << "Parser: " << parser.error() << std::endl; return DAWN_VALIDATION_ERROR(errorStream.str().c_str()); @@ -827,16 +826,18 @@ namespace dawn_native { const auto* wgslDesc = static_cast(chainedDescriptor); + tint::Source::File file("", wgslDesc->source); + if (device->IsToggleEnabled(Toggle::UseTintGenerator)) { tint::ast::Module module; - DAWN_TRY_ASSIGN(module, ParseWGSL(wgslDesc->source)); + DAWN_TRY_ASSIGN(module, ParseWGSL(&file)); if (device->IsValidationEnabled()) { DAWN_TRY(ValidateModule(&module)); } parseResult.tintModule = std::make_unique(std::move(module)); } else { tint::ast::Module module; - DAWN_TRY_ASSIGN(module, ParseWGSL(wgslDesc->source)); + DAWN_TRY_ASSIGN(module, ParseWGSL(&file)); { tint::transform::Manager transformManager;