diff --git a/llvm/utils/merge-json.py b/llvm/utils/merge-json.py index f5b9dcf11c4cd..0a085c14ea526 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(): @@ -35,6 +36,14 @@ 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: + 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}) unique_data = [json.loads(entry) for entry in unique_data]