[llvm] [LLVM] Automatically strip `-fno-lifetime-dse` from compile_commands.json (PR #124623)

Joseph Huber via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 28 05:34:30 PST 2025


https://github.com/jhuber6 updated https://github.com/llvm/llvm-project/pull/124623

>From eac455419578475363f7c47fc3895a8a371a991a Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Mon, 27 Jan 2025 14:48:00 -0600
Subject: [PATCH 1/2] [LLVM] Automatically strip `-fno-lifetime-dse` from
 compile_commands.json

Summary:
This flag is always passed by LLVM to bypass some LTO related bug with
GCC. The problem is that this is not supported by clang and shows up in
the compile_commands.json file. That means it will always show at least
one error complaining about this file. Since I already have a script to
merge the runtimes stuff, just strip this out there for convenience.

There was a discussion a long time ago about not adding this as a no-op
flag to clang, so this is the next best thing.
---
 llvm/utils/merge-json.py | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/llvm/utils/merge-json.py b/llvm/utils/merge-json.py
index f5b9dcf11c4cdc2..eb0fc0ece8d9e95 100644
--- a/llvm/utils/merge-json.py
+++ b/llvm/utils/merge-json.py
@@ -35,6 +35,13 @@ def main():
         except (IOError, json.JSONDecodeError) as e:
             continue
 
+    # LLVM passes this argument by default but it is not supported by clang,
+    # causing annoying errors in the generated compile_commands.json file.
+    # Remove it here before we deduplicate the entries.
+    for entry in merged_data:
+        if isinstance(entry, dict) and "command" in entry:
+            entry["command"] = entry["command"].replace("-fno-lifetime-dse ", "")
+
     # Deduplicate by converting each entry to a tuple of sorted key-value pairs
     unique_data = list({json.dumps(entry, sort_keys=True) for entry in merged_data})
     unique_data = [json.loads(entry) for entry in unique_data]

>From 54bdfd1ea7c7162559d14ab893136c8171cadc87 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Tue, 28 Jan 2025 07:34:15 -0600
Subject: [PATCH 2/2] comments

---
 llvm/utils/merge-json.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/llvm/utils/merge-json.py b/llvm/utils/merge-json.py
index eb0fc0ece8d9e95..0a085c14ea52639 100644
--- a/llvm/utils/merge-json.py
+++ b/llvm/utils/merge-json.py
@@ -9,6 +9,7 @@
 import argparse
 import json
 import sys
+import os
 
 
 def main():
@@ -40,7 +41,8 @@ def main():
     # Remove it here before we deduplicate the entries.
     for entry in merged_data:
         if isinstance(entry, dict) and "command" in entry:
-            entry["command"] = entry["command"].replace("-fno-lifetime-dse ", "")
+            if os.path.basename(entry["command"].partition(" ")[0]) != "g++":
+                entry["command"] = entry["command"].replace("-fno-lifetime-dse ", "")
 
     # Deduplicate by converting each entry to a tuple of sorted key-value pairs
     unique_data = list({json.dumps(entry, sort_keys=True) for entry in merged_data})



More information about the llvm-commits mailing list