[llvm] r343984 - Fix incorrect Twine usage in CFGPrinter
Kristina Brooks via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 8 10:29:40 PDT 2018
Author: kristina
Date: Mon Oct 8 10:29:39 2018
New Revision: 343984
URL: http://llvm.org/viewvc/llvm-project?rev=343984&view=rev
Log:
Fix incorrect Twine usage in CFGPrinter
CFGPrinter (-view-cfg, -dot-cfg) invokes an undefined behaviour (dangling
pointer to rvalue) on IR files with branch weights. This patch fixes the
problem caused by Twine initialization and string conversion split into
two statements.
This change fixes the bug 37019. A similar patch to this problem was
provided in the llvmlite project
Patch by mcopik (Marcin Copik).
Differential Revision: https://reviews.llvm.org/D52933
Added:
llvm/trunk/test/Other/cfg-printer-branch-weights.ll
Modified:
llvm/trunk/include/llvm/Analysis/CFGPrinter.h
Modified: llvm/trunk/include/llvm/Analysis/CFGPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/CFGPrinter.h?rev=343984&r1=343983&r2=343984&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/CFGPrinter.h (original)
+++ llvm/trunk/include/llvm/Analysis/CFGPrinter.h Mon Oct 8 10:29:39 2018
@@ -172,8 +172,7 @@ struct DOTGraphTraits<const Function*> :
// Prepend a 'W' to indicate that this is a weight rather than the actual
// profile count (due to scaling).
- Twine Attrs = "label=\"W:" + Twine(Weight->getZExtValue()) + "\"";
- return Attrs.str();
+ return ("label=\"W:" + Twine(Weight->getZExtValue()) + "\"").str();
}
};
} // End llvm namespace
Added: llvm/trunk/test/Other/cfg-printer-branch-weights.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/cfg-printer-branch-weights.ll?rev=343984&view=auto
==============================================================================
--- llvm/trunk/test/Other/cfg-printer-branch-weights.ll (added)
+++ llvm/trunk/test/Other/cfg-printer-branch-weights.ll Mon Oct 8 10:29:39 2018
@@ -0,0 +1,19 @@
+;RUN: opt < %s -analyze -dot-cfg 2>/dev/null
+;RUN: FileCheck %s -input-file=cfg.f.dot
+
+define void @f(i32) {
+entry:
+ %check = icmp sgt i32 %0, 0
+ br i1 %check, label %if, label %exit, !prof !0
+
+; CHECK: label="W:1"
+; CHECK-NOT: ["];
+if: ; preds = %entry
+ br label %exit
+; CHECK: label="W:200"
+; CHECK-NOT: ["];
+exit: ; preds = %entry, %if
+ ret void
+}
+
+!0 = !{!"branch_weights", i32 1, i32 200}
More information about the llvm-commits
mailing list