[clang] Rework the printing of attributes (PR #87281)
giulianobelinassi wrote: I am not sure how I feel about dropping the canPrintOnRight/printOnRight logic. We use it as a fallback when the SourceRange of a function is unreliable, otherwise we always copy and paste the code the user wrote. Regardless of that I will check for fallbacks on clang-extract once I get it to link with this branch. https://github.com/llvm/llvm-project/pull/87281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Rework the printing of attributes (PR #87281)
giulianobelinassi wrote: > > > > > @erichkeane, thank you. What's the process of including this in the > > > > > next release? > > > > > > > > > > > > After CI is complete, you can click "Squash and Merge" below (if you > > > > cannot, let us know and someone can do it for you), and it'll be > > > > included in the 19.1 release this summer. > > > > > > > > > I have commit access. I want this to be part of the 18.x releases as that > > > breaks our downstream clients. > > > > > > Ah, hmm... I am not sure this qualifies for inclusion in the current > > release branch. Perhaps @AaronBallman can comment here. > > I'm not particularly comfortable putting this into 18.x; we should only be > pushing very safe fixes to regressions and this one doesn't really qualify. > It's debatable whether it's a regression (it sort of is, sort of isn't), but > the changes are also relatively involved. I'd feel more comfortable with this > in 19.x so we have more time to find and fix remaining edge cases. How about this single-line fix? It would fix the override regression for now. ``` diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 80e607525a0a..a39288464040 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -2511,6 +2511,7 @@ def Overloadable : Attr { } def Override : InheritableAttr { + let CanPrintOnLeft = 0; let Spellings = [CustomKeyword<"override">]; let SemaHandler = 0; // Omitted from docs, since this is language syntax, not an attribute, as far ``` https://github.com/llvm/llvm-project/pull/87281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Rework the printing of attributes (PR #87281)
giulianobelinassi wrote: We would like this fixed in 18.1 as well. We are expanding to support C++ and we will hit this bug at some point. https://github.com/llvm/llvm-project/pull/87281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Rework the printing of attributes (PR #87281)
giulianobelinassi wrote: > Maybe you can open a PR against the branch? Sorry, but I can only do this tomorrow. Feel free to open the PR if you need it immediately. > And `final` as well as `override`? (This is why I'm not convinced we should > be backporting anything -- the problem is with printing in general and will > crop up in various places, so we're not really fixing a regression so much as > playing whack-a-mole with a few cases.) Why not? `override` and perhaps `final` output is broken so I'd say we fix this on LLVM-18. It is better than leave it broken. I don't think this will break many test cases once this bug got undetected. https://github.com/llvm/llvm-project/pull/87281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Fix the behavior of __COUNT__ macros when PCH is enabled (PR #105591)
https://github.com/giulianobelinassi created https://github.com/llvm/llvm-project/pull/105591 Previoulsy, calling `ASTUnit::LoadFromCompilerInvocation` with `PrecompilePreambleAfterNParses > 0` caused the `__COUNT__` macro value to be restarted. This commit fixes this by remembering the value of this macro when the PCH finished parsing. >From 259653e147aff62c70dd2c16d46886ae2c92412d Mon Sep 17 00:00:00 2001 From: Giuliano Belinassi Date: Wed, 21 Aug 2024 18:31:36 -0300 Subject: [PATCH] Fix the behavior of __COUNT__ macros when PCH is enabled Previoulsy, calling `ASTUnit::LoadFromCompilerInvocation` with `PrecompilePreambleAfterNParses > 0` caused the `__COUNT__` macro value to be restarted. This commit fixes this by remembering the value of this macro when the PCH finished parsing. Signed-off-by: Giuliano Belinassi --- clang/include/clang/Frontend/ASTUnit.h| 8 ++- clang/include/clang/Frontend/FrontendAction.h | 3 + .../clang/Frontend/PrecompiledPreamble.h | 10 +++- clang/lib/Frontend/ASTUnit.cpp| 40 ++--- clang/lib/Frontend/FrontendAction.cpp | 2 +- clang/lib/Frontend/PrecompiledPreamble.cpp| 9 ++- clang/unittests/Frontend/ASTUnitTest.cpp | 60 +++ 7 files changed, 115 insertions(+), 17 deletions(-) diff --git a/clang/include/clang/Frontend/ASTUnit.h b/clang/include/clang/Frontend/ASTUnit.h index 080844893c13c9..40aada6405b453 100644 --- a/clang/include/clang/Frontend/ASTUnit.h +++ b/clang/include/clang/Frontend/ASTUnit.h @@ -372,13 +372,15 @@ class ASTUnit { bool Parse(std::shared_ptr PCHContainerOps, std::unique_ptr OverrideMainBuffer, - IntrusiveRefCntPtr VFS); + IntrusiveRefCntPtr VFS, + unsigned PCHCountValue = 0); std::unique_ptr getMainBufferWithPrecompiledPreamble( std::shared_ptr PCHContainerOps, CompilerInvocation &PreambleInvocationIn, - IntrusiveRefCntPtr VFS, bool AllowRebuild = true, - unsigned MaxLines = 0); + IntrusiveRefCntPtr VFS, + unsigned *CountValueAtFinish = nullptr, + bool AllowRebuild = true, unsigned MaxLines = 0); void RealizeTopLevelDeclsFromPreamble(); /// Transfers ownership of the objects (like SourceManager) from diff --git a/clang/include/clang/Frontend/FrontendAction.h b/clang/include/clang/Frontend/FrontendAction.h index 039f6f247b6d8c..b8112cb7e21469 100644 --- a/clang/include/clang/Frontend/FrontendAction.h +++ b/clang/include/clang/Frontend/FrontendAction.h @@ -178,6 +178,9 @@ class FrontendAction { /// details. virtual bool isModelParsingAction() const { return false; } + /// Do we need to reuse existing preprocessor? + virtual bool reuseExistingPreprocessor() const { return false; } + /// Does this action only use the preprocessor? /// /// If so no AST context will be created and this action will be invalid diff --git a/clang/include/clang/Frontend/PrecompiledPreamble.h b/clang/include/clang/Frontend/PrecompiledPreamble.h index 624df004bf89e4..ce376c990e2392 100644 --- a/clang/include/clang/Frontend/PrecompiledPreamble.h +++ b/clang/include/clang/Frontend/PrecompiledPreamble.h @@ -102,6 +102,11 @@ class PrecompiledPreamble { /// be used for logging and debugging purposes only. std::size_t getSize() const; + /// Returns the value of __COUNT__ macro when the process finished. + unsigned getCountValue() const { +return CountValueAtFinish; + } + /// Returned string is not null-terminated. llvm::StringRef getContents() const { return {PreambleBytes.data(), PreambleBytes.size()}; @@ -137,7 +142,8 @@ class PrecompiledPreamble { std::vector PreambleBytes, bool PreambleEndsAtStartOfLine, llvm::StringMap FilesInPreamble, - llvm::StringSet<> MissingFiles); + llvm::StringSet<> MissingFiles, + unsigned CountPreamble); /// Data used to determine if a file used in the preamble has been changed. struct PreambleFileHash { @@ -205,6 +211,8 @@ class PrecompiledPreamble { std::vector PreambleBytes; /// See PreambleBounds::PreambleEndsAtStartOfLine bool PreambleEndsAtStartOfLine; + /// __COUNT__ macro value when the preamble finished building. + unsigned CountValueAtFinish; }; /// A set of callbacks to gather useful information while building a preamble. diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index 84e273a3949ef0..0ccd811ee40d11 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -1046,6 +1046,7 @@ class TopLevelDeclTrackerConsumer : public ASTConsumer { class TopLevelDeclTrackerAction : public ASTFrontendAction { public: ASTUnit &Unit; + bool ReusePreprocessor; std::unique_ptr CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override { @@ -1056,11 +105
[clang] Fix the behavior of __COUNT__ macros when PCH is enabled (PR #105591)
https://github.com/giulianobelinassi updated https://github.com/llvm/llvm-project/pull/105591 >From 914427af9b83848ac395bbff663133aadf387161 Mon Sep 17 00:00:00 2001 From: Giuliano Belinassi Date: Wed, 21 Aug 2024 18:31:36 -0300 Subject: [PATCH] Fix the behavior of __COUNT__ macros when PCH is enabled Previoulsy, calling `ASTUnit::LoadFromCompilerInvocation` with `PrecompilePreambleAfterNParses > 0` caused the `__COUNT__` macro value to be restarted. This commit fixes this by remembering the value of this macro when the PCH finished parsing. Signed-off-by: Giuliano Belinassi --- clang/include/clang/Frontend/ASTUnit.h| 6 +- clang/include/clang/Frontend/FrontendAction.h | 3 + .../clang/Frontend/PrecompiledPreamble.h | 7 ++- clang/lib/Frontend/ASTUnit.cpp| 39 clang/lib/Frontend/FrontendAction.cpp | 3 +- clang/lib/Frontend/PrecompiledPreamble.cpp| 8 ++- clang/unittests/Frontend/ASTUnitTest.cpp | 60 +++ 7 files changed, 109 insertions(+), 17 deletions(-) diff --git a/clang/include/clang/Frontend/ASTUnit.h b/clang/include/clang/Frontend/ASTUnit.h index 080844893c13c9..2762abedaa2927 100644 --- a/clang/include/clang/Frontend/ASTUnit.h +++ b/clang/include/clang/Frontend/ASTUnit.h @@ -372,12 +372,14 @@ class ASTUnit { bool Parse(std::shared_ptr PCHContainerOps, std::unique_ptr OverrideMainBuffer, - IntrusiveRefCntPtr VFS); + IntrusiveRefCntPtr VFS, + unsigned PCHCountValue = 0); std::unique_ptr getMainBufferWithPrecompiledPreamble( std::shared_ptr PCHContainerOps, CompilerInvocation &PreambleInvocationIn, - IntrusiveRefCntPtr VFS, bool AllowRebuild = true, + IntrusiveRefCntPtr VFS, + unsigned *CountValueAtFinish = nullptr, bool AllowRebuild = true, unsigned MaxLines = 0); void RealizeTopLevelDeclsFromPreamble(); diff --git a/clang/include/clang/Frontend/FrontendAction.h b/clang/include/clang/Frontend/FrontendAction.h index 039f6f247b6d8c..b8112cb7e21469 100644 --- a/clang/include/clang/Frontend/FrontendAction.h +++ b/clang/include/clang/Frontend/FrontendAction.h @@ -178,6 +178,9 @@ class FrontendAction { /// details. virtual bool isModelParsingAction() const { return false; } + /// Do we need to reuse existing preprocessor? + virtual bool reuseExistingPreprocessor() const { return false; } + /// Does this action only use the preprocessor? /// /// If so no AST context will be created and this action will be invalid diff --git a/clang/include/clang/Frontend/PrecompiledPreamble.h b/clang/include/clang/Frontend/PrecompiledPreamble.h index 624df004bf89e4..ef3302b82a30b0 100644 --- a/clang/include/clang/Frontend/PrecompiledPreamble.h +++ b/clang/include/clang/Frontend/PrecompiledPreamble.h @@ -102,6 +102,9 @@ class PrecompiledPreamble { /// be used for logging and debugging purposes only. std::size_t getSize() const; + /// Returns the value of __COUNT__ macro when the process finished. + unsigned getCountValue() const { return CountValueAtFinish; } + /// Returned string is not null-terminated. llvm::StringRef getContents() const { return {PreambleBytes.data(), PreambleBytes.size()}; @@ -137,7 +140,7 @@ class PrecompiledPreamble { std::vector PreambleBytes, bool PreambleEndsAtStartOfLine, llvm::StringMap FilesInPreamble, - llvm::StringSet<> MissingFiles); + llvm::StringSet<> MissingFiles, unsigned CountPreamble); /// Data used to determine if a file used in the preamble has been changed. struct PreambleFileHash { @@ -205,6 +208,8 @@ class PrecompiledPreamble { std::vector PreambleBytes; /// See PreambleBounds::PreambleEndsAtStartOfLine bool PreambleEndsAtStartOfLine; + /// __COUNT__ macro value when the preamble finished building. + unsigned CountValueAtFinish; }; /// A set of callbacks to gather useful information while building a preamble. diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index 84e273a3949ef0..bd6e4f902fc38e 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -1046,6 +1046,7 @@ class TopLevelDeclTrackerConsumer : public ASTConsumer { class TopLevelDeclTrackerAction : public ASTFrontendAction { public: ASTUnit &Unit; + bool ReusePreprocessor; std::unique_ptr CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override { @@ -1056,11 +1057,13 @@ class TopLevelDeclTrackerAction : public ASTFrontendAction { Unit, Unit.getCurrentTopLevelHashValue()); } -public: - TopLevelDeclTrackerAction(ASTUnit &_Unit) : Unit(_Unit) {} + TopLevelDeclTrackerAction(ASTUnit &_Unit, bool _ReusePreprocessor = false) +: Unit(_Unit), ReusePreprocessor(_ReusePreprocessor) {} bool hasCodeCompletionSupport() const ov
[clang] Fix the behavior of __COUNT__ macros when PCH is enabled (PR #105591)
https://github.com/giulianobelinassi updated https://github.com/llvm/llvm-project/pull/105591 >From 3a1a241f925e7b6dcc6c8701ab83b5fb04f18853 Mon Sep 17 00:00:00 2001 From: Giuliano Belinassi Date: Wed, 21 Aug 2024 18:31:36 -0300 Subject: [PATCH] Fix the behavior of __COUNT__ macros when PCH is enabled Previoulsy, calling `ASTUnit::LoadFromCompilerInvocation` with `PrecompilePreambleAfterNParses > 0` caused the `__COUNT__` macro value to be restarted. This commit fixes this by remembering the value of this macro when the PCH finished parsing. Signed-off-by: Giuliano Belinassi --- clang/include/clang/Frontend/ASTUnit.h| 6 +- clang/include/clang/Frontend/FrontendAction.h | 3 + .../clang/Frontend/PrecompiledPreamble.h | 7 ++- clang/lib/Frontend/ASTUnit.cpp| 39 clang/lib/Frontend/FrontendAction.cpp | 3 +- clang/lib/Frontend/PrecompiledPreamble.cpp| 8 ++- clang/unittests/Frontend/ASTUnitTest.cpp | 60 +++ 7 files changed, 109 insertions(+), 17 deletions(-) diff --git a/clang/include/clang/Frontend/ASTUnit.h b/clang/include/clang/Frontend/ASTUnit.h index 080844893c13c9..2762abedaa2927 100644 --- a/clang/include/clang/Frontend/ASTUnit.h +++ b/clang/include/clang/Frontend/ASTUnit.h @@ -372,12 +372,14 @@ class ASTUnit { bool Parse(std::shared_ptr PCHContainerOps, std::unique_ptr OverrideMainBuffer, - IntrusiveRefCntPtr VFS); + IntrusiveRefCntPtr VFS, + unsigned PCHCountValue = 0); std::unique_ptr getMainBufferWithPrecompiledPreamble( std::shared_ptr PCHContainerOps, CompilerInvocation &PreambleInvocationIn, - IntrusiveRefCntPtr VFS, bool AllowRebuild = true, + IntrusiveRefCntPtr VFS, + unsigned *CountValueAtFinish = nullptr, bool AllowRebuild = true, unsigned MaxLines = 0); void RealizeTopLevelDeclsFromPreamble(); diff --git a/clang/include/clang/Frontend/FrontendAction.h b/clang/include/clang/Frontend/FrontendAction.h index 039f6f247b6d8c..b8112cb7e21469 100644 --- a/clang/include/clang/Frontend/FrontendAction.h +++ b/clang/include/clang/Frontend/FrontendAction.h @@ -178,6 +178,9 @@ class FrontendAction { /// details. virtual bool isModelParsingAction() const { return false; } + /// Do we need to reuse existing preprocessor? + virtual bool reuseExistingPreprocessor() const { return false; } + /// Does this action only use the preprocessor? /// /// If so no AST context will be created and this action will be invalid diff --git a/clang/include/clang/Frontend/PrecompiledPreamble.h b/clang/include/clang/Frontend/PrecompiledPreamble.h index 624df004bf89e4..ef3302b82a30b0 100644 --- a/clang/include/clang/Frontend/PrecompiledPreamble.h +++ b/clang/include/clang/Frontend/PrecompiledPreamble.h @@ -102,6 +102,9 @@ class PrecompiledPreamble { /// be used for logging and debugging purposes only. std::size_t getSize() const; + /// Returns the value of __COUNT__ macro when the process finished. + unsigned getCountValue() const { return CountValueAtFinish; } + /// Returned string is not null-terminated. llvm::StringRef getContents() const { return {PreambleBytes.data(), PreambleBytes.size()}; @@ -137,7 +140,7 @@ class PrecompiledPreamble { std::vector PreambleBytes, bool PreambleEndsAtStartOfLine, llvm::StringMap FilesInPreamble, - llvm::StringSet<> MissingFiles); + llvm::StringSet<> MissingFiles, unsigned CountPreamble); /// Data used to determine if a file used in the preamble has been changed. struct PreambleFileHash { @@ -205,6 +208,8 @@ class PrecompiledPreamble { std::vector PreambleBytes; /// See PreambleBounds::PreambleEndsAtStartOfLine bool PreambleEndsAtStartOfLine; + /// __COUNT__ macro value when the preamble finished building. + unsigned CountValueAtFinish; }; /// A set of callbacks to gather useful information while building a preamble. diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index 84e273a3949ef0..ccc638d43070ac 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -1046,6 +1046,7 @@ class TopLevelDeclTrackerConsumer : public ASTConsumer { class TopLevelDeclTrackerAction : public ASTFrontendAction { public: ASTUnit &Unit; + bool ReusePreprocessor; std::unique_ptr CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override { @@ -1056,11 +1057,13 @@ class TopLevelDeclTrackerAction : public ASTFrontendAction { Unit, Unit.getCurrentTopLevelHashValue()); } -public: - TopLevelDeclTrackerAction(ASTUnit &_Unit) : Unit(_Unit) {} + TopLevelDeclTrackerAction(ASTUnit &_Unit, bool _ReusePreprocessor = false) + : Unit(_Unit), ReusePreprocessor(_ReusePreprocessor) {} bool hasCodeCompletionSupport() const
[clang] Fix the behavior of __COUNT__ macros when PCH is enabled (PR #105591)
@@ -1243,12 +1247,19 @@ bool ASTUnit::Parse(std::shared_ptr PCHContainerOps, } std::unique_ptr Act( - new TopLevelDeclTrackerAction(*this)); + new TopLevelDeclTrackerAction(*this, true)); giulianobelinassi wrote: The problem is that when you are using PCH it always recreate the preprocessor for compiling the .c/.cpp file instead of reusing the one that resulted from the PCH. So we need a way to ensure that it isn't recreated in this process. https://github.com/llvm/llvm-project/pull/105591 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits