From 100a27bb1c8ecaaedb0589464db5e09f73eddcbe Mon Sep 17 00:00:00 2001 From: Alessandro Di Federico Date: Thu, 3 Aug 2023 14:52:44 +0200 Subject: [PATCH] HeaderToModel: emit forward declaration later We used to emit the forward declaration for the type we were editing *before* `#pragma once`. This was not good per se, but it also lead to failures due to the introduction of `_PACKED`, which is not yet defined at that stage. --- lib/ImportModelFromC/ImportModelFromCAnalysis.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/ImportModelFromC/ImportModelFromCAnalysis.cpp b/lib/ImportModelFromC/ImportModelFromCAnalysis.cpp index 55bb592c4..0aaab95d6 100644 --- a/lib/ImportModelFromC/ImportModelFromCAnalysis.cpp +++ b/lib/ImportModelFromC/ImportModelFromCAnalysis.cpp @@ -154,12 +154,13 @@ struct ImportModelFromCAnalysis { if (not isa(*TypeToEdit) and not isa(*TypeToEdit) and not isa(*TypeToEdit)) { + llvm::raw_string_ostream Stream(Options.PostIncludes); ptml::PTMLCBuilder ThePTMLCBuilder(true); - ptml::PTMLIndentedOstream ThePTMLStream(Header, 4, true); - Header << ThePTMLCBuilder.getLineComment("The type we are editing."); + ptml::PTMLIndentedOstream ThePTMLStream(Stream, 4, true); + Stream << ThePTMLCBuilder.getLineComment("The type we are editing"); // The definition of this type will be at the end of the file. printForwardDeclaration(**TypeToEdit, ThePTMLStream, ThePTMLCBuilder); - Header << '\n'; + Stream << '\n'; } // Find all types whose definition depends on the type we are editing.