[clang-tools-extra] [Docs][LTO] Updated HowToSubmitABug.rst for LTO crashes (PR #68389)

Shivam Gupta via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 19 00:55:18 PDT 2023


https://github.com/xgupta updated https://github.com/llvm/llvm-project/pull/68389

>From bdf991f4563e3aa840bec35b1678ad4fe8f9fbb6 Mon Sep 17 00:00:00 2001
From: Shivam Gupta <shivam98.tkg at gmail.com>
Date: Fri, 6 Oct 2023 12:32:24 +0530
Subject: [PATCH 1/4] [Docs][LTO] Update HowToSubmitABug.rst for LTO crashes

---
 llvm/docs/HowToSubmitABug.rst | 51 +++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/llvm/docs/HowToSubmitABug.rst b/llvm/docs/HowToSubmitABug.rst
index 733dae6c928d098..88f9af44add7c64 100644
--- a/llvm/docs/HowToSubmitABug.rst
+++ b/llvm/docs/HowToSubmitABug.rst
@@ -153,6 +153,57 @@ Please run this, then file a bug with the instructions and reduced .bc file
 that bugpoint emits.  If something goes wrong with bugpoint, please submit
 the "foo.bc" file and the option that llc crashes with.
 
+​.. _lto-crash:
+
+LTO bugs
+---------------------------
+
+If you find a bug that crashes llvm in LTO phase (by using -flto option),
+compile your source file to a .bc file by passing
+"``-flto -fuse-ld=lld -Wl,-plugin-opt=save-temps``"
+to clang (in addition to the options you already pass). If you are building
+a project, pass the appropriate CFLAGS, CXXFLAG​S and LDFLAGS for example -
+
+.. code-block:: bash
+
+   export CFLAGS="-flto -fuse-ld=lld" CXXFLAGS="-flto -fuse-ld=lld" LDFLAGS="-Wl,-plugin-opt=save-temps"
+
+This will generate four intermediate bytecode files:
+
+1. a.out.0.0.preopt.bc      (Before any link-time optimizations (LTO) are applied)
+2. a.out.0.2.internalize.bc (After initial optimizations applied)
+3. a.out.0.4.opt.bc         (After the more extensive set of optimizations has been applied)
+4. a.out.0.5.precodegen.bc  (After LTO but before it's translated into machine code)
+
+Once you have these, one of the following commands should fail:
+
+#. ``opt "-passes=lto<O3>" a.out.0.0.preopt.bc``
+#. ``opt "-passes=lto<O3>" a.out.0.2.internalize.bc``
+#. ``opt "-passes=lto<O3>" a.out.0.4.opt.bc``
+#. ``llc a.out.0.5.precodegen.bc``
+
+If one of these do crash, you should be able to reduce
+this with :program:`llvm-reduce`
+command line (use the bc file corresponding to the command above that failed):
+
+#. ``llvm-reduce --test llvm-reduce.sh a.out.0.2.internalize.bc``
+
+An example of ``llvm-reduce.sh`` script
+
+.. code-block:: bash
+
+   $ cat llvm-reduce.sh
+   #!/usr/bin/env bash
+
+   $HOME/llvm/llvm-project/build/bin/opt "-passes=lto<O3>" $1 -o temp.bc  2>&1 | tee err.log
+   grep "It->second == &Insn" err.log
+   exit $?
+
+Here we have grepped the failed assert message.
+
+Please run this, then file a bug with the instructions and reduced .bc file
+that llvm-reduce emits.
+
 .. _miscompiling:
 
 Miscompilations

>From 1823285171ddbefc49065c4995e9c33bee7b952a Mon Sep 17 00:00:00 2001
From: Shivam Gupta <shivam98.tkg at gmail.com>
Date: Thu, 19 Oct 2023 10:57:25 +0530
Subject: [PATCH 2/4] address review comment

---
 llvm/docs/HowToSubmitABug.rst | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/llvm/docs/HowToSubmitABug.rst b/llvm/docs/HowToSubmitABug.rst
index 88f9af44add7c64..197ed3e0fde6893 100644
--- a/llvm/docs/HowToSubmitABug.rst
+++ b/llvm/docs/HowToSubmitABug.rst
@@ -168,6 +168,12 @@ a project, pass the appropriate CFLAGS, CXXFLAG​S and LDFLAGS for example -
 
    export CFLAGS="-flto -fuse-ld=lld" CXXFLAGS="-flto -fuse-ld=lld" LDFLAGS="-Wl,-plugin-opt=save-temps"
 
+On Windows, you should use lld-link as the linker.
+
+.. code-block:: bash
+
+   export CFLAGS="-flto -fuse-ld=lld-link" CXXFLAGS="-flto -fuse-ld=lld-link" LDFLAGS="-Wl,-plugin-opt=save-temps"
+
 This will generate four intermediate bytecode files:
 
 1. a.out.0.0.preopt.bc      (Before any link-time optimizations (LTO) are applied)

>From 0e19d37bf4eb9a312b4989fe941837e285f92a97 Mon Sep 17 00:00:00 2001
From: Shivam Gupta <shivam98.tkg at gmail.com>
Date: Thu, 19 Oct 2023 12:29:23 +0530
Subject: [PATCH 3/4] rebase and improve some wording

---
 llvm/docs/HowToSubmitABug.rst | 36 ++++++++++++++++++++---------------
 1 file changed, 21 insertions(+), 15 deletions(-)

diff --git a/llvm/docs/HowToSubmitABug.rst b/llvm/docs/HowToSubmitABug.rst
index 197ed3e0fde6893..7e9ac089a0f70a1 100644
--- a/llvm/docs/HowToSubmitABug.rst
+++ b/llvm/docs/HowToSubmitABug.rst
@@ -158,30 +158,34 @@ the "foo.bc" file and the option that llc crashes with.
 LTO bugs
 ---------------------------
 
-If you find a bug that crashes llvm in LTO phase (by using -flto option),
-compile your source file to a .bc file by passing
-"``-flto -fuse-ld=lld -Wl,-plugin-opt=save-temps``"
-to clang (in addition to the options you already pass). If you are building
-a project, pass the appropriate CFLAGS, CXXFLAG​S and LDFLAGS for example -
+If you encounter a bug that leads to crashes in the LLVM LTO phase when using
+the `-flto` option, follow these steps to diagnose and report the issue:
+
+Compile your source file to a .bc (Bitcode) file with the following flags,
+in addition to your existing compilation options:
 
 .. code-block:: bash
 
    export CFLAGS="-flto -fuse-ld=lld" CXXFLAGS="-flto -fuse-ld=lld" LDFLAGS="-Wl,-plugin-opt=save-temps"
 
-On Windows, you should use lld-link as the linker.
+These flags enable LTO and save temporary files generated during compilation
+for later analysis.
+
+On Windows, you should use lld-link as the linker. Adjust your compilation 
+flags as follows:
 
 .. code-block:: bash
 
    export CFLAGS="-flto -fuse-ld=lld-link" CXXFLAGS="-flto -fuse-ld=lld-link" LDFLAGS="-Wl,-plugin-opt=save-temps"
 
-This will generate four intermediate bytecode files:
+Using the specified flags will generate four intermediate bytecode files:
 
-1. a.out.0.0.preopt.bc      (Before any link-time optimizations (LTO) are applied)
-2. a.out.0.2.internalize.bc (After initial optimizations applied)
-3. a.out.0.4.opt.bc         (After the more extensive set of optimizations has been applied)
-4. a.out.0.5.precodegen.bc  (After LTO but before it's translated into machine code)
+#. a.out.0.0.preopt.bc (Before any link-time optimizations (LTO) are applied)
+#. a.out.0.2.internalize.bc (After initial optimizations are applied)
+#. a.out.0.4.opt.bc (After an extensive set of optimizations)
+#. a.out.0.5.precodegen.bc (After LTO but before translating into machine code)
 
-Once you have these, one of the following commands should fail:
+Execute one of the following commands to identify the source of the problem:
 
 #. ``opt "-passes=lto<O3>" a.out.0.0.preopt.bc``
 #. ``opt "-passes=lto<O3>" a.out.0.2.internalize.bc``
@@ -192,13 +196,15 @@ If one of these do crash, you should be able to reduce
 this with :program:`llvm-reduce`
 command line (use the bc file corresponding to the command above that failed):
 
-#. ``llvm-reduce --test llvm-reduce.sh a.out.0.2.internalize.bc``
+.. code-block:: bash
+
+   llvm-reduce --test reduce.sh a.out.0.2.internalize.bc
 
-An example of ``llvm-reduce.sh`` script
+Example of reduce.sh Script
 
 .. code-block:: bash
 
-   $ cat llvm-reduce.sh
+   $ cat reduce.sh
    #!/usr/bin/env bash
 
    $HOME/llvm/llvm-project/build/bin/opt "-passes=lto<O3>" $1 -o temp.bc  2>&1 | tee err.log

>From ee273ae182ba3ada4db981b10402241ec9f86d6d Mon Sep 17 00:00:00 2001
From: Shivam Gupta <shivam98.tkg at gmail.com>
Date: Thu, 19 Oct 2023 13:24:40 +0530
Subject: [PATCH 4/4] minor change

---
 llvm/docs/HowToSubmitABug.rst | 2 --
 1 file changed, 2 deletions(-)

diff --git a/llvm/docs/HowToSubmitABug.rst b/llvm/docs/HowToSubmitABug.rst
index 7e9ac089a0f70a1..95fd6ca62a762be 100644
--- a/llvm/docs/HowToSubmitABug.rst
+++ b/llvm/docs/HowToSubmitABug.rst
@@ -153,8 +153,6 @@ Please run this, then file a bug with the instructions and reduced .bc file
 that bugpoint emits.  If something goes wrong with bugpoint, please submit
 the "foo.bc" file and the option that llc crashes with.
 
-​.. _lto-crash:
-
 LTO bugs
 ---------------------------
 



More information about the cfe-commits mailing list