[clang] Fix the behavior of __COUNT__ macros when PCH is enabled (PR #105591)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 21 15:18:35 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff ab86fc74c04ff508f909b7b6131df1551dd833fc 259653e147aff62c70dd2c16d46886ae2c92412d --extensions h,cpp -- clang/include/clang/Frontend/ASTUnit.h clang/include/clang/Frontend/FrontendAction.h clang/include/clang/Frontend/PrecompiledPreamble.h clang/lib/Frontend/ASTUnit.cpp clang/lib/Frontend/FrontendAction.cpp clang/lib/Frontend/PrecompiledPreamble.cpp clang/unittests/Frontend/ASTUnitTest.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/include/clang/Frontend/ASTUnit.h b/clang/include/clang/Frontend/ASTUnit.h
index 40aada6405..2762abedaa 100644
--- a/clang/include/clang/Frontend/ASTUnit.h
+++ b/clang/include/clang/Frontend/ASTUnit.h
@@ -379,8 +379,8 @@ private:
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
CompilerInvocation &PreambleInvocationIn,
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
- unsigned *CountValueAtFinish = nullptr,
- bool AllowRebuild = true, unsigned MaxLines = 0);
+ 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/PrecompiledPreamble.h b/clang/include/clang/Frontend/PrecompiledPreamble.h
index ce376c990e..ef3302b82a 100644
--- a/clang/include/clang/Frontend/PrecompiledPreamble.h
+++ b/clang/include/clang/Frontend/PrecompiledPreamble.h
@@ -103,9 +103,7 @@ public:
std::size_t getSize() const;
/// Returns the value of __COUNT__ macro when the process finished.
- unsigned getCountValue() const {
- return CountValueAtFinish;
- }
+ unsigned getCountValue() const { return CountValueAtFinish; }
/// Returned string is not null-terminated.
llvm::StringRef getContents() const {
@@ -142,8 +140,7 @@ private:
std::vector<char> PreambleBytes,
bool PreambleEndsAtStartOfLine,
llvm::StringMap<PreambleFileHash> FilesInPreamble,
- llvm::StringSet<> MissingFiles,
- unsigned CountPreamble);
+ llvm::StringSet<> MissingFiles, unsigned CountPreamble);
/// Data used to determine if a file used in the preamble has been changed.
struct PreambleFileHash {
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index 0ccd811ee4..ccc638d430 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -1058,8 +1058,7 @@ public:
}
TopLevelDeclTrackerAction(ASTUnit &_Unit, bool _ReusePreprocessor = false)
- : Unit(_Unit),
- ReusePreprocessor(_ReusePreprocessor){}
+ : Unit(_Unit), ReusePreprocessor(_ReusePreprocessor) {}
bool hasCodeCompletionSupport() const override { return false; }
@@ -1255,8 +1254,8 @@ bool ASTUnit::Parse(std::shared_ptr<PCHContainerOperations> PCHContainerOps,
ActCleanup(Act.get());
if (!Clang->hasPreprocessor()) {
- // Create the Preprocessor.
- Clang->createPreprocessor(TUKind);
+ // Create the Preprocessor.
+ Clang->createPreprocessor(TUKind);
}
Clang->getPreprocessor().setCounterValue(PCHCountValue);
@@ -1355,8 +1354,7 @@ std::unique_ptr<llvm::MemoryBuffer>
ASTUnit::getMainBufferWithPrecompiledPreamble(
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
CompilerInvocation &PreambleInvocationIn,
- IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
- unsigned *CountValueAtFinish,
+ IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS, unsigned *CountValueAtFinish,
bool AllowRebuild, unsigned MaxLines) {
auto MainFilePath =
PreambleInvocationIn.getFrontendOpts().Inputs[0].getFile();
@@ -1725,9 +1723,8 @@ bool ASTUnit::LoadFromCompilerInvocation(
std::unique_ptr<llvm::MemoryBuffer> OverrideMainBuffer;
if (PrecompilePreambleAfterNParses > 0) {
PreambleRebuildCountdown = PrecompilePreambleAfterNParses;
- OverrideMainBuffer =
- getMainBufferWithPrecompiledPreamble(PCHContainerOps, *Invocation, VFS,
- &PCHCountValue);
+ OverrideMainBuffer = getMainBufferWithPrecompiledPreamble(
+ PCHContainerOps, *Invocation, VFS, &PCHCountValue);
getDiagnostics().Reset();
ProcessWarningOptions(getDiagnostics(), Invocation->getDiagnosticOpts());
}
diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp
index e6e1d79b90..9e0fe1031e 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -816,7 +816,8 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
// Set up the preprocessor if needed. When parsing model files the
// preprocessor of the original source is reused.
- if (!CI.hasPreprocessor() || (!isModelParsingAction() && !reuseExistingPreprocessor()))
+ if (!CI.hasPreprocessor() ||
+ (!isModelParsingAction() && !reuseExistingPreprocessor()))
CI.createPreprocessor(getTranslationUnitKind());
// Inform the diagnostic client we are processing a source file.
diff --git a/clang/lib/Frontend/PrecompiledPreamble.cpp b/clang/lib/Frontend/PrecompiledPreamble.cpp
index c93a9a016c..c7cd108301 100644
--- a/clang/lib/Frontend/PrecompiledPreamble.cpp
+++ b/clang/lib/Frontend/PrecompiledPreamble.cpp
@@ -729,8 +729,7 @@ PrecompiledPreamble::PrecompiledPreamble(
std::unique_ptr<PCHStorage> Storage, std::vector<char> PreambleBytes,
bool PreambleEndsAtStartOfLine,
llvm::StringMap<PreambleFileHash> FilesInPreamble,
- llvm::StringSet<> MissingFiles,
- unsigned CountValue)
+ llvm::StringSet<> MissingFiles, unsigned CountValue)
: Storage(std::move(Storage)), FilesInPreamble(std::move(FilesInPreamble)),
MissingFiles(std::move(MissingFiles)),
PreambleBytes(std::move(PreambleBytes)),
diff --git a/clang/unittests/Frontend/ASTUnitTest.cpp b/clang/unittests/Frontend/ASTUnitTest.cpp
index 55a6cd9296..e0fabbf0f1 100644
--- a/clang/unittests/Frontend/ASTUnitTest.cpp
+++ b/clang/unittests/Frontend/ASTUnitTest.cpp
@@ -253,7 +253,7 @@ TEST_F(ASTUnitTest, PCHCount) {
ASSERT_TRUE(de.hasErrorOccurred());
/* Make sure we have the two functions. */
- bool functions[2] = { false, false };
+ bool functions[2] = {false, false};
for (auto it = AU->top_level_begin(); it != AU->top_level_end(); ++it) {
if (FunctionDecl *fdecl = dyn_cast<FunctionDecl>(*it)) {
if (fdecl->getName() == "function_0") {
``````````
</details>
https://github.com/llvm/llvm-project/pull/105591
More information about the cfe-commits
mailing list