[llvm] [StandardInstrumentations]Add support for numeric label (PR #148844)

Ruoyu Qiu via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 4 20:58:31 PDT 2025


================
@@ -1950,10 +1958,9 @@ std::string DotCfgDiffNode::getBodyContent() const {
   // Drop leading newline, if present.
   if (BS.front() == '\n')
     BS1 = BS1.drop_front(1);
-  // Get label.
-  StringRef Label = BS1.take_until([](char C) { return C == ':'; });
   // drop predecessors as they can be big and are redundant
-  BS1 = BS1.drop_until([](char C) { return C == '\n'; }).drop_front();
+  if (BS1.str().find(Label) != std::string::npos)
----------------
cabbaken wrote:

I tested the code by compiling it with `clang++ -mllvm -print-changed -O t.c`, and there were indeed some comments in the output.  
Then, I added some instrumentation:
```diff
diff --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp
index f67d4de4b..307efd8f6 100644
--- a/llvm/lib/Passes/StandardInstrumentations.cpp
+++ b/llvm/lib/Passes/StandardInstrumentations.cpp
@@ -1959,8 +1960,10 @@ std::string DotCfgDiffNode::getBodyContent() const {
   if (BS.front() == '\n')
     BS1 = BS1.drop_front(1);
   // drop predecessors as they can be big and are redundant
+  dbgs() << "Before_BS1:\n" << BS1 << "\n";
   BS1 = BS1.drop_until([](char C) { return C == '\n'; }).drop_front();
+  dbgs() << "After_BS1:\n" << BS1 << "\n";
```
When I compiled with `clang++ -mllvm -print-changed -O t.c`, this code path was not triggered.
However, when compiling with `clang++ -mllvm -print-changed=dot-cfg -O t.c`, the output was:
```
Before_BS1:
for.cond.cleanup:                                 ; preds = %for.cond
  call void @llvm.lifetime.end.p0(i64 4, ptr %i) #3
  br label %for.end

After_BS1:
  call void @llvm.lifetime.end.p0(i64 4, ptr %i) #3
  br label %for.end
```
There is no comment here.
Another reason I think the line is label is from the original code:
```
  // Get label.
  StringRef Label = BS1.take_until([](char C) { return C == ':'; });
  // drop predecessors as they can be big and are redundant
  BS1 = BS1.drop_until([](char C) { return C == '\n'; }).drop_front();
```
It gets the label before erase the line. And the way it gets the label may indicate the line is the label.

https://github.com/llvm/llvm-project/pull/148844


More information about the llvm-commits mailing list