From b69dcb873476cd8e7d3f6f9ffd5b6d0bbe1a3a17 Mon Sep 17 00:00:00 2001 From: Jan Svoboda Date: Thu, 1 May 2025 07:31:30 -0700 Subject: [clang][frontend] Require invocation to construct `CompilerInstance` (#137668) This PR makes it so that `CompilerInvocation` needs to be provided to `CompilerInstance` on construction. There are a couple of benefits in my view: * Making it impossible to mis-use some `CompilerInstance` APIs. For example there are cases, where `createDiagnostics()` was called before `setInvocation()`, causing the `DiagnosticEngine` to use the default-constructed `DiagnosticOptions` instead of the intended ones. * This shrinks `CompilerInstance`'s state space. * This makes it possible to access **the** invocation in `CompilerInstance`'s constructor (to be used in a follow-up). --- clang/unittests/Frontend/CompilerInstanceTest.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'clang/unittests/Frontend/CompilerInstanceTest.cpp') diff --git a/clang/unittests/Frontend/CompilerInstanceTest.cpp b/clang/unittests/Frontend/CompilerInstanceTest.cpp index 07329eb2..6e9a6f5 100644 --- a/clang/unittests/Frontend/CompilerInstanceTest.cpp +++ b/clang/unittests/Frontend/CompilerInstanceTest.cpp @@ -66,9 +66,8 @@ TEST(CompilerInstance, DefaultVFSOverlayFromInvocation) { FAIL() << "could not create compiler invocation"; // Create a minimal CompilerInstance which should use the VFS we specified // in the CompilerInvocation (as we don't explicitly set our own). - CompilerInstance Instance; + CompilerInstance Instance(std::move(CInvok)); Instance.setDiagnostics(Diags.get()); - Instance.setInvocation(CInvok); Instance.createFileManager(); // Check if the virtual file exists which means that our VFS is used by the -- cgit v1.1