Author: Balázs Benics
Date: 2026-10-14T10:40:46+01:00
New Revision: 2ac1d901d7711f66365be11aa21848c06c9fb79c

URL: 
https://github.com/llvm/llvm-project/commit/2ac1d901d7711f66365be11aa21848c06c9fb79c
DIFF: 
https://github.com/llvm/llvm-project/commit/2ac1d901d7711f66365be11aa21848c06c9fb79c.diff

LOG: [TimeProfiler] Mark the TimeTraceScope class nodiscard (#231700)

This would have caught #213521
This patch is similar to #180008 - to understand why
to put this attribute onto the class instead of on the individual ctors.

This patch also fixes the discarded TimeTraceScope
instances within clang and clang-tools-extra now that I was here.

Added: 
    

Modified: 
    clang-tools-extra/clang-doc/BitcodeReader.cpp
    clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
    llvm/include/llvm/Support/TimeProfiler.h

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp 
b/clang-tools-extra/clang-doc/BitcodeReader.cpp
index 3299dedfbc3e4..b303076d3346a 100644
--- a/clang-tools-extra/clang-doc/BitcodeReader.cpp
+++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp
@@ -413,7 +413,7 @@ template <typename T, typename BlockBeginHandler, typename 
BlockEndHandler,
 llvm::Error
 ClangDocBitcodeReader::parseBlock(unsigned ID, T I, BlockBeginHandler &&BBH,
                                   BlockEndHandler &&BEH, RecordHandler &&RH) {
-  llvm::TimeTraceScope("Reducing infos", "readBlock");
+  llvm::TimeTraceScope TimeTrace("Reducing infos", "readBlock");
   if (llvm::Error Err = Stream.EnterSubBlock(ID))
     return Err;
 
@@ -1185,7 +1185,7 @@ llvm::Error ClangDocBitcodeReader::readRecord(unsigned 
ID, T I) {
 
 template <>
 llvm::Error ClangDocBitcodeReader::readRecord(unsigned ID, Reference *I) {
-  llvm::TimeTraceScope("Reducing infos", "readRecord");
+  llvm::TimeTraceScope TimeTrace("Reducing infos", "readRecord");
   Record R;
   llvm::StringRef Blob;
   llvm::Expected<unsigned> MaybeRecID = Stream.readRecord(ID, R, &Blob);
@@ -1289,7 +1289,7 @@ llvm::Error 
ClangDocBitcodeReader::handleSubBlock(unsigned ID, T Parent) {
 
 template <typename T>
 llvm::Error ClangDocBitcodeReader::readSubBlock(unsigned ID, T I) {
-  llvm::TimeTraceScope("Reducing infos", "readSubBlock");
+  llvm::TimeTraceScope TimeTrace("Reducing infos", "readSubBlock");
 
   static auto CreateAddFunc = [](auto AddFunc) {
     return [AddFunc](auto Parent, auto Child) {
@@ -1377,7 +1377,7 @@ llvm::Error ClangDocBitcodeReader::readSubBlock(unsigned 
ID, T I) {
 
 llvm::Expected<ClangDocBitcodeReader::Cursor>
 ClangDocBitcodeReader::skipUntilRecordOrBlock(unsigned &BlockOrRecordID) {
-  llvm::TimeTraceScope("Reducing infos", "skipUntilRecordOrBlock");
+  llvm::TimeTraceScope TimeTrace("Reducing infos", "skipUntilRecordOrBlock");
   BlockOrRecordID = 0;
 
   while (!Stream.AtEndOfStream()) {
@@ -1433,7 +1433,7 @@ llvm::Error ClangDocBitcodeReader::validateStream() {
 }
 
 llvm::Error ClangDocBitcodeReader::readBlockInfoBlock() {
-  llvm::TimeTraceScope("Reducing infos", "readBlockInfoBlock");
+  llvm::TimeTraceScope TimeTrace("Reducing infos", "readBlockInfoBlock");
   Expected<std::optional<llvm::BitstreamBlockInfo>> MaybeBlockInfo =
       Stream.ReadBlockInfoBlock();
   if (!MaybeBlockInfo)
@@ -1448,7 +1448,7 @@ llvm::Error ClangDocBitcodeReader::readBlockInfoBlock() {
 
 template <typename T>
 llvm::Expected<Info *> ClangDocBitcodeReader::createInfo(unsigned ID) {
-  llvm::TimeTraceScope("Reducing infos", "createInfo");
+  llvm::TimeTraceScope TimeTrace("Reducing infos", "createInfo");
   auto *I = doc::allocateTransient<T>();
   if (auto Err = readBlock(ID, I))
     return std::move(Err);
@@ -1456,7 +1456,7 @@ llvm::Expected<Info *> 
ClangDocBitcodeReader::createInfo(unsigned ID) {
 }
 
 llvm::Expected<Info *> ClangDocBitcodeReader::readBlockToInfo(unsigned ID) {
-  llvm::TimeTraceScope("Reducing infos", "readBlockToInfo");
+  llvm::TimeTraceScope TimeTrace("Reducing infos", "readBlockToInfo");
   switch (ID) {
   case BI_NAMESPACE_BLOCK_ID:
     return createInfo<NamespaceInfo>(ID);

diff  --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp 
b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index 0b81a3cb20351..f4cf954ce0f81 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -278,7 +278,7 @@ Example usage for a project using a compile commands 
database:
   if (FTimeTrace)
     llvm::timeTraceProfilerInitialize(200, "clang-doc");
   {
-    llvm::TimeTraceScope("main");
+    llvm::TimeTraceScope TimeTrace("main");
 
     // Fail early if an invalid format was provided.
     llvm::StringRef Format = getFormatString();

diff  --git a/llvm/include/llvm/Support/TimeProfiler.h 
b/llvm/include/llvm/Support/TimeProfiler.h
index 2eb2c09d1becd..e80ace27a23ca 100644
--- a/llvm/include/llvm/Support/TimeProfiler.h
+++ b/llvm/include/llvm/Support/TimeProfiler.h
@@ -179,7 +179,7 @@ LLVM_ABI void timeTraceProfilerEnd(TimeTraceProfilerEntry 
*E);
 /// of the time trace profiler.  When the object is constructed, it begins
 /// the section; and when it is destroyed, it stops it. If the time profiler
 /// is not initialized, the overhead is a single branch.
-class TimeTraceScope {
+class [[nodiscard]] TimeTraceScope {
 public:
   TimeTraceScope() = delete;
   TimeTraceScope(const TimeTraceScope &) = delete;


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to