From c7ca7668cc1f65ef664945eb0f6fda309b1b00f5 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Wed, 17 Feb 2021 16:23:52 +0000 Subject: [PATCH] Fix TypesBuilder::builder pointer initialization When copying or moving a ProgramBuilder, we always want the ProgramBuilder::ty to point back to the owner. We were previously std::move()'ing the ty field, which is not correct - this will result in the TypesBuilder pointing to the wrong ProgramBuilder. I'm not sure why we've not seen any issues with this using clang, but running under MSVC immediately highlighted this brokenness. Change-Id: I4293bb00ac4fbdfa66d12b1504a7bd060e014cd6 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41861 Commit-Queue: Ben Clayton Auto-Submit: Ben Clayton Reviewed-by: dan sinclair --- src/program_builder.cc | 6 ++---- src/program_builder.h | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/program_builder.cc b/src/program_builder.cc index 11b960d5b7..bee3f299bb 100644 --- a/src/program_builder.cc +++ b/src/program_builder.cc @@ -28,11 +28,10 @@ namespace tint { ProgramBuilder::ProgramBuilder() - : ty(this), ast_(ast_nodes_.Create(Source{})) {} + : ast_(ast_nodes_.Create(Source{})) {} ProgramBuilder::ProgramBuilder(ProgramBuilder&& rhs) - : ty(std::move(rhs.ty)), - types_(std::move(rhs.types_)), + : types_(std::move(rhs.types_)), ast_nodes_(std::move(rhs.ast_nodes_)), sem_nodes_(std::move(rhs.sem_nodes_)), ast_(rhs.ast_), @@ -46,7 +45,6 @@ ProgramBuilder::~ProgramBuilder() = default; ProgramBuilder& ProgramBuilder::operator=(ProgramBuilder&& rhs) { rhs.MarkAsMoved(); AssertNotMoved(); - ty = std::move(rhs.ty); types_ = std::move(rhs.types_); ast_nodes_ = std::move(rhs.ast_nodes_); sem_nodes_ = std::move(rhs.sem_nodes_); diff --git a/src/program_builder.h b/src/program_builder.h index f0ecfb3471..24a018640a 100644 --- a/src/program_builder.h +++ b/src/program_builder.h @@ -477,7 +477,7 @@ class ProgramBuilder { template struct CToAST {}; - ProgramBuilder* builder; + ProgramBuilder* const builder; }; ////////////////////////////////////////////////////////////////////////////// @@ -1101,7 +1101,7 @@ class ProgramBuilder { void WrapInFunction(ast::StatementList stmts); /// The builder types - TypesBuilder ty; + TypesBuilder const ty{this}; protected: /// Asserts that the builder has not been moved.